RabbitMQ Spring 死信配置不工作
RabbitMQ Spring dead letter config not working
以下是我正在使用的配置。没有错误的消息,从交换到队列工作正常,转换由侦听器接收,非常棒。我 想要 发生错误消息的原因是,当我抛出 AmqpRejectAndDontRequeueException 时,"rabbitQueue" 会将消息转发到它的死信exchange 并最终进入 "rabbitErrorQueue." 尽管在死信交换或队列中没有 activity。谁能看出我在这里做错了什么?
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="clientConnectionFactory"
class="org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean">
</bean>
<rabbit:connection-factory
id="rabbitConnectionFactory"
connection-factory="clientConnectionFactory"
host="${rabbit.broker.url}"
port="${rabbit.broker.port}"
username="${rabbit.username}"
password="${rabbit.password}"
publisher-confirms="true"/>
<rabbit:admin connection-factory="rabbitConnectionFactory" />
<rabbit:template id="rabbitTemplate"
connection-factory="rabbitConnectionFactory"
exchange="${rabbit.exchange.name}"
message-converter="messageConverter"
queue="${rabbit.queue.name}" >
</rabbit:template>
<rabbit:queue id="rabbitQueue" name="${rabbit.queue.name}" >
<rabbit:queue-arguments>
<entry key="x-dead-letter-exchange" value="${rabbit.dead.letter.exchange.name}"/>
<entry key="x-message-ttl" value="10000" value-type="java.lang.Long"/>
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:queue id="rabbitErrorQueue" name="${rabbit.dead.letter.queue.name}" />
<rabbit:fanout-exchange id="fanoutExchange" name="${rabbit.exchange.name}">
<rabbit:bindings>
<rabbit:binding queue="rabbitQueue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:direct-exchange id="directErrorExchange" name="${rabbit.dead.letter.exchange.name}">
<rabbit:bindings>
<rabbit:binding key="${rabbit.queue.name}" queue="rabbitErrorQueue" />
</rabbit:bindings>
</rabbit:direct-exchange>
<bean id="messageConverter" class="com.example.RabbitMQExampleEventMessageConverter"/>
<bean id="rabbitMQExampleConsumer" class="com.example.consumer.RabbitMQExampleConsumer">
<constructor-arg name="eventProcessor" ref="userEventProcessor" />
</bean>
<rabbit:listener-container connection-factory="rabbitConnectionFactory" message-converter="messageConverter">
<rabbit:listener queues="${rabbit.queue.name}" ref="rabbitMQExampleConsumer" method="onMessage" />
</rabbit:listener-container>
</beans>
尝试添加显式 x-dead-letter-routing-key
- 否则将使用与原始路由相同的密钥 - 扇出交换不需要路由密钥。
以下是我正在使用的配置。没有错误的消息,从交换到队列工作正常,转换由侦听器接收,非常棒。我 想要 发生错误消息的原因是,当我抛出 AmqpRejectAndDontRequeueException 时,"rabbitQueue" 会将消息转发到它的死信exchange 并最终进入 "rabbitErrorQueue." 尽管在死信交换或队列中没有 activity。谁能看出我在这里做错了什么?
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="clientConnectionFactory"
class="org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean">
</bean>
<rabbit:connection-factory
id="rabbitConnectionFactory"
connection-factory="clientConnectionFactory"
host="${rabbit.broker.url}"
port="${rabbit.broker.port}"
username="${rabbit.username}"
password="${rabbit.password}"
publisher-confirms="true"/>
<rabbit:admin connection-factory="rabbitConnectionFactory" />
<rabbit:template id="rabbitTemplate"
connection-factory="rabbitConnectionFactory"
exchange="${rabbit.exchange.name}"
message-converter="messageConverter"
queue="${rabbit.queue.name}" >
</rabbit:template>
<rabbit:queue id="rabbitQueue" name="${rabbit.queue.name}" >
<rabbit:queue-arguments>
<entry key="x-dead-letter-exchange" value="${rabbit.dead.letter.exchange.name}"/>
<entry key="x-message-ttl" value="10000" value-type="java.lang.Long"/>
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:queue id="rabbitErrorQueue" name="${rabbit.dead.letter.queue.name}" />
<rabbit:fanout-exchange id="fanoutExchange" name="${rabbit.exchange.name}">
<rabbit:bindings>
<rabbit:binding queue="rabbitQueue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:direct-exchange id="directErrorExchange" name="${rabbit.dead.letter.exchange.name}">
<rabbit:bindings>
<rabbit:binding key="${rabbit.queue.name}" queue="rabbitErrorQueue" />
</rabbit:bindings>
</rabbit:direct-exchange>
<bean id="messageConverter" class="com.example.RabbitMQExampleEventMessageConverter"/>
<bean id="rabbitMQExampleConsumer" class="com.example.consumer.RabbitMQExampleConsumer">
<constructor-arg name="eventProcessor" ref="userEventProcessor" />
</bean>
<rabbit:listener-container connection-factory="rabbitConnectionFactory" message-converter="messageConverter">
<rabbit:listener queues="${rabbit.queue.name}" ref="rabbitMQExampleConsumer" method="onMessage" />
</rabbit:listener-container>
</beans>
尝试添加显式 x-dead-letter-routing-key
- 否则将使用与原始路由相同的密钥 - 扇出交换不需要路由密钥。