java-RabbitMQ春季死信配置不起作用
作者:互联网
以下是我正在使用的配置.消息没有错误,从交换到队列都可以正常工作,并且侦听器可以进行转换,这很棒.我想要对错误消息进行的操作是,当我抛出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>
解决方法:
尝试添加一个显式的x-dead-letter-routing-key-否则使用与原始路由相同的密钥-扇出交换不需要路由密钥.
标签:spring-amqp,rabbitmq,spring,java 来源: https://codeday.me/bug/20191120/2046248.html