Search code examples
rabbitmqnestjs

Encountering PRECONDITION_FAILED Error (Code 406) in RabbitMQ When Sending Large Messages


I'm working on a project where I need to send large messages through RabbitMQ. However, I'm encountering the following error:

I am using NestJs microservices

"err": {     "code": 406,     "classId": 60,     "methodId": 40   }

Context:

  • RabbitMQ Version: [Specify your RabbitMQ version]

  • Client Library: [Specify the client library and version you're using]

  • Message Size: Approximately [specify size, e.g., 20 MB]

What I've Tried:

  1. Adjusting Queue Arguments:

    • Set the x-max-length-bytes argument to 20971520 (20 MB) during queue declaration.

    • Verified that the queue is declared with the correct arguments.

  2. Increasing frame_max:

    • Configured frame_max to a higher value in the RabbitMQ configuration to accommodate larger frames.
  3. Client Configuration:

    • Ensured that the client settings (e.g., socketOptions in Node.js) are configured to handle larger message sizes.

Observations:

  • Sending smaller messages works without any issues.

  • The error occurs consistently with larger messages.

Questions:

  1. Is there a maximum message size limit in RabbitMQ that I'm exceeding?

  2. Are there additional configurations or best practices for handling large messages in RabbitMQ?

  3. Could the PRECONDITION_FAILED error be related to other settings or misconfigurations?

Any insights or suggestions would be greatly appreciated. Thank you in advance!


Solution

  • I added rabbitmq.conf file with these configs:

    max_message_size = 536870912
    frame_max = 536870912
    

    and it can now accept larger messages.