以下是我正在使用的配置。消息没有错误,从交换到队列都可以正常工作,并且侦听器可以进行转换,这很棒。我希望与错误消息一起发生的原因是,当我抛出 AmqpRejectAndDontRequeueException 时,“rabbitQueue”会将消息转发到死信交换,并最终出现在“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
-否则使用与原始路由相同的密钥-展开扇出交换不需要路由密钥。