List of usage examples for org.springframework.messaging.support ExecutorSubscribableChannel addInterceptor
@Override public void addInterceptor(int index, ChannelInterceptor interceptor)
From source file:org.springframework.messaging.simp.broker.OrderedMessageSender.java
/** * Install or remove an {@link ExecutorChannelInterceptor} that invokes a * completion task once the message is handled. * @param channel the channel to configure * @param preservePublishOrder whether preserve order is on or off based on * which an interceptor is either added or removed. *///from w ww . j a v a2 s . co m static void configureOutboundChannel(MessageChannel channel, boolean preservePublishOrder) { if (preservePublishOrder) { Assert.isInstanceOf(ExecutorSubscribableChannel.class, channel, "An ExecutorSubscribableChannel is required for `preservePublishOrder`"); ExecutorSubscribableChannel execChannel = (ExecutorSubscribableChannel) channel; if (execChannel.getInterceptors().stream().noneMatch(i -> i instanceof CallbackInterceptor)) { execChannel.addInterceptor(0, new CallbackInterceptor()); } } else if (channel instanceof ExecutorSubscribableChannel) { ExecutorSubscribableChannel execChannel = (ExecutorSubscribableChannel) channel; execChannel.getInterceptors().stream().filter(i -> i instanceof CallbackInterceptor).findFirst() .map(execChannel::removeInterceptor); } }