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

查看:33
本文介绍了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?

Did you try redeliveryDelay of redeliveryPolicyProfile?

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

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天全站免登陆