当前位置: 首页>>代码示例>>Java>>正文


Java MqttClient.close方法代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java MqttClient.close方法的具体用法?Java MqttClient.close怎么用?Java MqttClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.paho.client.mqttv3.MqttClient的用法示例。


在下文中一共展示了MqttClient.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMQtt

import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
@Test
public void testMQtt() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    MqttClient client = new MqttClient("tcp://localhost:" + MQTT_PORT, MqttClient.generateClientId(), new MemoryPersistence());
    client.connect();
    MqttComponent mqtt = new MqttComponent();
    mqtt.client = client;
    Publisher<byte[]> fromTopic = mqtt.from("input", byte[].class);
    Subscriber<byte[]> toTopic = mqtt.to("output", byte[].class);
    Flux.from(fromTopic)
        .log()
        .subscribe(toTopic);
    
    client.subscribe("output", (topic, message) -> {
        result = new Integer(new String(message.getPayload()));
        latch.countDown();
    });
    client.publish("input", new MqttMessage(new Integer(2).toString().getBytes()));
    client.publish("input", new MqttMessage(new Integer(2).toString().getBytes()));
    latch.await(100, TimeUnit.SECONDS);
    Assert.assertEquals(2, result, 0.1);
    client.disconnect();
    client.close();
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:25,代码来源:MqttTest.java

示例2: bruteDisconnect

import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
@Test
public void bruteDisconnect(TestContext context) {

  try {
    MemoryPersistence persistence = new MemoryPersistence();
    MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence);
    client.connect();
    client.close();
    context.assertTrue(false);
  } catch (MqttException e) {
    context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_CLIENT_CONNECTED);
    e.printStackTrace();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:15,代码来源:MqttServerDisconnectTest.java

示例3: doClose

import org.eclipse.paho.client.mqttv3.MqttClient; //导入方法依赖的package包/类
@Override
public void doClose(MqttClient client) throws Exception {
    try {
        doDisconnect(client);
    } finally {
        client.close();
    }
}
 
开发者ID:quarks-edge,项目名称:quarks,代码行数:9,代码来源:MqttConnector.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。