@IocBean(name = "mqttClient", depose = "close")
    public MqttClient createMqttClient(@Inject MqttConnectOptions mqttConnectOptions, @Inject MqttClientPersistence mqttClientPersistence) throws MqttException {
        String clientId = conf.get(PROP_CLIENT_ID);
        if (Strings.isBlank(clientId)) {
            clientId = MqttClient.generateClientId();
        }
        log.info("Client Id = " + clientId);
        MqttClient client = new MqttClient(conf.get(PROP_URL, "tcp://127.0.0.1:1883"), clientId, mqttClientPersistence);
        if (ioc.has("mqttCallback")) {
            client.setCallback(ioc.get(MqttCallback.class, "mqttCallback"));
        }
        client.setTimeToWait(conf.getLong(PROP_TIME_TO_WAIT, -1));
        if (conf.getBoolean(PROP_CONNECT_ON_START, true)) {
            IMqttToken token = client.connectWithResult(mqttConnectOptions);
            if (token.getException() != null)
                throw token.getException();
        }
        return client;
    }
@ IocBean ( name = "mqttClient" , depose = "close" ) public MqttClient createMqttClient ( @ Inject MqttConnectOptions mqttConnectOptions , @ Inject MqttClientPersistence mqttClientPersistence ) throws MqttException { String clientId = conf . get ( PROP_CLIENT_ID ) ; if ( Strings . isBlank ( clientId ) ) { clientId = MqttClient . generateClientId ( ) ; } log . info ( "Client Id = " + clientId ) ; MqttClient client = new MqttClient ( conf . get ( PROP_URL , "tcp://127.0.0.1:1883" ) , clientId , mqttClientPersistence ) ; if ( ioc . has ( "mqttCallback" ) ) { client . setCallback ( ioc . get ( MqttCallback . class , "mqttCallback" ) ) ; } client . setTimeToWait ( conf . getLong ( PROP_TIME_TO_WAIT , - 1 ) ) ; if ( conf . getBoolean ( PROP_CONNECT_ON_START , true ) ) { IMqttToken token = client . connectWithResult ( mqttConnectOptions ) ; if ( token . getException ( ) != null ) throw token . getException ( ) ; } return client ; }
同步阻塞客户端, 然后它不支持通过MqttAsyncClient来构建,真蛋疼