2016-05-16 43 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