我如何解决这个问题mqtt Paho超时,但没有报告连接丢失

时间:2015-11-05 09:35:45

标签: java mqtt paho

使用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 v 1.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

1 个答案:

答案 0 :(得分:0)

快速修复

刚设置:

setConnectionTimeout(0)使用零来禁用超时。

  

setConnectionTimeout public void setConnectionTimeout(int   connectionTimeout)设置连接超时值。这个值,   以秒为单位测量,定义客户端的最大时间间隔   等待建立MQTT服务器的网络连接。   默认超时为30秒。值为0将禁用超时   处理意味着客户端将等到网络连接   成功或失败。参数:connectionTimeout -   超时值,以秒为单位。它必须是> 0;

希望它能帮到你。