简体   繁体   English

在Spring Integration中使用拦截器发送日志消息

[英]Sending Logging Message with Interceptor in Spring Integration

Is it possible to configure an interceptor in Spring Integration to specify a logging message? 是否可以在Spring Integration中配置拦截器以指定日志消息?

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. 有一会儿我以为我可以定义一个带有SpEL表达式的服务激活器,以在通道拦截器定义内生成字符串记录消息(以及所需记录通道的输出通道),但是它正在寻找输入通道。

Instead of using a wire-tap, you could make the channels you are interested in <publish-subscribe-channel/> s. 不用窃听,您可以创建对<publish-subscribe-channel/>感兴趣<publish-subscribe-channel/>

Subscribe the appropriate transformer to the channel (with an output-channel going to the logging adapter). 将适当的转换器订阅到通道(将output-channel发送到日志适配器)。

You can control whether the log happens before or after the real subscriber using the order attribute on the transformer and other subscriber. 您可以使用转换器和其他订户上的order属性控制日志是发生在实际订户之前还是之后。

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. 然后将其发送到<header-value-router/> ,后者依次路由到适当的转换器,再路由到单个日志记录通道适配器。

Of course, if you want, you can combine the routing and/or transforming right into the interceptor. 当然,如果您愿意,可以将路由和/或转换合并到拦截器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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