当前位置: 首页>>代码示例>>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;未经允许,请勿转载。