有没有办法设置来自bean的消息头? [英] Is there a way to set message headers from a bean?
问题描述
我有一条需要修改的简单骆驼路线.路线如下所示:
I have a simple camel route I need to modify. The route looks like this:
from(source.uri)
.unmarshal()
.bean(TransformMessageBean.class, "SomeMethod")
.to(destination.uri)
我想在解组设置头信息的值后添加另一个bean方法调用,而不会破坏当前的数据流.有人知道这样做的方法吗?我在apache的文档中了解到,出站消息正文中设置了bean的返回值.有没有办法将其更改为标题?
I want to add another bean method call after the unmarshaling that set's a header value without disrupting the current data flow . Does anyone know of a way to do this? I read that in apache's documentation that a bean's return value is set in the outbound message body. Is there a way to change that to a header?
提前谢谢!
推荐答案
当然!可用的选项之一是
Certainly! One of the options available is
.setHeader("headerName").method(beanInstance, "methodToGetHeaderValue")
使用这种方法,提供的bean实例上的方法(例如methodToGetHeaderValue
)将返回一个值,该值将成为标头的值.
Using this approach, the method (say, methodToGetHeaderValue
) on the provided bean instance will return a value, and that will become the value of the header.
有许多可用的选项.您可以将其称为一个bean类(例如您的示例),甚至是一个bean名称,全部带有或不带有方法名称.
There are a number of options available. You can call it with a bean instance, a bean class (like in your example), or even a bean name, all with or without a method name.
这篇关于有没有办法设置来自bean的消息头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!