以下是我正在使用的配置。没有错误的消息,从交换到队列的工作正常,并且听众收到了转换,这很棒。当我抛出 AmqpRejectAndDontRequeueException ," rabbitQueue"时,想要发生错误信息将消息转发给它的死信交换并最终进入" rabbitErrorQueue。"尽管如此,死信交换或队列上没有任何活动。谁能看到我在这里做错了什么?
<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>
答案 0 :(得分:3)
尝试添加明确的x-dead-letter-routing-key
- 否则使用与原始路由相同的密钥 - 并且扇出交换不需要路由密钥。