我有2个相同的电话:
String msg1 = exchange.getIn().getBody(String.class);
String msg2 = exchange.getIn().getBody(String.class);
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
处理器仅包含上面的2个语句.route1中的处理是正确的,但是在route2中我得到了描述的行为:第一次调用 - 有效字符串,第二次调用 - 空字符串.所以我想也许它与HttpMessage转换有关.
Ser*_*gey 11
来自http://camel.apache.org/jetty.html
Jetty是基于流的,这意味着它接收的输入作为流提交给Camel.这意味着您只能读取一次流的内容.
只需转换String中的输入,然后再使用它两次或更多次
<route id="route2">
<from uri="jetty://http://localhost:8090" />
<convertBodyTo type="String" />
<process ref="messageProcessor" />
</route>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7343 次 |
| 最近记录: |