Commit cb6e91277f8dad93a2f09d2f1d3efce35e9cd9e0

Authored by bdrlamb
Committed by Andrew Shvayka
1 parent 6e82f4c8

Fix MQTT inactivity disconnects

MQTT clients don't send PINGREQ messages if they've recently sent [UN]SUBSCRIBE/PUBLISH messages.  The MQTT server last activity timestamp is currently only updated in response to PINGREQ messages.  This causes the server to disconnect any clients that regularly send PUBLISH messages since they don't send PINGREQ. 

This change adds reportActivity calls in response to PUBLISH, SUBSCRIBE and UNSUBSCRIBE in addition to PINGREQ.
@@ -138,12 +138,24 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -138,12 +138,24 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
138 break; 138 break;
139 case PUBLISH: 139 case PUBLISH:
140 processPublish(ctx, (MqttPublishMessage) msg); 140 processPublish(ctx, (MqttPublishMessage) msg);
  141 + transportService.reportActivity(sessionInfo);
  142 + if (gatewaySessionHandler != null) {
  143 + gatewaySessionHandler.reportActivity();
  144 + }
141 break; 145 break;
142 case SUBSCRIBE: 146 case SUBSCRIBE:
143 processSubscribe(ctx, (MqttSubscribeMessage) msg); 147 processSubscribe(ctx, (MqttSubscribeMessage) msg);
  148 + transportService.reportActivity(sessionInfo);
  149 + if (gatewaySessionHandler != null) {
  150 + gatewaySessionHandler.reportActivity();
  151 + }
144 break; 152 break;
145 case UNSUBSCRIBE: 153 case UNSUBSCRIBE:
146 processUnsubscribe(ctx, (MqttUnsubscribeMessage) msg); 154 processUnsubscribe(ctx, (MqttUnsubscribeMessage) msg);
  155 + transportService.reportActivity(sessionInfo);
  156 + if (gatewaySessionHandler != null) {
  157 + gatewaySessionHandler.reportActivity();
  158 + }
147 break; 159 break;
148 case PINGREQ: 160 case PINGREQ:
149 if (checkConnected(ctx, msg)) { 161 if (checkConnected(ctx, msg)) {