Reputation: 382
I implemented the ChannelInterceptor and got it working by configuring on xml. But it is not working with annotation based bean configuration.
trying to bring this to work -
@Bean
@ConditionalOnProperty(name="enableLog", havingValue="true")
@GlobalChannelInterceptor(patterns="${message.input.channel},${message.output.channel},${message.error.channel},${message.exception.channel}")
public ChannelInterceptor messageChannelInterceptor() {
ChannelInterceptor channelInterceptor = new MessageChannelInterceptor();
return channelInterceptor;
}
Upvotes: 2
Views: 1396
Reputation: 174729
What's "not working"; the patterns? the condition?
I just wrote this test app and it works fine...
@SpringBootApplication
public class So36483811Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(So36483811Application.class, args);
context.getBean("channel", QueueChannel.class).send(new GenericMessage<>("foo"));
context.close();
}
@Bean
@GlobalChannelInterceptor(patterns="*")
public ChannelInterceptor messageChannelInterceptor() {
ChannelInterceptor channelInterceptor = new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
System.out.println("Here: " + message);
return message;
}
};
return channelInterceptor;
}
@Bean
public QueueChannel channel() {
return new QueueChannel();
}
}
and
Here: GenericMessage [payload=foo, headers={id=89770de1-9404-1930-283c-1d74fbb06916, timestamp=1460054756722}]
Upvotes: 1