2017-10-10 69 views
0

我正在基於webservice和jms隊列的駱駝動態路由管理器。我有這個以下結構:駱駝動態路由不轉發郵件

endpoint:cxf -> jms:queue -> dynamic routing to a jms:queue -> processing 

這裏是我的路由定義:

@Override 
public void configure() throws Exception { 
    routeDefinition = from(fromEndpoint).routeId(name) 
      .dynamicRouter(method(DynamicRoutingManager.class, "getRoute")).process(exchange -> { 
       final List<?> soaList = exchange.getIn().getBody(List.class); 
       final String type = (String) soaList.get(0); 
       final String documentNumber = (String) soaList.get(1); 
       final String productionStepNumber = (String) soaList.get(2); 
       final String message = (String) soaList.get(3); 

       final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type 
         + ", document number=" + documentNumber + ", production step number" + productionStepNumber 
         + ", message=" + message; 
       LOG.debug("==> message={}", messageToSend); 
       exchange.getOut().setBody(messageToSend); 
      }); // .to(DLQ); 
} 

,在這裏我的動態路由管理器(保持簡單):

public String getRoute(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) { 
    LOG.debug("========> BODY={}", body); 
    return "jms:topic:urgent_doc1_prod1"; 
} 

路線jms:topic:urgent_doc1_prod1在運行時定義並運行(在日誌中查看)

事實是wh恩我送一個這樣的請求(見下文),我收到了超時錯誤......

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://cxf.apache.org/wsse/handler/helloworld"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <hel:message> 
     <!--Optional:--> 
     <type>urgent</type> 
     <!--Optional:--> 
     <document_number>1</document_number> 
     <!--Optional:--> 
     <production_step_number>1</production_step_number> 
     <!--Optional:--> 
     <message>un message</message> 
     </hel:message> 
    </soapenv:Body> 
</soapenv:Envelope> 

因爲我覺得我的消息不forwared到第二JMS:隊列,所以可以做任何處理...

我做錯了什麼?

回答

0

使用recipientListtoD,如果你想將消息路由到一個動態的目標 - 看到這個常見問題:http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

動態路由器就像是while loop,保持路由,直到你告訴它停止空/空目的地。請參閱頂部的文檔:http://camel.apache.org/dynamic-router.html。而你的例子並沒有將它作爲硬編碼的目標值。

+0

感謝您的回答,但它不起作用。郵件列入'jms:topic:urgent_doc1_prod1',但從未出列並以DLQ結尾.. – ggwtf

+0

我不想問您的問題。您是否正在通過JMS進行某種請求/回覆,並希望駱駝在繼續之前等待回覆消息。 –

+0

我使用用戶界面在運行時動態創建路由,動態部分用於根據這些動態路由轉發消息(根據請求中定義的選項)。最後,目前,我只想發送一個處理過的消息(包含最初請求的內容) – ggwtf

0

其實,這是我的一個誤解。我沒有在動態路由之後獨立地聲明「from」路由,所以沒有消費者,所以超時。

@Override 
public void configure() throws Exception { 
    from(fromEndpoint).routeId(name + "a").recipientList(method(DynamicRoutingManager.class, "getRoute")); 

    from(toEndpoint).routeId(name + "b").process(exchange -> { 

     final List<?> soaList = exchange.getIn().getBody(List.class); 
     final String type = (String) soaList.get(0); 
     final Integer documentNumber = (Integer) soaList.get(1); 
     final Integer productionStepNumber = (Integer) soaList.get(2); 
     final String message = (String) soaList.get(3); 

     final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type 
       + ", document number=" + documentNumber + ", production step number" + productionStepNumber 
       + ", message=" + message; 

     LOG.debug("==> message={}", messageToSend); 
     exchange.getOut().setBody(messageToSend); 
    }); 
} 

使它起作用。