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:
- Limit the max size to 10000000 (10M) in the rabbitmq.conf
max_message_size = 10000000
- Restart the RabbitMQ
- 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
- 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.