java - Apache Camel : modify endpoint on redelivery

标签 java apache-camel

我有一个带有 .recipientList() 的动态端点,并且我想在发生异常时更改端点。这是我的例子:

onException(IOException.class)
 .maximumRedeliveries(2)
 .onRedelivery(urlChangeProcessor)
 .process(failureProccessor);

from("direct:foo")
 .recipientList(simple("cxf:${exchangeProperty.targetUrl}?dataFormat=POJO"));

在重新传递之前出现异常,“urlChangeProcessor”会使用正确的 URL 更新“targetUrl”属性,但重新传递尝试仍会指向错误的 URL。

是否无法更改重新交付时的目标端点?如果没有,什么是优雅的解决方案?我当前的解决方法是 doTry/doCatch,更改 doCatch 中的属性并将其再次发送到同一端点。

我使用 Camel 2.15.3

提前致谢!

最佳答案

由于这是不可能的,因此我的解决方案是删除 onException 并添加 doTry/doCatch:

from("direct:foo")
 .doTry()
  .to("direct:out")
 .doCatch(IOException.class)
  .process(urlChangeProcessor)
  .to("direct:foo")
 .end();

from("direct:out")
 .recipientList(simple("cxf:${exchangeProperty.targetUrl}?dataFormat=POJO"));

添加一些条件,这样就不会以无限循环结束。

关于java - Apache Camel : modify endpoint on redelivery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47475414/

相关文章:

java - 使用 Hibernate 拦截器时,我应该在 Struts2 Web 应用程序中的哪里打开和关闭 Hibernate session

java - 在 apache Camel 中压缩和解压缩大文件而不将整个文件加载到内存中

java - 在java中使用blueprint中定义的数据源访问oracle db

java - 调频 radio : can we implement FM Radio and create and application of it?

java - 如何显示文件名的某些部分

java - System.out.println() 与 Android 完全兼容吗?

JavaFX CSS : Custom Functions

java - 访问java pojo的成员设置为camel spring路由中的交换属性

java - 使用 Apache Camel 和 Spring,我可以使用属性构建 uri 吗?

java - 如何从 Exchange 获取内容。In :Body object from a ProcessDefinition in Camel