本文整理匯總了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();
}
}