INT-3469 MQTT - Set Callback Before Subscribing

JIRA: https://jira.spring.io/browse/INT-3469

Previously, the callback was set immediately after
subscribing which caused a small possibility of
message loss.

Set the callback before subscribing.
This commit is contained in:
Gary Russell
2014-07-09 11:21:23 -04:00
parent e9ad73ad2c
commit cef58dae34

View File

@@ -97,6 +97,7 @@ public class MqttPahoMessageDrivenChannelAdapter extends AbstractMqttMessageDriv
private void connectAndSubscribe() throws MqttException {
this.client = this.clientFactory.getClientInstance(this.getUrl(), this.getClientId());
this.client.setCallback(this);
this.client.connect(this.clientFactory.getConnectionOptions());
try {
this.client.subscribe(this.getTopic());
@@ -106,7 +107,6 @@ public class MqttPahoMessageDrivenChannelAdapter extends AbstractMqttMessageDriv
throw e;
}
if (this.client.isConnected()) {
this.client.setCallback(this);
this.connected = true;
if (this.reconnectFuture != null) {
this.cancelReconnect();