-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
In what version(s) of Spring Integration are you seeing this issue?
sprint-boot 2.7.5
spring-integration-mqtt 5.5.15
org.eclipse.paho.mqttv5.client 1.2.5
Describe the bug
If an MQTTv5 broker disconnects a client via a disconnect message then MqttConnectionFailedEvent is never triggered.
To Reproduce
@EventListener
public void handleFailedEvent(MqttConnectionFailedEvent mfe) {
System.out.println("MqttConnectionFailedEvent "+mfe.getCause().getMessage());
}
and trigger a disconnect event from the broker.
Expected behavior
MqttConnectionFailedEvent is called.
Details
The problem occurs because
org.eclipse.paho.mqttv5.client.internal.CommsCallback:
public void connectionLost(MqttException cause, MqttDisconnect message) {
final String methodName = "connectionLost";
// If there was a problem and a client callback has been set inform
// the connection lost listener of the problem.
try {
if (mqttCallback != null && message != null) {
MqttDisconnectResponse disconnectResponse = new MqttDisconnectResponse(message.getReturnCode(),
message.getProperties().getReasonString(),
(ArrayList<UserProperty>) message.getProperties().getUserProperties(),
message.getProperties().getServerReference());
mqttCallback.disconnected(disconnectResponse);
this constructur does not set the cause as exception in MqttDisconnectResponse.
public MqttDisconnectResponse(int returnCode, String reasonString, ArrayList<UserProperty> userProperties,
String serverReference) {
this.returnCode = returnCode;
this.reasonString = reasonString;
this.userProperties = userProperties;
this.serverReference = serverReference;
}
this disconnectResponse eventually triggers disconnected in Mqttv5PahoMessageDrivenChannelAdapter. The check cause != null is false (because cause == null) and thus the event is never publisher.
public void disconnected(MqttDisconnectResponse disconnectResponse) {
MqttException cause = disconnectResponse.getException();
ApplicationEventPublisher applicationEventPublisher = getApplicationEventPublisher();
if (cause != null && applicationEventPublisher != null) {
applicationEventPublisher.publishEvent(new MqttConnectionFailedEvent(this, cause));
}
}