这是我的 rabbitmq 配置:
<rabbit:admin connection-factory="rmqConnectionFactory"/>
<bean id="**retryAdvice**" class="org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean">
<property name="retryOperations" ref="retryTemplate"/>
</bean>
<bean id="**retryTemplate**" class="org.springframework.retry.support.RetryTemplate">
<property name="retryPolicy" ref="simpleRetryPolicy"/>
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
<property name="backOffPeriod" value="5000"/>
</bean>
</property>
<property name="retryContextCache" ref="retryContext"/>
</bean>
<bean id="**retryContext**" class="org.springframework.retry.policy.MapRetryContextCache"/>
<bean id="**simpleRetryPolicy**" class="org.springframework.retry.policy.SimpleRetryPolicy">
<property name="maxAttempts" value="3"/>
</bean>
<!-- Spring AMQP Template -->
<bean id="**rabbitTemplate**" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="rmqConnectionFactory"/>
<property name="messageConverter" ref="stdJsonMessageConverter"/>
</bean>
<bean id="**stdJsonMessageConverter**" class="org.springframework.amqp.support.converter.JsonMessageConverter">
<property name="createMessageIds" value="true"/>
</bean>
我的队列配置如下:
<rabbit:queue name="${queue}" durable="true">
<rabbit:queue-arguments>
<entry key="x-ha-policy" value="all"/>
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:direct-exchange name="${exchange}">
<rabbit:bindings>
<rabbit:binding queue="${queue}" key="${routingKey}"/>
</rabbit:bindings>
</rabbit:direct-exchange>
当我第一次在交易所发布消息时,监听器失败并出现 null ID 异常。我也清除了有错误消息的队列。尽管如此,每次我启动服务时,都会重试失败的消息处理,并且会不断失败,直到出现 RetryCacheCapacityExceeded 异常。
我失败的消息是否缓存在某个地方?有没有办法清除它? 另外,即使我的重试模板建议以 5 秒的间隔重试 3 次,为什么重试仍在继续?
最佳答案
当您使用有状态重试时,每个消息 ID 的重试状态都保存在缓存中(因此我们知道何时停止)。
如果没有 ID,消息将失败(并继续传递),除非您将 MissingMessageIdAdvice
添加到通知链(在重试拦截器之前),这将允许重试 1 次没有消息的消息编号。
关于java - 兔子 : Failed message being reprocessed in an infinite loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43478775/