【问题标题】:Apache Camel : Custom Redelivery PolicyApache Camel:自定义重新交付策略
【发布时间】:2020-07-13 17:28:30
【问题描述】:

我有一条调用外部休息服务的路线。我已经配置了我的错误处理程序,如下所示。

errorHandler(deadLetterChannel("jms:dlc").maximumRedeliveries(3));

我想做什么:

  • 如果连接外部api失败,我想重试3次,然后发送到deadLetterChannel

  • 如果 api 调用正常,我想检查状态码,记录响应,然后将消息发送到 deadLetterChannel。

为此,我将 throwExceptionOnFailure 设置为 false。

在我的路线中,我有一个 bean 作为最后一个端点。此 bean 接收来自外部端点的响应并检查状态。

void process(Exchange exchange){
  //check http status code
  //if not success
  exchange.setProperty(Exchange.ROUTE_STOP,true);
  //sendToDeadLetterQueue;
  }

我的问题是即使我能够连接到 API,也会发生重新交付。我希望重新交付会发生错误。但我正在处理响应并将交换设置为停止。

我可以停止从我的 bean 中重新交付吗?

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    您可以按如下方式使用 onException:

    <onException>
       <exception>SomeException</exception>
       <handled><constant>true</constant></handled>
       <process ref="failureResponse"/>
    </onException
    

    【讨论】:

      【解决方案2】:

      使用 onException 标记作为 true 处理

      Java DSL

      onException(ExceptionClass).handled(true) .to(deadLetterChannel);

      Spring DSL:

      <onException>
      <exception>SomeException</exception>
         <handled><constant>true</constant></handled>
         <to uri=deadLetterChannel/>
      </onException>

      更多说明请点击here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-09
        • 1970-01-01
        • 1970-01-01
        • 2015-06-23
        相关资源
        最近更新 更多