有没有办法从 bean 设置消息头? [英] Is there a way to set message headers from a bean?

查看:27
本文介绍了有没有办法从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆