Spring RabbitTemplate is not creating dead letter queue with TTL

不羁的心 提交于 2019-12-24 03:31:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!