java - Camel 的重新投递政策

标签 java xml apache-camel

我有一条小路由,我想使用自定义重新传递策略重复向端点发送消息,但这种行为很奇怪。看起来 redeliveryPolicy 只是在重复错误抛出。我试图将所有交换发送到路由的开头,但是策略不起作用,因为每次都在创建:

        <route id="sampleRoute">
            <from uri="direct:anotheRoute" />
            <to uri="nmr:kaboom" />
            <choice>
                <when>
                    <xpath>//result = 'true'</xpath>
                    <to uri="direct:anotherAnotherRoute" />
                </when>
                <otherwise>
                    <throwException ref="redeliveryException" />
                </otherwise>
            </choice>
            <onException>
                <exception>java.net.SocketException</exception>
                <exception>java.net.ConnectException</exception>
                <exception>my.custom.error.RedeliveryException</exception>
                <redeliveryPolicy ref="customRedeliveryPolicy" />
                <to uri="direct:anotheRoute" />
            </onException>
        </route>

我做错了什么?我想在发生错误时每隔一段时间重复我的请求。我的 Camel 版本是2.6

日志:

16:29:43,780 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:43,780 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 0 caught: my.custom.error.RedeliveryException
16:29:43,780 | DEBUG | cc5bd91-thread-1 | RedeliveryPolicy                 |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Sleeping for: 60 millis until attempting redelivery
16:29:43,840 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:43,840 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 1 caught: my.custom.error.RedeliveryException
16:29:43,840 | DEBUG | cc5bd91-thread-1 | RedeliveryPolicy                 |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Sleeping for: 60 millis until attempting redelivery
16:29:43,900 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:43,900 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 2 caught: my.custom.error.RedeliveryException
16:29:43,900 | DEBUG | cc5bd91-thread-1 | RedeliveryPolicy                 |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Sleeping for: 60 millis until attempting redelivery
16:29:43,960 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:43,960 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 3 caught: my.custom.error.RedeliveryException
16:29:43,960 | DEBUG | cc5bd91-thread-1 | RedeliveryPolicy                 |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Sleeping for: 60 millis until attempting redelivery
16:29:44,020 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:44,020 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 4 caught: my.custom.error.RedeliveryException
16:29:44,020 | DEBUG | cc5bd91-thread-1 | RedeliveryPolicy                 |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Sleeping for: 60 millis until attempting redelivery
16:29:44,080 | DEBUG | cc5bd91-thread-1 | DefaultListableBeanFactory       |  | 59 - org.springframework.beans - 3.0.5.RELEASE | Returning cached instance of singleton bean 'RedeliveryPolicy'
16:29:44,080 | DEBUG | cc5bd91-thread-1 | DefaultErrorHandler              |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | Failed delivery for exchangeId: ID-1NVC-52527-1436958153799-314-4. On delivery attempt: 5 caught: my.custom.error.RedeliveryException
16:29:44,081 | DEBUG | cc5bd91-thread-1 | NMR                              |  | 81 - org.apache.servicemix.nmr.core - 1.4.0.fuse-03-01 | Channel org.apache.servicemix.nmr.core.ChannelImpl@7dc124e5 dispatching exchange: [

最佳答案

这并不奇怪,Camel 的错误处理程序和重新交付从失败的步骤开始执行,而不是从路由的开始。

您可以再次调用 direct:anotherRoute 而不是抛出错误,唯一的问题是如果您这样做过于频繁,您的调用堆栈可能会变得太深。

您可以做的是将 nmr:kaboom 放入单独的路由中,并将其配置为具有 noErrorHandler,然后从第一个路由调用它使用 direct:,错误处理程序可以从头开始重新传递整个路由。

关于java - Camel 的重新投递政策,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31433213/

相关文章:

XML 解析快速访问 attributeDict

java - 使用 Apache Camel 事务时如何回滚文件写入?

java - 如何将 .jar 文件添加到 Java 代码

java - 将 CardView 添加到 FrameLayout 会忽略 CardView 的 XML 文件中定义的 LayoutParams

java - "wrong"使用 java Apache XML RPC 3.1.3 服务器响应的数组类型

java - Camel,Amazon SQS - 没有类型转换器可用于将类型 : java. lang.String 转换为所需类型 : com. amazonaws.services.sqs.AmazonSQS

java - 如果已定义(不为空),如何使用自定义处理器?

java - 如何在 Java 中生成随机颜色?

java - Maven 构建失败,超出 GC 开销限制

java - AlertDialog 上没有键盘,因为没有焦点在对话框上并且仍然在后台 Activity 上,如何解决?