當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。