Apache Camel - Delay when exception occurs

寵の児 提交于 2020-01-17 01:53:08

问题


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.

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>

回答1:


Did you try redeliveryDelay of redeliveryPolicyProfile?

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" />

Read more on here




回答2:


By making below modification in my bundle context (bundle context displayed above), re-delivery policy kicked in and seems to do the trick.



来源:https://stackoverflow.com/questions/30170022/apache-camel-delay-when-exception-occurs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!