简体   繁体   中英

Sending Logging Message with Interceptor in Spring Integration

Is it possible to configure an interceptor in Spring Integration to specify a logging message?

This is in contrast to using a wire-tap to send the message to a logging channel to which a logging channel adapter subscribes. The problem with this approach is that the logging channel has the expression for what exactly to log. In my use case I'd like to use a global channel-interceptor to specify a logging message and send it to a logging channel adapter, rather than having to define a logging channel adapter for every possible logging message I might want.

For a moment I thought I could define a service activator with an SpEL expression to produce the string logging message (and with an output-channel of the deisred logging channel) inside a channel-interceptor definition, but it's looking for an input-channel.

Instead of using a wire-tap, you could make the channels you are interested in <publish-subscribe-channel/> s.

Subscribe the appropriate transformer to the channel (with an output-channel going to the logging adapter).

You can control whether the log happens before or after the real subscriber using the order attribute on the transformer and other subscriber.

Another alternative is a global interceptor that adds a header to the message

MessageBuilder.fromMessage(message).setHeader('foo', routeForThisMessageType).build()

Then send it to a <header-value-router/> which, in turn, routes to the appropriate transformer, and thence to the single logging channel adapter.

Of course, if you want, you can combine the routing and/or transforming right into the interceptor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM