有没有办法从 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 类(就像你的例子),甚至 一个 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屋!