我需要使用键“foo_bar”记录消息头的值,以便当该头的值为“baz”时,日志消息看起来像这样:
Value of header foo_bar: baz
如何使用窃听和日志记录 channel 适配器进行此操作?
最佳答案
使用logging-channel-adapter的expression属性,并设置如下所示的窃听和logging-channel-adapter:
<integration:channel id="channel1">
<integration:interceptors>
<integration:wire-tap channel="loggingChannel1"/>
</integration:interceptors>
</integration:channel>
<integration:logging-channel-adapter
id="loggingChannel1"
expression="'Value of header foo_bar: '.concat(headers.foo_bar)"
level="DEBUG"
/>
使用expression属性时,根对象是spring集成消息。因此,表达式中的“ header ”会为您提供消息的 header 映射。
关于spring-integration - 如何在Spring Integration中使用logging-channel-adapter记录消息 header 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5458237/