當前位置: 首頁>>代碼示例>>Java>>正文


Java MqttClient.unsubscribe方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:AppLozic,項目名稱:Applozic-Android-Chat-Sample,代碼行數:22,代碼來源:ApplozicMqttService.java

示例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();
    }
}
 
開發者ID:AppLozic,項目名稱:Applozic-Android-Chat-Sample,代碼行數:22,代碼來源:ApplozicMqttService.java

示例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();
  }
}
 
開發者ID:vert-x3,項目名稱:vertx-mqtt,代碼行數:30,代碼來源:MqttServerUnsubscribeTest.java

示例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();
    }

}
 
開發者ID:EnMasseProject,項目名稱:enmasse,代碼行數:26,代碼來源:UnsubscribeTest.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttClient.unsubscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。