Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 骆驼的再交付政策_Java_Xml_Apache Camel - Fatal编程技术网

Java 骆驼的再交付政策

Java 骆驼的再交付政策,java,xml,apache-camel,Java,Xml,Apache Camel,我有一个小的路由,我想使用自定义的重新传递策略来重复向端点发送消息,但是这种行为非常奇怪。看起来,重新交付策略只是在重复一个错误抛出。我试图将所有exchange发送到路由的开头,但策略不起作用,因为每次都会创建: <route id="sampleRoute"> <from uri="direct:anotheRoute" /> <to uri="nmr:kaboom" />

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

        <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的错误处理程序和重新交付是从失败的步骤开始执行的,而不是从路由的开始

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


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

这并不奇怪,Camel的错误处理程序和重新传递从失败的步骤开始执行,不是从路线的开始

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


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

感谢您的解释。我将发布正确答案:

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

<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>

谢谢你的解释。我将发布正确答案:

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

<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>