Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use logging-channel-adapter in Spring Integration to log a message header value

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?

like image 889
kosoant Avatar asked Mar 28 '11 11:03

kosoant


People also ask

What is SubscribableChannel?

Interface SubscribableChannelA MessageChannel that maintains a registry of subscribers and invokes them to handle messages sent through this channel.

What is Adapter in Spring Integration?

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.

What is direct channel in Spring Integration?

A channel that invokes a single subscriber for each sent Message. The invocation will occur in the sender's thread.

What is a logging channel?

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.


1 Answers

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.

like image 136
kosoant Avatar answered Sep 22 '22 07:09

kosoant