I have a question about spring.
I make a connection with MQTT broker using Spring-Paho MqttPahoMessageDrivenChannelAdapter
. Here is a java config part:
@Bean
@Description("mqtt inbound adapter: receives mqtt messages")
public MessageProducer mqttInboundAdapter() {
log.info("creating mqtt inbound adapter");
MqttPahoMessageDrivenChannelAdapter adapter =
new MqttPahoMessageDrivenChannelAdapter(
env.getProperty("mqtt.hostname")+":" +env.getProperty("mqtt.port"),
"myClient",
"#");
adapter.setCompletionTimeout(5000);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setQos(1);
adapter.setOutputChannel(mqttInputChannel());
adapter.setErrorChannel(mqttErrorChannel());
return adapter;
}
When the broker is off and the connection is not establiched the ConnectException
is thrown. It is great, but I want not only to see the trace of it in the log, but also receive a warning email.
I hoped that it could be realized with the help of mqttErrorChannel
, but ConnectException
is not the case of usage of error channels. Is there any way to catch the ConnectException to another channel or in another way?
Thank you in advance.
Starting with Spring Integration
4.2.2
theMqttConnectionFailedEvent
is emitted, when we lost connection or can't connect on subscribe.You can catch that
ApplicationEvent
for example with theApplicationEventListeningMessageProducer
and send it to the appropriate channel.See more information in the Reference Manual: http://docs.spring.io/spring-integration/reference/html/mqtt.html