I need to log the value of the message header with key "foo_bar" so that the log message looks something like this when the value of that header is "baz":
Value of header foo_bar: baz
How to do this with a wire-tap and logging-channel-adapter?
Interface SubscribableChannelA MessageChannel that maintains a registry of subscribers and invokes them to handle messages sent through this channel.
A channel adapter is a message endpoint that enables connecting a single sender or receiver to a message channel. Spring Integration provides a number of adapters to support various transports, such as JMS, file, HTTP, web services, mail, and more. Upcoming chapters of this reference guide discuss each adapter.
A channel that invokes a single subscriber for each sent Message. The invocation will occur in the sender's thread.
Each channel represents a specific way of writing log information. For example, the single channel writes log files to a single log file, while the slack channel sends log messages to Slack. Log messages may be written to multiple channels based on their severity.
Use the expression attribute of the logging-channel-adapter and set up the wire-tap and logging-channel-adapter something like this:
<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"
/>
When using the expression attribute, the root object is the spring integration message. So "headers" in the expression gets you the headers map of the message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With