2016-05-16 42 views
0

我正在嘗試在請求 - 響應調用與QPID端點之間的駝峯交換中保存一個值。Apache Camel - 無法在請求 - 響應之間傳播JMS標頭屬性

您可以從我的代碼中看到我在調用端點之前設置了Header(和Property)。返回時,相同的標題和屬性值爲空。

我基本上要保持文件名和文件路徑的軌道,這樣我可以把結果寫入到同一位置

與此真正地奮鬥。

import org.apache.camel.builder.RouteBuilder; 
import org.springframework.beans.factory.annotation.Value; 

public class ProcessingRoute extends RouteBuilder { 

    @Override 
    public void configure() throws Exception { 

    //@formatter:off 
     from("file:/home/molko/in/?recursive=true&include=.*.txt") 
      .log("File read from disk : ${file:name}") 
      .doTry() 
       .setHeader("JMSReplyTo", constant("response-1"; {create:always, node:{type:queue}}")) 
       .setHeader("JMSCorrelationID", constant(java.util.UUID.randomUUID().toString())) 

       .process(new Processor() { 
        @Override 
        public void process(Exchange exchange) throws Exception { 

         final String fileParent = exchange.getIn().getHeader("CamelFileParent", String.class); 
         final String endPath = fileParent.substring(fileParent.lastIndexOf('/') + 1); 

         exchange.getIn().setHeader("endPath", endPath); 
         exchange.setProperty("endPath", endPath); 
        } 

       })     

       .to(amqp:request-1;{node:{type:queue}}?preserveMessageQos=true?exchangePattern=InOut") 
      .doCatch(Exception.class) 
       .log("Failed : ${file:name}") 
       .log("${exception.stacktrace}") 
      .stop(); 

     from("amqp:response-1; {create:always, node:{type:queue}}") 
      .log("Received from qpid broker : ${date:now}") 
      .doTry() 
       .process(new Processor() { 
        @Override 
        public void process(Exchange exchange) throws Exception { 

         byte[] response = exchange.getIn().getBody(byte[].class); 

         System.out.println("properties : " + exchange.getProperties()); 
         System.out.println("headers : " + exchange.getIn().getHeaders()); 
         }    
        })    
       .to("file:/home/molko/out") 
      .doCatch(Exception.class) 
       .log("Failed from qpid brokre : ${date:now}") 
       .log("${exception.stacktrace}") 
      .stop(); 
    //@formatter:on 
    } 
} 

回答

0

includeAllJMSXProperties可能是你在找什麼,

駱駝2.11.2/2.12:是否包括所有JMSXxxx屬性時,從JMS駱駝消息 映射。當設置爲true屬性時,例如 將包括JMSXAppID和JMSXUserID等。注意:如果您使用 自定義headerFilterStrategy,則此選項不適用。

來源:https://camel.apache.org/jms.html