spring集成amqp当来自amqp的转换消息出现错误时,它不会去重试
spring集成amqp版本:5.0.11 目标:当发生致命异常时,消息将删除。但不是致命的,消息将重新查询并转到重试策略 但在我的例子中,我有一个自定义的消息转换器,当我的转换发生一些非致命错误时,它将始终重新请求,而不会转到重试策略 我尝试读取代码,spring集成amqp当来自amqp的转换消息出现错误时,它不会去重试,spring,spring-integration,spring-rabbit,spring-integration-amqp,Spring,Spring Integration,Spring Rabbit,Spring Integration Amqp,spring集成amqp版本:5.0.11 目标:当发生致命异常时,消息将删除。但不是致命的,消息将重新查询并转到重试策略 但在我的例子中,我有一个自定义的消息转换器,当我的转换发生一些非致命错误时,它将始终重新请求,而不会转到重试策略 我尝试读取代码,AmqpInboundChannelAdapter.Listener#onMessage在重试之前,它会转换消息,这意味着当消息转换发生一些错误时,它不会转到重试,将转到错误处理程序 public void onMessage(final Mes
AmqpInboundChannelAdapter.Listener#onMessage
在重试之前,它会转换消息,这意味着当消息转换发生一些错误时,它不会转到重试,将转到错误处理程序
public void onMessage(final Message message, final Channel channel) throws Exception {
boolean retryDisabled = AmqpInboundChannelAdapter.this.retryTemplate == null;
try {
if (retryDisabled) {
createAndSend(message, channel);
}
else {
final org.springframework.messaging.Message<Object> toSend = createMessage(message, channel);
AmqpInboundChannelAdapter.this.retryTemplate.execute(context -> {
StaticMessageHeaderAccessor.getDeliveryAttempt(toSend).incrementAndGet();
setAttributesIfNecessary(message, toSend);
sendMessage(toSend);
return null;
},
(RecoveryCallback<Object>) AmqpInboundChannelAdapter.this.recoveryCallback);
}
}
我如何解决这个问题,谢谢。好吧,我们相信转换器错误确实是致命的。这就是为什么AMQP消息的转换实际上是在重试循环之外完成的
如果您确信转换器中的错误是间歇性的,请考虑在转换器中包含一个重试逻辑,因此当<代码> AMQPoxNanghannAdvult调用<代码>转换器.FaseMead(消息)时,如果发生异常,将应用您的代码> RejyTasks/COD>。 如果使用现成的转换器,请参阅
ProxyFactoryBean
和RetryInterceptorBuilder
。否则,可以将@Retryable
应用于convert()
方法
请参阅Spring重试项目中的更多信息:
@Bean
public IntegrationFlow EndpointMessageAndConvertModelDlxFlow(
@Qualifier("rabbitmqUnFatalExceptionRetryTemplate") RetryTemplate template,
ConnectionFactory factory,
EndpointCodeDelegatingMessageConverter converter) {
final MailRabbitmqProperties.Queue queue = getQueueConfig(ENDPOINT_BUFFER_DLX_NODE,
ENDPOINT_BUFFER_FUNCTION);
template.setRetryPolicy(endpointMessageExceptionClassifierRetryPolicy()); //fatal err not go retry
return IntegrationFlows.from(Amqp.inboundAdapter(factory, queue.getName())
.configureContainer(smlc -> {
smlc.acknowledgeMode(AcknowledgeMode.AUTO); //
smlc.defaultRequeueRejected(true); //requeue
final ConditionalRejectingErrorHandler errorHandler =
new ConditionalRejectingErrorHandler(
new EndPointMessageFatalExceptionStrategy());
smlc.errorHandler(errorHandler);
})
.retryTemplate(template)
.messageConverter(converter))
.channel(mailActionCreateTopicChannel())
.get();
}