With Spring 5.3.29, how can I detect that a MessageDriveChannelAdapter
is connected to JMS without receiving a message.
Currently, I have;
IntegrationFlows.from(
Jms
.messageDrivenChannelAdapter(connectionFactory)
.destination(myDestination)
.errorChannel(myErrorChannel)
.configureListenerContainer(c -> {
c.errorHandler(...);
c.exceptionListener(...);
})
.handle(...)
.get();
By implementing the ErrorHandler
and ExceptionListener
I can alert that we are not connected. I could implement "clear alert" logic in the handle()
, but I want to "clear" without getting a message.
There is no event like that in Spring JMS, nor JMS spec by itself. And probably there is indeed no reason in it: when you receive a message in the handle()
, that's definitely an indicator that connection to JMS broker was OK. If connection fails, that exceptionListener()
would do that trick.
You can do that "clear" logic in the ChannelInterceptor
before that handle()
.
See intercept()
DSL operator:
/**
* Add one or more {@link ChannelInterceptor} implementations
* to the current {@link #currentMessageChannel}, in the given order, after any interceptors already registered.
* @param interceptorArray one or more {@link ChannelInterceptor}s.
* @return the current {@link BaseIntegrationFlowDefinition}.
* @throws IllegalArgumentException if one or more null arguments are provided
* @since 5.3
*/
public B intercept(ChannelInterceptor... interceptorArray) {