【问题标题】:Circuit Breaker for asynchronous channel along with Dead Letter Channel异步通道的断路器以及死信通道
【发布时间】:2021-08-20 15:05:53
【问题描述】:

我需要将断路器与死信通道 (DLC) 一起使用。错误输出的消息应发送至 DLC。当电路打开时,不应使用其他消息。 现在我已经实现如下:

public void configure() throws Exception {
// @formatter:off

    int threshold = 2;
    long failureWindow = 30000;
    long halfOpenAfter = 120000;
    RoutePolicy routePolicy = 
      new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null);

    errorHandler(deadLetterChannel("seda:errorQueue").
               useOriginalMessage().maximumRedeliveries(3).redeliveryDelay(1000));



    from("timer://myTimer?period=5s")
    .routeId("InputFolderToTestSedaRoute")
    .setBody(exchangeProperty(Exchange.TIMER_FIRED_TIME))
    .convertBodyTo(String.class)
    .to("seda://testSeda")
    .log("**** Input data published to  testSeda - ${body}***** :")
    ;

    from("seda://testSeda")
    .routeId("TestSedaToOutputFolderRoute")
    .routePolicy(routePolicy)
    .to("file://{{outputFolder}}?autoCreate=false&fileName=TimerFile-${exchangeProperty.CamelTimerCounter}")
    ;

    //Error Handling route!

    from("seda:errorQueue")
    .routeId("ErrorHandlingRoute")
    .log("***** error body: ${body} *****")
    .to("file://{{errorFolder}}?fileName=TimerFile-${exchangeProperty.CamelTimerCounter}.txt")
    .log("***** Exception Caught: ${exception} *****")
    ;

    // @formatter:on

}

问题是,如果启用 DLC,这将无法按预期工作。但是,如果我注释以“errorHandler(deadLetterChannel()”开头的行,它将起作用 - 意味着上述代码仅适用于默认错误处理程序。

我的问题是 - 我希望错误消息进入错误队列并且我希望启用断路器。有什么办法吗?非常感谢您的宝贵时间。

【问题讨论】:

    标签: design-patterns apache-camel eai


    【解决方案1】:

    我解决了这个问题。我只是添加了以下内容,而不是 DLC:

    onException(GenericFileOperationFailedException.class).handled(false).to("seda:errorQueue");
    

    这解决了问题。

    【讨论】:

    • 太棒了!请记住,到达“seda:error”端点的是捕获异常时交换的当前状态。一般来说,我们对 original 消息感兴趣(cfr useOriginaMessage on DLC)
    • 是的,我后来添加了它,当我测试时发现了这一点。感谢您的建议!甚至还添加了重试。
    猜你喜欢
    • 2021-09-19
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2014-03-27
    相关资源
    最近更新 更多