Search code examples
propertiesrabbitmqspring-cloud-streamspring-rabbit

How to set property 'x-message-ttl' for queue in java


How to set 'x-message-ttl' properties to this queue?

rabbit:
            bindings:
              TEST_RESPONSE:
                consumer:
                  bindingRoutingKey: "'${routing}'"
                  prefetch: ${prefetch}
                  acknowledge-mode: MANUAL
          bindings:
            TEST_RESPONSE:
              destination: TEST_RESPONSE
              content-type: application/json
              group: test

because a have this error

Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-message-ttl' for queue 'TEST_RESPONSE.test' in vhost '/': received none but current is the value '60000' of type 'long', class-id=50, method-id=10)

enter image description here


Solution

  • Queue definitions are immutable; you can't change a queue argument.

    You either need to disable queue declaration

    ...rabbit.bindings.foo.consumer.bindQueue: false
    

    or add

    ...rabbit.bindings.foo.consumer.ttl: 60000
    

    to match the existing definition.

    See consumer properties.

    https://cloud.spring.io/spring-cloud-static/spring-cloud-stream-binder-rabbit/3.0.3.RELEASE/reference/html/spring-cloud-stream-binder-rabbit.html#_rabbitmq_consumer_properties