The RabbitMQ queue length limit

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_queuesIn the field messages_ready, message_bytes_readyand 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 overflowset.

Queue overflow behavior

Use overflow settings to configure queue overflow behavior. If overflowset reject-publish, the most recent news release will be discarded. In addition, if the publisher confirmed enabled, through basic.nackdenial 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.nackrelease 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-lengthand /or max-length-bytesadded 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-polStrategies to ensure that one-megthe 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 overflowadded 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-polStrategies to ensure that two-messagesqueue 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.nackin 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-lengthto set the maximum number of messages to provide a nonnegative integer value.

Declaring parameters can queue x-max-length-bytesto 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-overflowbe 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

Guess you like

Origin blog.csdn.net/qq_35958788/article/details/91483790