Apache Camel-异常发生时延迟 [英] Apache Camel - Delay when exception occurs

查看:141
本文介绍了Apache Camel-异常发生时延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一条骆驼路线,它轮询一个文件夹,拾取请求,检查服务器上的内存消耗(在Java文件中).如果其阈值以下,则将请求丢弃到JMS队列上,否则将引发异常,然后再次选择该异常进行处理.

I have written a camel route that polls a file folder, picks up request, checks for memory consumption on server (in a java file). If its below threshold it drops the request on a JMS queue otherwise it throws an exception and picks it again for processing.

我需要做的是,当引发异常时,我需要将处理延迟可配置的时间,例如15分钟.这将使服务器有一些时间稳定下来,而不是保持不必要的轮询. 我正在使用骆驼的errorHandler机制,但是它似乎不起作用. Camle继续处理请求,没有任何延迟.请帮助解决此问题. 下面是捆绑软件上下文快照:

What i need to do is that when exception is thrown i need to delay processing for a configurable amount of time say 15 mins. This will give some time for server to stabilize instead of keeping it polling unnecessarily. I am using errorHandler mechanism of camel however it doesnt seem to work. Camle keeps on picking up the request without any delay. Please help with this issue. Below is the bundle context snapshot:

<camel:onException>
        <camel:exception>java.lang.Exception</camel:exception>
        <camel:redeliveryPolicy backOffMultiplier="500" />
        <camel:log message="Default error handler was called"></camel:log>
    </camel:onException>
            <camel:route>
                <!--  Reading from REST url -->
                <camel:from uri="<my url>" />
                <!--  If else loop -->
                <camel:choice>
                    <camel:when>
                        <camel:xpath>Some path</camel:xpath>
                        <!--  Parsing OrderNumber and OrderVersion-->
                        <camel:log message="Recieved request ${headers.OrderNumber}-${headers.OrderVersion}.xml"/>
                        <camel:setHeader headerName="OrderNumber">
                            <xpath>Some path</xpath>
                        </camel:setHeader>
                        <camel:setHeader headerName="OrderVersion">
                            <camel:xpath>Some path</camel:xpath>
                        </camel:setHeader>
                        <!-- Request being put in file folder -->
                        <to
                            uri="file:data/inbox?fileName=${header.OrderNumber}-${header.OrderVersion}.xml"
                            pattern="InOut" />
                    </camel:when>
                    <!--  For all other requests put on  queue -->
                    <camel:otherwise>
                        <camel:log message="Request ${headers.OrderNumber}-${headers.OrderVersion}.xml directly sent to  queue"/>
                            <to uri="my queue"
                                pattern="InOut" />
                    </camel:otherwise>
                </camel:choice>
            </camel:route>
            <camel:route errorHandlerRef="errorHandler">
            <!-- Route to put message from folder to JMS queue if memory consumption is below limit-->
                <camel:from uri="file:data/inbox"/>
                    <camel:process ref="checkMemoryConsumption"/>
                    <camel:convertBodyTo type="String" />
                    <camel:log message="Sucessfully processing service order ${headers.OrderNumber}-${headers.OrderVersion}.xml"/>
                    <to uri="my queue"
                            pattern="InOut" />
            </camel:route>

推荐答案

您尝试了redeliveryPolicyProfileredeliveryDelay吗?

以下策略配置文件将重试3次,每次尝试之间的延迟为1000mS.

Below policy profile will retry 3 times with the delay of 1000mS between each try.

<redeliveryPolicyProfile id="myRedeliveryProfile"
        maximumRedeliveries="3"
        redeliveryDelay="1000" allowRedeliveryWhileStopping="false"
        retryAttemptedLogLevel="INFO" />

此处

这篇关于Apache Camel-异常发生时延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆