在activemq消息中设置对象属性

时间:2013-12-01 15:30:23

标签: java jms activemq apache-camel

如何在activemq消息中设置对象属性?

当我使用这种方法时,使用Apache Camel我什么也得不到!

在Activemq中:

        BytesMessage byteMessage = session.createBytesMessage();
        byteMessage.writeBytes(new byte[1]);
        byteMessage.setJMSReplyTo(tempDest);
        String correlationId = this.createRandomString();
        byteMessage.setJMSCorrelationID(correlationId);

        byteMessage.setStringProperty("param1", "x");

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("param3", "y");
        map.put("param4", "z");
        byteMessage.setObjectProperty("param2", map);

然后在Camel:

....
    .process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            Message in = exchange.getIn();
            System.out.println(in.getHeaders().keySet());

            Object map= in.getHeaders().get("param2");
            System.out.println(map);
            }
        })
    ;
keySet()中的

没有param2!并且最后一行的结果是NULL!

1 个答案:

答案 0 :(得分:2)

Map不是setObjectProperty的有效对象。来自Javadoc for Message:

“属性值可以是boolean,byte,short,int,long,float,double和String。”

http://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html