【问题标题】:Apache Camel inOut routes, out exchange marshaling/unmarshaling with jaxbApache Camel inOut 路由,使用 jaxb 交换编组/解组
【发布时间】:2011-07-24 07:55:24
【问题描述】:

我们有这条 apache 骆驼路线,

from(commandDrop).marshal(jaxbDataFormat).to(jmsQueue);    
from(jmsQueue).inOut("jms:doCommand?requestTimeout=500000");          
from("jms:doCommand").unmarshal(jaxbDataFormat).beanRef("bean");

....还有一个像这样的bean类

class BeanClass {
        public void doCommand(Command command, Exchange exchange){
    {       
        command.run();      
        exchange.getOut().setBody(command);     
    }
}

我们试图在这样的路线上发送消息并等待回复

Object ret = template.requestBody(commandDrop, new TestCommand());

正向路线上的对象正在出色地编组/取消编组。但是 setBody 调用会导致 java.io.NotSerializableException。有没有办法配置路由以在返回的路上使用相同的 jaxb 编组/解组?我的 Command 类包含一些 jaxb 生成的不可序列化的类对象。他们在前进方向上由元帅/解组员很好地处理,如果他们能在回来的路上会很棒。我对骆驼比较陌生,所以不确定这是否是最好的方法。

非常感谢。

【问题讨论】:

    标签: activemq apache-camel


    【解决方案1】:

    您可以在 bean 调用之后对其进行编组

    from("jms:doCommand").unmarshal(jaxbDataFormat).beanRef("bean").marshal(jaxbDataFormat);
    

    【讨论】:

    • 啊哈。这将在调用端返回一个字节数组。我可以像这样解组, retCommand = (Command) jaxbContext.createUnmarshaller().unmarshal(new ByteArrayInputStream(ret));谢谢!
    猜你喜欢
    • 2016-06-20
    • 1970-01-01
    • 2016-09-29
    • 2012-12-21
    • 1970-01-01
    • 2021-08-26
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多