Reputation: 5
I had declare a queue like below:
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-length-bytes", 2 * 1024 * 1024); // Max length is 2G
channel.queueDeclare("queueName", true, false, false, args);
When the queue messages count bytes is large than 2G, It will auto remove the message on the head of the queue.
But what I expected is That it reject produce the last message and return exception to the producer.
How can I get it?
Upvotes: 0
Views: 3399
Reputation: 22682
A possible workaround is check the queue size before send your message using the HTTP API.
For example if you have a queue called: myqueuetest
with max size = 20.
Before send the message you can call the HTTP API in this way: http://localhost:15672/api/queues/
the result is a JSON
like this:
"message_bytes":10,
"message_bytes_ready":10,
"message_bytes_unacknowledged":0,
"message_bytes_ram":10,
"message_bytes_persistent":0,
..
"name":"myqueuetest",
"vhost":"test",
"durable":true,
"auto_delete":false,
"arguments":{
"x-max-length-bytes":20
},
then you cloud read the message_bytes
field before send your message and then decide if send or not.
Hope it helps
EDIT
Just try to see if it is ok for your application.
Upvotes: 1
Reputation: 2313
As explained on the official docs:
Messages will be dropped or dead-lettered from the front of the queue to make room for new messages once the limit is reached.
https://www.rabbitmq.com/maxlength.html
If you think RabbitMQ should drop messages form the end of the queue, feel free to open an issue here so we can discuss about it https://github.com/rabbitmq/rabbitmq-server/issues
Upvotes: 0