I have written mqtt client in java for mosquitto broker . it works for while but after sometime if there is no traffic between my client and mqtt broker it gets disconnected with following error:
org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity : Timed out as no activity, keepAlive=30,000 lastOutboundActivity=1,493,194,287,903 lastInboundActivity=1,493,194,270,964 time=1,493,194,317,903 lastPing=1,493,194,287,903
How do i stay connected to mqtt broker continuously? what configuration settings do i need to make ?
final String brokerUrl = AppProperties.getProperty(AppConstants.MQTT_BROKER);
final String clientId = "";
final String topic = AppProperties.getProperty(AppConstants.MQTT_TOPIC);
MemoryPersistence persistence = new MemoryPersistence();
try {
MqttClient sampleClient = new MqttClient(brokerUrl, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
if(!sampleClient.isConnected()){
sampleClient.connect(connOpts);
}
LOGGER.info("Mqtt Connected to broker: "+ brokerUrl);
sampleClient.setCallback(this);
sampleClient.subscribe(topic);
LOGGER.info("Subscribed");
LOGGER.info("Listening");
}
On Broker in the logs i am getting following error :
1493181236: Socket error on client , disconnecting.
Any help is appreciated. Thank you.