Queue length limit
Outline
The maximum length of the queue may be limited to a set number of messages or a group of bytes (the sum of all the length of the message body and ignores other overhead message attributes), or both.
For any given queue, the maximum length (of either type) can be defined using the parameters of the queue by the client, the server can also be used in the configuration policy ( policies
) is defined. In the case of policies and parameters specify the maximum length of the application of the smaller of the two values.
Length of the list can use operator policies forced.
In all cases, the use of ready number of messages; unacknowledged messages not included limits.
rabbitmqctl list_queues
In the field messages_ready
, message_bytes_ready
and the value shown is the management API is limited.
The default maximum queue length limit behavior
When setting the maximum queue length or size and reaches its maximum, the default behavior RabbitMQ is discarded from the front of the queue or dead-letter message (i.e., the oldest message in the queue). To modify this behavior, use described in the following overflow
set.
Queue overflow behavior
Use overflow settings to configure queue overflow behavior. If overflow
set reject-publish
, the most recent news release will be discarded. In addition, if the publisher confirmed enabled, through basic.nack
denial notification message to the publisher. If a message is routed to a plurality of queues and wherein the at least one queue rejected, through the channel basic.nack
release notifications. The message will be issued to all other queues that can be queued.
Use configuration defines the maximum queue length
To use the configuration specified maximum length, set the keywords max-length
and /
or max-length-bytes
added to the configuration definition. E.g:
type | value |
---|---|
rabbitmqctl | rabbitmqctl set_policy my-pol “^one-meg$” \ ‘{“max-length-bytes”:1048576}’ \ --apply-to queues |
rabbitmqctl on Windows | rabbitmqctl.bat set_policy my-pol “^one-meg$” ^ "{"“max-length-bytes”":1048576}" ^ --apply-to queues |
my-pol
Strategies to ensure that one-meg
the queue contains no more than 1MB of message data. When the limit is reached 1mB, discarding the oldest messages from the queue head.
To define the overflow behavior - is to delete the message from the head or reject the new release, keywords need to be overflow
added to the policy definition. E.g:
rabbitmqctl | rabbitmqctl set_policy my-pol "^two-messages$" \
'{"max-length":2,"overflow":"reject-publish"}' \
--apply-to queues
|
---|---|
rabbitmqctl on Windows | rabbitmqctl.bat set_policy my-pol "^two-messages$" ^
"{""max-length"":2,""overflow"":""reject-publish""}" ^
--apply-to queues
|
my-pol
Strategies to ensure that two-messages
queue contains messages are not more than two, and all other publishers are basic sent. As long as the message and the queue contains two case confirmed the publisher is enabled, the other will receive a message sent basic.nack
in response.
Policy configuration can also be defined by management plug-ins. The details look at related documents
During the use of x-arguments statement defining a maximum queue length
Declaration by the queue parameter x-max-length
to set the maximum number of messages to provide a nonnegative integer value.
Declaring parameters can queue x-max-length-bytes
to provide a nonnegative integer value, setting the maximum byte length.
If the two parameters are set, the two parameters will apply; no matter which comes first restrictions will be enforced.
Queue overflow is to declare the parameters can x-overflow
be set to provide a string value. Possible values are drop-head
(the default) orreject-publish
The following example Java declares the maximum length of a message queue 10:
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-length", 10);
channel.queueDeclare("myqueue", false, false, false, args);
Original Address https://www.rabbitmq.com/maxlength.html