Package org.eclipse.paho.client.mqttv3

Examples of org.eclipse.paho.client.mqttv3.MqttClient.publish()


        Session s = activeMQConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = s.createConsumer(s.createTopic("test"));

        MqttClient client = new MqttClient("tcp://localhost:" + mqttConnector.getConnectUri().getPort(), "clientid", new MemoryPersistence());
        client.connect();
        client.publish("test", "hello".getBytes(), 1, false);

        Message msg = consumer.receive(100 * 5);
        assertNotNull(msg);

        client.disconnect();
View Full Code Here


                        client.connect();
                        connectedDoneLatch.countDown();
                        sendBarrier.await();
                        for( int i=0; i < 10; i++) {
                           Thread.sleep(1000);
                           client.publish("test", "hello".getBytes(), 1, false);
                        }
                        client.disconnect();
                        client.close();
                    } catch (Throwable e) {
                        e.printStackTrace();
View Full Code Here

    MqttMessage mqttMessage = new MqttMessage();
    mqttMessage.setPayload(data.getBytes());
    try {
      client = factory.getClientInstance("tcp://" + host + ":" + port, "guest");
      client.connect();
      client.publish("xd.mqtt.test", mqttMessage);
      try {
        Thread.sleep(1000);
      }
      catch (InterruptedException e) {
        Thread.currentThread().interrupt();
View Full Code Here

    private void publish(MqttClient client, String topicName, int qos, byte[] payload) throws MqttException {
      MqttTopic topic = client.getTopic(topicName);
       MqttMessage message = new MqttMessage(payload);
      message.setQos(qos);
      MqttDeliveryToken token = topic.publish(message);
      token.waitForCompletion();
    }

    public void connectionLost(Throwable cause) {
        if (!expectConnectionFailure)
View Full Code Here

        message.setQos(qos);
        message.setRetained(retain);

        // publish message asynchronously
        MqttTopic mqttTopic = client.getTopic(topic);
        MqttDeliveryToken deliveryToken = mqttTopic.publish(message);

        logger.debug("Publishing message {} to topic '{}'",
            deliveryToken.getMessageId(), topic);
        if (!async) {
          // wait for publish confirmation
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.