本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttClient.unsubscribe方法的典型用法代码示例。如果您正苦于以下问题:Java MqttClient.unsubscribe方法的具体用法?Java MqttClient.unsubscribe怎么用?Java MqttClient.unsubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.paho.client.mqttv3.MqttClient
的用法示例。
在下文中一共展示了MqttClient.unsubscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unSubscribeToTypingTopic
import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
public synchronized void unSubscribeToTypingTopic(Channel channel) {
try {
String currentId = null;
if (channel != null) {
currentId = String.valueOf(channel.getKey());
} else {
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
currentId = mobiComUserPreference.getUserId();
}
final MqttClient client = connect();
if (client == null || !client.isConnected()) {
return;
}
client.unsubscribe("typing-" + getApplicationKey(context) + "-" + currentId);
Utils.printLog(context,TAG, "UnSubscribed to topic: " + "typing-" + getApplicationKey(context) + "-" + currentId);
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: unSubscribeToTypingTopic
import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
public synchronized void unSubscribeToTypingTopic(Channel channel) {
try {
String currentId = null;
if (channel != null) {
currentId = String.valueOf(channel.getKey());
} else {
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
currentId = mobiComUserPreference.getUserId();
}
final MqttClient client = connect();
if (client == null || !client.isConnected()) {
return;
}
client.unsubscribe("typing-" + getApplicationKey(context) + "-" + currentId);
Utils.printLog(context, TAG, "UnSubscribed to topic: " + "typing-" + getApplicationKey(context) + "-" + currentId);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: unsubscribe
import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
@Test
public void unsubscribe(TestContext context) {
this.subscribeAsync = context.async();
this.unsubscribeAsync = context.async();
try {
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
client.connect();
String[] topics = new String[]{MQTT_TOPIC};
int[] qos = new int[]{0};
client.subscribe(topics, qos);
this.subscribeAsync.await();
client.unsubscribe(topics);
this.unsubscribeAsync.await();
context.assertTrue(true);
} catch (MqttException e) {
context.assertTrue(false);
e.printStackTrace();
}
}
示例4: unsubscribe
import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
@Test
public void unsubscribe(TestContext context) {
try {
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_BIND_ADDRESS, MQTT_LISTEN_PORT), CLIENT_ID, persistence);
client.connect();
String[] topics = new String[]{ MQTT_TOPIC };
int[] qos = new int[]{ 1 };
// after calling subscribe, the qos is replaced with granted QoS that should be the same
client.subscribe(topics, qos);
client.unsubscribe(MQTT_TOPIC);
context.assertTrue(true);
} catch (MqttException e) {
context.assertTrue(false);
e.printStackTrace();
}
}