当前位置: 首页>>代码示例>>Java>>正文


Java MQTT.callbackConnection方法代码示例

本文整理汇总了Java中org.fusesource.mqtt.client.MQTT.callbackConnection方法的典型用法代码示例。如果您正苦于以下问题:Java MQTT.callbackConnection方法的具体用法?Java MQTT.callbackConnection怎么用?Java MQTT.callbackConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.fusesource.mqtt.client.MQTT的用法示例。


在下文中一共展示了MQTT.callbackConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Start
public void start() throws URISyntaxException {
	if (host != null && !host.isEmpty() && port != null) {
		// create the MQTT client
		client = new MQTT();
		client.setHost(host, port);
		connection = client.callbackConnection();

		Log.info("{} is trying to connect to {}:{} ...", context.getInstanceName(), host, port);
		connection.connect(new org.fusesource.mqtt.client.Callback<Void>() {
			public void onFailure(Throwable throwable) {
				Log.error(context.getInstanceName() + " failed to connect to " + host + ":" + port, throwable);
			}

			public void onSuccess(Void v) {
				Log.info("{} connected to {}:{}", context.getInstanceName(), host, port);
			}
		});
	}
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:21,代码来源:MQTTPubClient.java

示例2: provideMqttConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Provides
@Singleton
public CallbackConnection provideMqttConnection(final MQTTProperties mqttProperties) throws Exception {
    MQTT mqtt = new MQTT();
    mqtt.setHost(mqttProperties.getBrokerHost(), mqttProperties.getBrokerPort());
    mqtt.setCleanSession(mqttProperties.isMqttcleanSession());
    mqtt.setClientId(mqttProperties.getMqttClientId());
    mqtt.setKeepAlive((short) mqttProperties.getMqttKeepAlive());
    mqtt.setUserName(mqttProperties.getMqttUsername());
    mqtt.setPassword(mqttProperties.getMqttPassword());

    return mqtt.callbackConnection();
}
 
开发者ID:dobermai,项目名称:mqtt-irc-bot,代码行数:14,代码来源:MqttBotModule.java

示例3: start

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Start
public void start() throws URISyntaxException {
    if (host != null && !host.isEmpty() && port != null) {
        // create the MQTT client
        client = new MQTT();
        client.setHost(host, port);

        connection = client.callbackConnection();
        connection.listener(this);

        Log.info("{} is trying to connect to {}:{} ...", context.getInstanceName(), host, port);
        connection.connect(new org.fusesource.mqtt.client.Callback<Void>() {
            public void onFailure(Throwable value) {
                Log.error("{} unable to connect to {}:{}", context.getInstanceName(), host, port);
            }

            public void onSuccess(Void v) {
                Log.info("{} connected to {}:{}", context.getInstanceName(), host, port);
                Topic[] topics = new Topic[] { new Topic(topic, QoS.EXACTLY_ONCE) };
                connection.subscribe(topics, new Callback<byte[]>() {
                    @Override
                    public void onSuccess(byte[] bytes) {
                        Log.info("{} subscribed to topic {}", context.getInstanceName(), topic);
                    }

                    @Override
                    public void onFailure(Throwable throwable) {
                        Log.error(context.getInstanceName()+" failed to subscribe to topic "+topic, throwable);
                    }
                });
            }
        });
    }
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:35,代码来源:MQTTSubClient.java

示例4: createConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
public CallbackConnection createConnection(String key, MQTT mqtt) {
	CallbackConnection conn = mqtt.callbackConnection();
	connections.put(key, conn);
	return conn;
}
 
开发者ID:emqtt,项目名称:mqtt-jmeter,代码行数:6,代码来源:ConnectionsManager.java


注:本文中的org.fusesource.mqtt.client.MQTT.callbackConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。