Publish a message to a specific MQTT v3 client

Publish a message from one MQTT v3 client to another, using ClientIdentifier as the topic name and IBM® MQ as the publish/subscribe broker.

Before you begin

Do the task, Publishing a message to the MQTT client utility from IBM MQ Explorer. Leave the MQTT client utility connected.

About this task

The task demonstrates two things:
  1. Subscribing to a topic in one MQTT client, and receiving a publication from another MQTT client.
  2. Setting up "point-to-point" subscriptions by using ClientIdentifier as the topic string.
An additional task, Using the MQTT daemon for devices as the publish/subscribe broker, uses the MQTT daemon for devices as the publish/subscribe broker, rather than IBM MQ.
Note: The daemon for devices is no longer available. For an alternative solution, see the eclipse.org Mosquitto project (https://eclipse.org/mosquitto).

Procedure

  1. Discard any existing subscriptions by disconnecting and reconnecting the MQTT client utility.

    The subscription is discarded because, unless you change the defaults, the MQTT client utility connects with a clean session; see Clean sessions.

    To make it easier to do the task, type your own ClientIdentifier, rather than use the generated ClientIdentifier created by the MQTT client utility.

    1. Click Disconnect to disconnect the MQTT client utility from the telemetry channel.

      The Client History records a Disconnected event

    2. Change the Client Identifer to MyClient.
    3. Click Connect.

    The Client History records a Connected event

  2. Create a subscription to the topic, MyClient

    MyClient is the ClientIdentifier of this client.

    1. Type MyClient into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribed event.

  3. Start another MQTT client utility.
    1. Open the Queue Managers\QmgrName\Telemetry\channels folder.
    2. Right-click the PlainText channel> Run MQTT Client Utility...
    3. Click Connect.

    The Client History records a Connected event

  4. Publish Hello MyClient! to the topic MyClient.
    1. Copy the subscription topic, MyClient, from the MQTT client utility running with the ClientIdentifier, MyClient.
    2. Paste MyClient into the Publication\Topic field of each of the MQTT client utility instances.
    3. Type Hello MyClient! into the Publication\message field.
    4. Click Publish in both instances.

Results

The Client history in the MQTT client utility with the ClientIdentifier, MyClient, records two Received events and one Published event. The other MQTT client utility instance records one Published event.

If you see only one Received event check the following possible causes:
  1. Is the default transmission queue for the queue manager set to SYSTEM.MQTT.TRANSMIT.QUEUE ?
  2. Have you created queue manager aliases or remote queue definitions referencing MyClient in doing the other exercises? In case you have a configuration problem, delete any resources that reference MyClient, such as a queue manager aliases or transmission queues. Disconnect the client utilities, stop, and restart the telemetry (MQXR) service.

What to do next

Do the next task, Using the MQTT daemon for devices as the publish/subscribe broker. The MQTT client utility connects to the MQTT daemon for devices rather than to a telemetry channel.

Using the MQTT daemon for devices as the publish/subscribe broker

Use the MQTT daemon for devices as the publish/subscribe broker instead of IBM MQ. Publish a message with one instance of the MQTT client utility to send to another instance, by subscribing using its ClientIdentifier as a topic string.

Before you begin

Note: The daemon for devices is no longer available. For an alternative solution, see the eclipse.org Mosquitto project (https://eclipse.org/mosquitto).

Install the MQTT daemon for devices, if you have not done so already.

Do not run the verification; it uses port 1883, which is already in use by the PlainText telemetry channel.

About this task

In the task, you connect MQTT clients to the MQTT daemon for devices using a non-default TCP/IP port. One client subscribes using its ClientIdentifier as a topic string, and the other client publishes to ClientIdentifier, exactly in the same way as in the previous task, see Procedure.

Note: The task is documented for running the daemon on Windows. To run the daemon on Linux®, modify the path and the permissions for the configuration file.

Procedure

  1. Open a command window in the directory containing the MQTT daemon for devices.
  2. Run the daemon on a different TCP/IP port.
    1. Create a file called <configfile name>.cfg in the same directory as the daemon.
    2. Add a line to the file to configure a different default port for the daemon.
      
      port 1884
      
    3. Save the file.
  3. Start the daemon.
    
    amqtdd
    

    The daemon writes its console log to the command window:

    20100712 123133.857 CWNAN9999I MQTT daemon for devices
    20100712 123133.857 CWNAN9997I Licensed Materials - Property of IBM
    20100712 123133.857 CWNAN9996I Copyright IBM Corp. 2007, 2024. All Rights Reserved
    20100712 123133.857 CWNAN9995I US Government Users Restricted Rights ...
    20100712 123133.857 CWNAN0049I Configuration file name is .\<configfile name>.cfg
    20100712 123133.873 CWNAN0054I Features included: bridge
    20100712 123134.060 CWNAN0014I MQTT protocol starting, listening on port 1884
    
  4. Start an instance of the MQTT client utility.

    Start the MQTT client utility only from a telemetry channel, and then you can connect to the daemon. Alternatively you can install the <configfile name> SupportPac, IA92. The SupportPac is available from IA92: WBI Brokers - Java implementation of IBM MQ Telemetry transport.

    1. Open the Queue Managers\QmgrName\Telemetry\channels folder.
    2. Right-click the PlainText channel> Run MQTT Client Utility...
    3. Change the Port to 1884.
    4. Change the Client Identifer to MyClient.
    5. Click Connect.

    The Client History records a Connected event

  5. Create a subscription to the topic, MyClient

    MyClient is the ClientIdentifier of this client.

    1. Type MyClient into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribed event.

  6. Start another MQTT client utility.
    1. Open the Queue Managers\QmgrName\Telemetry\channels folder.
    2. Right-click the PlainText channel> Run MQTT Client Utility...
    3. Change the Port to 1884.
    4. Click Connect.

    The Client History records a Connected event

  7. Publish Hello MyClient! to the topic MyClient.
    1. Copy the subscription topic, MyClient, from the MQTT client utility running with the ClientIdentifier, MyClient.
    2. Paste MyClient into the Publication\Topic field of each of the MQTT client utility instances.
    3. Type Hello MyClient! into the Publication\message field.
    4. Click Publish in both instances.

Results

The Client history in the MQTT client utility with the ClientIdentifier, MyClient, records two Received events and one Published event. The other MQTT client utility instance records one Published event.

You can also monitor the connection and disconnection events to the MQTT daemon for devices in the command window.