Package org.eclipse.paho.client.mqttv3

Examples of org.eclipse.paho.client.mqttv3.MqttMessage


      sslProperties.put("com.ibm.ssl.trustStore", trustStore);
    }
    mqttConnectOptions.setSSLProperties(sslProperties);

    try {
      mqttClient = new MqttClient(serverURI, clientId, new MemoryPersistence());
      mqttClient.connect(mqttConnectOptions);
      logger.info("MQTT client connected");
    } catch (MqttException e) {
      logger.warn("Failed to initialize MQTT event client", e); //$NON-NLS-1$
    }
View Full Code Here


        ActiveMQConnection activeMQConnection = (ActiveMQConnection) new ActiveMQConnectionFactory(openwireTransport.getConnectUri()).createConnection();
        activeMQConnection.start();
        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();
        client.close();
    }
View Full Code Here

            Thread.sleep(10);
            new Thread(null, null, "client:"+i) {
                @Override
                public void run() {
                    try {
                        MqttClient client = new MqttClient("tcp://localhost:" + mqttConnector.getConnectUri().getPort(), Thread.currentThread().getName(), new MemoryPersistence());
                        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();
                        asyncError.set(e);
                    } finally {
                        disconnectDoneLatch.countDown();
View Full Code Here

   * @param data String to be transmitted to the Mqtt Broker.
   */
  public void sendData(String data) {
    Assert.hasText(data, "data must not be empty nor null");
    DefaultMqttPahoClientFactory factory;
    MqttClient client = null;
    factory = new DefaultMqttPahoClientFactory();
    factory.setPassword("guest");
    factory.setUserName("foobar");
    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();
        throw new IllegalStateException(e);
      }
      client.disconnect();
      client.close();
    }
    catch (MqttException mqttException) {
      throw new IllegalStateException(mqttException.getMessage());
    }
  }
View Full Code Here

    super("MQTT");
  }

  @Override
  protected void obtainResource() throws Exception {
    resource = new MqttClient("tcp://localhost:1883", "xd-test-" + System.currentTimeMillis(), new MemoryPersistence());
    resource.connect();
  }
View Full Code Here

    @Override
    public void setUp() throws MqttException {
        clientId = getClass().getSimpleName() + ((int) (10000*Math.random()));
        clientId2 = clientId + "-2";
        client = new MqttClient(brokerUrl, clientId, null);
        client2 = new MqttClient(brokerUrl, clientId2, null);
        conOpt = new MyConnOpts();
        setConOpts(conOpt);
        receivedMessages = new ArrayList();
        expectConnectionFailure = false;
    }
View Full Code Here

    @Override
    public  void tearDown() throws MqttException {
        // clean any sticky sessions
        setConOpts(conOpt);
        client = new MqttClient(brokerUrl, clientId, null);
        try {
            client.connect(conOpt);
            client.disconnect();
        } catch (Exception _) {}

        client2 = new MqttClient(brokerUrl, clientId2, null);
        try {
            client2.connect(conOpt);
            client2.disconnect();
        } catch (Exception _) {}
    }
View Full Code Here

        client.disconnect();
    }

    public void testMultipleClientIds() throws MqttException, InterruptedException {
        client.connect(conOpt);
        client2 = new MqttClient(brokerUrl, clientId, null);
        client2.connect(conOpt);
        Thread.sleep(testDelay);
        Assert.assertFalse(client.isConnected());
        client2.disconnect();
    }
View Full Code Here

      MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(
          tmpDir);
      logger.debug(
          "Creating new client for '{}' using id '{}' and file store '{}'",
          url, clientId, tmpDir);
      client = new MqttClient(url, clientId, dataStore);
      client.setCallback(this);
    }

    MqttConnectOptions options = new MqttConnectOptions();
View Full Code Here

      logger.warn("Failure while disconecting the mqtt client", e); //$NON-NLS-1$
    }
  }

  private void initClient() {
    mqttConnectOptions = new MqttConnectOptions();
    String serverURI = PreferenceHelper.getString(ServerConstants.CONFIG_EVENT_HOST, null);
    String clientId = PreferenceHelper.getString(ServerConstants.CONFIG_EVENT_CLIENT_ID, MqttClient.generateClientId());
    if (serverURI == null) {
      //no MQTT message broker host defined
      if (logger.isWarnEnabled()) {
View Full Code Here

TOP

Related Classes of org.eclipse.paho.client.mqttv3.MqttMessage

Copyright © 2018 www.massapicom. 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.