如何从主体对象中的Exchange对象中获取标头



我在函数中设置了头,然后将Exchange对象保存到列表中。newExchange.`in`.setHeader("aggregationCount", 3)

然后我稍后尝试检索这个头,我可以在对象中看到它,它在Exchange.in.body.in.headers的路径中——我该如何访问这个变量,我尝试过(e.`in`.getHeader("aggregationCount"),但它不起作用。我只需要在Exchange对象上传递一个变量/属性,如果有其他方法可以做到这一点,请告诉我,我可以改为使用它。

在Camel路由中,您可以简单地使用.header("HeaderName"(来返回标头值。在这种情况下,类似于:

.header("aggregationCount")

或者,如果您需要在条件中使用值:

.when(header("aggregationCount").isGreaterThan(0))

https://camel.apache.org/components/latest/languages/header-language.html

为了回答您的另一个问题,您还可以使用exchangeProperty来存储和检索值。

https://camel.apache.org/components/3.4.x/languages/exchangeProperty-language.html

最新更新