[英]Errorhandler in Camel Route retrying more times than configured value
我已經設置了一個測試用例,我希望消息在發生異常后進入死信通道,重試 2 次以處理它:
public class TestObjectRoutes extends SpringRouteBuilder {
@Override
@Transactional
public void configure() {
errorHandler(transactionErrorHandler().logHandled(true)
.onRedelivery(exchange -> System.out.println("Testing..."))
.maximumRedeliveries(2));
from("activemq:queueone")
.transacted()
.to("activemq:queuetwo")
.process(javaThrower); // This line throws an exception
;
}
}
調用路由后,我可以看到以下內容:
Testing...
Testing...
2016-03-17 15:59:32.762 ERROR 3296 --- [testobject.one]] o.a.camel.processor.DeadLetterChannel : Failed delivery for (MessageId: ID:DESKTOP-HRMD8N6-64204-1458226711533-21:2:1:1:1 on ExchangeId: ID-DESKTOP-HRMD8N6-64190-1458226703758-0-8). Exhausted after delivery attempt: 3 caught: java.lang.IllegalArgumentException: JAVA EXCEPTION. Processed by failure processor: FatalFallbackErrorHandler[sendTo(Endpoint[activemq://mydeadletterchannel] InOnly)]
這看起來和我期待的一模一樣。
唯一的問題是它並不止於此。 它不斷重試呼叫,我看到這 2 條日志行和 ERROR 7次
然后它將消息移動到 DLQ,但是,它不是我定義的 DLQ 隊列名稱,而是移動到“ACTIVEMQ.DLQ”。
這讓我覺得其他地方正在接管另一個默認配置,但我似乎無法確定它。
這是我的 ActiveMQComponent 配置:
@Autowired
private PlatformTransactionManager platformTransactionManager;
@PostConstruct
public void init() throws Exception {
ActiveMQComponent component = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false");
component.setTransactionManager(platformTransactionManager);
component.setTransacted(true);
camelContext.addComponent("activemq", component);
}
有誰知道為什么會發生這種行為?
編輯:
添加自定義連接工廠后,我的代碼如下所示:
ActiveMQComponent component = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false");
component.setTransactionManager(platformTransactionManager);
component.setTransacted(true);
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setMaximumRedeliveries(0);
connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
connectionFactory.setBrokerURL("vm://localhost?broker.persistent=false");
component.setConnectionFactory(connectionFactory);
camelContext.addComponent("activemq", component);
camel-jms 的默認重試/重新傳遞是 6,這就是為什么您收到 2 條消息和 7 次錯誤的原因。
使用來自camel-jms 測試createConnectionFactory() 的連接工廠創建者方法指定您想要的最大重新交付並將此連接工廠傳遞到您的駱駝組件中。 如果使用 spring,那么事務性客戶端文檔已經提供了構建連接工廠和 ActiveMQComponents 的示例,您只需要向連接工廠 bean 添加一個重新傳遞策略 bean。
在camel-jms 組件測試中還有其他使用事務和配置JMS 消息重新傳遞的好例子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.