MqttSample (Java Functional Samples)
Date: 2020-08-07

mqtt

## Class MqttSample

- java.lang.Object
- - mqtt.MqttSample

-     public class MqttSample
      extends java.lang.Object

  Demonstrate integrating with the MQTT messaging system http://mqtt.org.

  `MqttStreams` is a connector used to create a bridge between topology streams and an MQTT broker.

  The sample publishes some messages to a MQTT topic. It also subscribes to the topic and reports the messages received. The messages received may include messages from prior runs of the sample.

  By default, the sample requires a running MQTT broker with the following characteristics:

  - the broker's connection is `tcp://localhost:1883`
  - the broker is configured for no authentication

  Required IBM Streams environment variables:

  - STREAMS_INSTALL - the Streams installation directory
  - STREAMS_DOMAIN_ID - the Streams domain to use for context `DISTRIBUTED`
  - STREAMS_INSTANCE_ID - the Streams instance to use for context `DISTRIBUTED`

  See the MQTT link above for information about setting up a MQTT broker.

  This may be executed from the `samples/java/functional` directory as:

  - `ant run.mqtt.distributed` - Using Apache Ant, this will run in distributed mode.
  - `ant run.mqtt` - Using Apache Ant, this will run in standalone mode.
  - `java -cp functionalsamples.jar:../../../com.ibm.streamsx.topology/lib/com.ibm.streamsx.topology.jar:$STREAMS_INSTALL/lib/com.ibm.streams.operator.samples.jar mqtt.MqttSample CONTEXT_TYPE [serverURI=<value>] [userID=<value>] [password=<value>] [trustStore=<value>] [trustStorePassword=<value>] [keyStore=<value>] [keyStorePassword=<value>]` - Run directly from the command line.
  Specify absolute pathnames if using the `trustStore` or `keyStore` arguments.
  CONTEXT_TYPE is one of:
  - `DISTRIBUTED` - Run as an IBM Streams distributed application.
  - `STANDALONE` - Run as an IBM Streams standalone application.
  - `BUNDLE` - Create an IBM Streams application bundle.
  - `TOOLKIT` - Create an IBM Streams application toolkit.
  - An application execution within your IDE once you set the class path to include the correct jars.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MqttSample()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `main(java.lang.String[] args)`
    `void` | `publishSubscribe(java.lang.String contextType)` Publish some messages to a topic; subscribe to the topic and report received messages.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MqttSample

          public MqttSample()

  - ### Method Detail

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### publishSubscribe

          public void publishSubscribe(java.lang.String contextType)
                                throws java.lang.Exception

      Publish some messages to a topic; subscribe to the topic and report received messages.
      Parameters:
        `contextType` - string value of a `StreamsContext.Type`
      Throws:
        `java.lang.Exception`