From 7089f864d57798a4f95807182ffd2ecade3e6aa4 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 2 Oct 2013 13:44:52 -0400 Subject: [PATCH] INTEXT-89 Fix Inbound Stop When No Server The reconnection task was not canceled in doStop(). --- .../MqttPahoMessageDrivenChannelAdapter.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java index 36876c96ab..b66286fe4f 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java @@ -22,6 +22,7 @@ import org.eclipse.paho.client.mqttv3.MqttCallback; import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; + import org.springframework.integration.Message; import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory; import org.springframework.integration.mqtt.core.MqttPahoClientFactory; @@ -69,17 +70,28 @@ public class MqttPahoMessageDrivenChannelAdapter extends AbstractMqttMessageDriv @Override protected void doStop() { + this.cancelReconnect(); super.doStop(); try { this.client.unsubscribe(this.getTopic()); - this.client.disconnect(); - this.client.close(); - this.connected = false; - this.client = null; } catch (MqttException e) { - logger.error("Exception while unsubscribing and disconnecting", e); + logger.error("Exception while unsubscribing", e); } + try { + this.client.disconnect(); + } + catch (MqttException e) { + logger.error("Exception while disconnecting", e); + } + try { + this.client.close(); + } + catch (MqttException e) { + logger.error("Exception while closing", e); + } + this.connected = false; + this.client = null; } private void connectAndSubscribe() throws MqttException {