本文整理汇总了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);
}
});
}
}
示例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();
}
示例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);
}
});
}
});
}
}
示例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;
}