2016-10-18 28 views
0

我有一個調用外部休息服務的路由。我已經配置了我的錯誤處理程序,如下所示。Apace Camel:自定義重新傳遞策略

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重新交付嗎?

回答

0

您可以使用onException的如下:

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

使用onException的標籤爲真

的Java DSL處理

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

春DSL:

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

更多的澄清點擊here