我将 Spring 与 RabbitMQ 结合使用,并试图避免在发生运行时异常时重新传递消息。我尝试将 设为requeue-rejectinfalse并listener-container配置一个抛出AmqpRejectAndDontRequeueException. 看来这两种策略都失败了,并且消息将永远继续重新传递。有什么想法吗?
感谢帮助。
<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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd">
<rabbit:connection-factory id="rabbitMQConnectionFactory" host="localhost" port="5672" username="guest" password="guest" />
<rabbit:admin connection-factory="rabbitMQConnectionFactory" />
<rabbit:template id="amqpTemplate" connection-factory="rabbitMQConnectionFactory" />
<rabbit:queue name="q1" />
<rabbit:queue name="q2" />
<rabbit:listener-container error-handler="errorHandler" connection-factory="rabbitMQConnectionFactory" concurrency="10" transaction-manager="transactionManager" requeue-rejected="false">
<rabbit:listener ref="q1Listener" method="consumeMessage" queue-names="q1" />
<rabbit:listener ref="q2Listener" method="consumeMessage" queue-names="q2" />
</rabbit:listener-container>
<bean id="errorHandler" class="ErrorHandler" />
<bean id="q1Listener" class="Q1MessageConsumerBean" />
<bean id="q2Listener" class="Q2MessageConsumerBean" />
</beans>
Run Code Online (Sandbox Code Playgroud)