Limit the per message max size in the RabbitMQ
search cancel

Limit the per message max size in the RabbitMQ

book

Article ID: 297346

calendar_today

Updated On:

Products

Support Only for OpenSource RabbitMQ

Issue/Introduction

Excessively large messages negatively impact RabbitMQ performance, so you may need to restrict the maximum message size. This guide will cover how to set the maximum allowed size of messages in the RabbitMQ.

Environment

Product Version: 3.10

Resolution

RabbitMQ does support a global maximum message setting that will cause any message greater than that size to be rejected. The default is 128MiB. You can configure it in the rabbitmq.conf using the "max_message_size" variable given as a maximum allowed message payload size in bytes. For instance, the following would limit the maximum message payload to 32KB
 
max_message_size = 32768
 
If you're using rabbitmq.config or advanced.config, the setting would be:
 
[
    {rabbit, [
        {max_message_size = 32768}
    ]}
].
 
The above would cause any message greater than 32KB size to be rejected.
 
Below are the steps for reference:
  1. Limit the max size to 10000000 (10M) in the rabbitmq.conf

    max_message_size = 10000000

  2. Restart the RabbitMQ
  3. Use the perf-test-2.19.0.jar to test and monitor the logs at the same time

    java -jar perf-test-2.19.0.jar -x 1 --size 10000001

  4. If a message is sent with the size 10000001 bytes, you will see the error in the logs as below:

    2023-06-27 11:10:49.887420+08:00 [error] <0.1093.0> operation basic.publish caused a channel exception precondition_failed: message size 10000001 is larger than configured max size 10000000

The message with a greater size is blocked and it works as expected.