Search code examples
spring-integrationspring-integration-mqtt

Pausing and resuming MQTT Inbound Adapter


We have: a converter that takes the messages from mqtt topics, parses, processes those, and after specific validations sends them to the other messaging system. Should the target system be not reachable, we create a specific event and send this through the injected instance of org.springframework.context.ApplicationEventPublisher.

We would like to: in cases the target messaging system is not availbale, to be able to pause (and then later to resume) the consumption of our inbound MQTT adapters.

We do have a collection of references to those adapters, and would like to write the "Toggler" that implements the ApplicationListener and based on event either pauses or resumes the consumption.

As any instance of MessageProducerSupport the MqttPahoMessageDrivenChannelAdapter has the protected doStart() and doStop() methods. Should one try to use those for pausing/resuming purposes?


Solution

  • The MessageProducerSupport extends an AbstractEndpoint which implements a SmartLifecycle with public start() and stop(). You simple can call those to stop polling messages from MQTT and restart whenever you need.