【问题标题】:Exchange.getIn().getBody() returns empty string in camel on second callExchange.getIn().getBody() 在第二次调用时以骆驼形式返回空字符串
【发布时间】:2015-06-25 10:40:01
【问题描述】:

我有 2 个相同的电话:

String msg1 = exchange.getIn().getBody(String.class);
String msg2 = exchange.getIn().getBody(String.class);

在 msg1 中,我得到了正确的期望值,但 msg2 是一个空字符串。我没有设置 Out 消息,因此交换 In 消息应该仍然完好无损。请解释为什么会这样。

骆驼路线:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route id="route1">
        <from uri="timer://myTimer?period=2000" />
        <setBody>
            <simple>Hello World ${header.firedTime}</simple>
        </setBody>
        <process ref="messageProcessor" />
        <to uri="http://localhost:8090"/>
    </route>
    <route id="route2">
        <from uri="jetty://http://localhost:8090" />
        <process ref="messageProcessor" />
    </route>
</camelContext>

处理器仅包含上面的 2 条语句。 route1 中的处理是正确的,但在 route2 中我得到了所描述的行为:第一次调用 - 有效字符串,第二次调用 - 空字符串。所以我想可能和HttpMessage转换有关。

【问题讨论】:

  • 请添加路由源码

标签: java apache-camel


【解决方案1】:

来自http://camel.apache.org/jetty.html

Jetty 是基于流的,这意味着它接收到的输入被提交 以骆驼为溪流。这意味着您将只能阅读 流的内容一次。

在使用两次或更多次之前将输入转换为字符串

<route id="route2">
    <from uri="jetty://http://localhost:8090" />
    <convertBodyTo type="String" />
    <process ref="messageProcessor" />
</route>

【讨论】:

  • 我为 route 尝试了 streamCache="true" ,或者将 exchange.in 正文设置为字符串值,它可以工作。非常感谢!
猜你喜欢
  • 2015-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-29
  • 2020-10-01
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多