问题
I am using spring-rabbit1.1 and RabbitMQ 3.3.1 ,
My spring configuration will create any queue with the help of RabbitTemplate on Rabbit MQ but if the queue has been configured with x-dead-letter-exchange and x-message-ttl , it just creates the queue with out the TTL and dead letter exchange.
For Eg : the below queue will create the queue but TTL and dead letter exhange is not getting created .
<rabbit:queue name="hello.queue.dead">
<rabbit:queue-arguments>
<entry key="x-dead-letter-exchange" value="hello.activity-task.topic"/>
<entry key="x-message-ttl" value="10000"/>
</rabbit:queue-arguments>
</rabbit:queue>
So i had to go and delete the queue from Rabbit MQ and create with all the required values manually to make it work .
Can anyone help me if there is any option to solve this issue ???
回答1:
You have to explicitly declare the queue and exchange...
<rabbit:queue name="q.with.dlx">
<rabbit:queue-arguments>
<entry key="x-dead-letter-exchange" value="dlx"/>
<entry key="x-message-ttl" value="10000" value-type="java.lang.Long"/>
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:queue name="dlq"/>
<rabbit:direct-exchange name="dlx">
<rabbit:bindings>
<rabbit:binding key="q.with.dlx" queue="dlq"/>
</rabbit:bindings>
</rabbit:direct-exchange>
This assumes you routed the original message using the default direct exchange (routing by queue name). Hence the dead letter routing uses the same routing key (queue name). If you route using an explicit routing key, you would use that.
By the way, the RabbitTemplate
does not declare these elements, it's the RabbitAdmin
instance.
来源:https://stackoverflow.com/questions/24858880/spring-rabbittemplate-is-not-creating-dead-letter-queue-with-ttl