我的服务使用paho mqtt时出现问题。超时,但没有报告连接丢失。有人能解决这个问题吗?
public void connect(String client_id) {
String tmpDir = System.getProperty("java.io.tmpdir");
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence( tmpDir );
MqttConnectOptions options = new MqttConnectOptions();
options.setKeepAliveInterval(120);
try {
_client = new MqttClient( _url, MqttClient.generateClientId(), dataStore );
_client.connect( options );
_client.setCallback( this );
_client.subscribe( TOPIC );
LOGGER.info("Subscribed to " + Arrays.toString(TOPIC));
LOGGER.info("MAX CORES " + MAX_CORES);
} catch ( MqttException e ) {
LOGGER.log( Level.INFO, "Mosquitto Error: " + e.fillInStackTrace() );
connect(null);
}
}
@Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
threadPool.execute(new Runnable(){// code});
}
使用mqtt v1.0.0
Nov 6, 2015 2:36:52 AM org.eclipse.paho.client.mqttv3.internal.ClientState checkForActivity
SEVERE: paho-595916529752865: Timed out as no activity, keepAlive=120,000 lastOutboundActivity=1,446,777,172,455 lastInboundActivity=1,446,777,117,734 time=1,446,777,412,455 lastPing=1,446,777,172,454
作为一个快速修复
刚刚设置:
setConnectionTimeout(0)
使用零禁用超时。
setConnectionTimeout public void setConnectionTimeout(intconnectionTimeout)设置连接超时值。这个值,以秒为单位,定义客户端将要使用的最大时间间隔等待建立到MQTT服务器的网络连接。默认超时为30秒。值0禁用超时处理意味着客户端将等待网络连接成功或失败。参数:connectionTimeout-超时值,以秒为单位。它必须大于0;
希望它能帮上忙。