2017-09-14 31 views
1

我正在使用http服務的合成請求消息。InOut交換模式有Out始終爲空

Order finalOrder = (Order) producerTemplate.requestBody("direct:processRequests", myOrder); 

我打電話以上code.and路線我知道requestBody()方法使用的InOut pattern.But當我試圖檢查最終交換是否有出的消息是虛報。

@Override 
    public void configure() throws Exception { 

     /*onException(Exception.class) 
     .handled(true);*/ 

     from("direct:processRequests") 
       .split(body().method("getItems"), new GroupedBodyAggregationStrategy()) 
       .parallelProcessing() 
       .to("direct:processRequest") 
       .end() 
     .end(); 


     from("direct:processRequest") 
     .choice() 
     .when(body().method("getHttpDetails").method("getCallType").isEqualTo("POST")) 
      .setHeader(Exchange.HTTP_METHOD, body().method("getHttpDetails").method("getCallType")) 
      .setProperty("sendTo",body().method("getEndPointUri")) 
      .setBody(body().method("getPayload")) 
      .toD("${exchangeProperty.sendTo}") 
} 
} 

我能夠在In消息中獲得響應正文,而不是Out.I正在處理aggitor類中的交換。

@Override 
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { 
    if (oldExchange == null) { 
     System.out.println("hasout "+newExchange.hasOut()); 
     // remaining code 

newExchange.hasOut()總是false.Message是在消息話題。可在傳播任一項解釋如何在傳播出的消息最終響應消息。 在此先感謝。

+0

看到這個FAQ:http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html –

+1

感謝您的回覆。但我不明白如何使路線提到以上使用InOut模式。我想在Out消息中提供最終響應。 – sasidhar

回答

0

您可能需要設置ExchangePattern到INOUT權之前,你TOD(..)調用,像這樣:同樣

.setExchangePattern(ExchangePattern.InOut) 
.toD("${exchangeProperty.sendTo}") 

,你嘗試過使用recipientList?自從我運行較早版本的Camel後,我只用它來做你想做的事情。要做到這一點,你可以用類似的東西替換你的toD(..):

.setExchangePattern(ExchangePattern.InOut) 
recipientList(simple("${exchangeProperty.sendTo}")) 

讓我知道這些方法是否有效。

+0

我嘗試了兩種方法,但都沒有奏效。 – sasidhar

0

由於駱駝Exchange文檔在Flow of an exchange through a route section說:

從每個步驟的出消息作爲在消息下一 一步

這可能是爲什麼你遇到你的問題。在我的經驗中,反應是幾乎從來沒有在出消息,我只是把它如下(如果需要)複製到了消息:

.process(new Processor() { 
    @Override 
    public void process(Exchange exchange) throws Exception { 
     exchange.setOut(exchange.getIn()); 
    } 
}) 

這通常是沒有必要的,但是。