以下是我使用的配置。没有错误的消息可以很好地从交换机传递到队列,由监听器接收并进行转换,非常好。对于有错误的消息,我想发生的是当我抛出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>
AmqpRejectAndDontRequeueException
吗? - Artem Bilanx-dead-letter-routing-key
- 否则将使用与原始路由相同的键 - 并且对于扇出交换不需要路由键。 - Gary Russell