Spring RabbitTemplate没有使用TTL创建死信队列 [英] Spring RabbitTemplate is not creating dead letter queue with TTL

查看:475
本文介绍了Spring RabbitTemplate没有使用TTL创建死信队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring-rabbit1.1和RabbitMQ 3.3.1

I am using spring-rabbit1.1 and RabbitMQ 3.3.1 ,

我的spring配置将在Rabbit MQ上借助RabbitTemplate来创建任何队列,但是如果已使用x-dead-letter-exchange和x-message-ttl配置了该队列,则只会创建没有TTL和死信交换.

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.

例如:下面的队列将创建该队列,但不会创建TTL和死信交换.

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>

因此,我不得不从Rabbit MQ中删除队列,并手动创建所有必需的值以使其正常工作.

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 ???

推荐答案

您必须显式声明队列并进行交换...

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.

顺便说一句,RabbitTemplate不声明这些元素,它是RabbitAdmin实例.

By the way, the RabbitTemplate does not declare these elements, it's the RabbitAdmin instance.

这篇关于Spring RabbitTemplate没有使用TTL创建死信队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆