Publishing a message to the MQTT client utility from IBM MQ Explorer

Follow the steps in this task to publish a message using IBM MQ Explorer, and subscribe to it with the MQTT client utility. An additional task shows you how to configure a queue manager alias rather than setting the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE.


Before starting

The task assumes that we are familiar with IBM MQ and the IBM MQ Explorer, and that IBM MQ and MQ Telemetry feature are installed.

The user creating the queue manager resources for this task must have sufficient authority to do so. For demonstration purposes, the IBM MQ Explorer user ID is assumed to be member of the mqm group.


About this task

In the task, you create a topic in IBM MQ and subscribe to the topic using the MQTT client utility. When you publish to the topic using IBM MQ Explorer, the MQTT client receives the publication.


Procedure

Do one of the following tasks:


What to do next

Do Send a message to an MQTT client using IBM MQ Explorer to send a message directly to the client utility. Parent topic: Send a message to an MQTT client


Start task with no telemetry (MQXR) service yet defined

Create a queue manager and run the Define sample configuration to define sample telemetry resources for the queue manager. Publish a message using IBM MQ Explorer, and subscribe to it with the MQTT client utility.


About this task

When you set up sample telemetry resources using the Define sample configuration, the wizard sets the guest user ID permissions. Carefully consider if you want the guest user ID to be authorized in this way. guest on Windows, and nobody on Linux, are given permission to publish and subscribe to the root of the topic tree, and to put messages onto SYSTEM.MQTT.TRANSMIT.QUEUE.

The wizard also sets the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE, which might interfere with applications running on an existing queue manager. It is possible, but laborious, to configure telemetry and not use the default transmission queue; do the follow on task: Use a queue manager alias. In this task, you create a queue manager to avoid the possibility of interfering with any existing default transmission queue.


Procedure

  1. Using IBM MQ Explorer, create and start a new queue manager.
    1. Right-click Queue Managers folder> New > Queue manager .... Type a queue manager name > Finish.

      Make up a queue manager name; for example, MQTTQMGR.

  2. Create and start the telemetry (MQXR) service and create a sample telemetry channel.
    1. Open the Queue Managers\QmgrName\Telemetry folder.
    2. Click Define sample configuration... > Finish

      Leave the Launch MQTT Client Utility check box checked.

  3. Create a subscription for MQTT Example using the MQTT client utility.
    1. Click Connect.

      The Client history records a Connected event.

    2. Type MQTT Example into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribed event.

  4. Create MQTTExampleTopic in IBM MQ.
    1. Right-click the Queue Managers\QmgrName\Topics folder in the MQ Explorer> New > Topic.
    2. Type MQTTExampleTopic as the Name > Next.
    3. Type MQTT Example as the Topic string > Finish.
    4. Click OK to close the acknowledgment window.

  5. Publish Hello World! to the topic MQTT Example using IBM MQ Explorer.
    1. Click the Queue Managers\QmgrName\Topics folder in the IBM MQ Explorer.
    2. Right-click MQTTExampleTopic > Test publication...
    3. Type Hello World! into the Message data field > Publish message > Switch to the MQTT Client Utility window.

    The Client history records a Received event.


Start task with a running telemetry (MQXR) service

Create a telemetry channel and a topic. Authorize the user to use the topic and the telemetry transmit queue. Publish a message using IBM MQ Explorer, and subscribe to it with the MQTT client utility.


Before starting

In this version of the task, a queue manager, QmgrName, is defined and running. A telemetry (MQXR) service is defined and running. The telemetry (MQXR) service might have been created manually, or by running the Define sample configuration wizard.


About this task

In this task you configure an existing queue manager to send a publication to the MQTT client utility.

Step 1 of the task sets the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE, which might interfere with applications running on an existing queue manager. It is possible, but laborious, to configure telemetry and not use the default transmission queue; do the follow on task: Use a queue manager alias.


Procedure

  1. Set SYSTEM.MQTT.TRANSMIT.QUEUE as the default transmit queue.
    1. Right-click the Queue Managers\QmgrName folder > Properties...
    2. Click Communication in the navigator.
    3. Click Select... > Select SYSTEM.MQTT.TRANSMIT.QUEUE > OK > OK.

  2. Create a telemetry channel MQTTExampleChannel to connect the MQTT client utility to IBM MQ, and start the MQTT client utility.
    1. Right-click the Queue Managers\QmgrName \Telemetry\Channels folder in the MQ Explorer> New > Telemetry channel....
    2. Type MQTTExampleChannel in the Channel name field> Next > Next.
    3. Change the Fixed user ID on the client authorization panel to the user ID that is going to publish and subscribe to MQTTExample > Next.
    4. Leave Launch Client Utility checked> Finish.

  3. Create a subscription for MQTT Example using the MQTT client utility.
    1. Click Connect.

      The Client history records a Connected event.

    2. Type MQTT Example into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribed event.

  4. Create MQTTExampleTopic in IBM MQ.
    1. Right-click the Queue Managers\QmgrName\Topics folder in the MQ Explorer> New > Topic.
    2. Type MQTTExampleTopic as the Name > Next.
    3. Type MQTT Example as the Topic string > Finish.
    4. Click OK to close the acknowledgment window.

  5. If we want a user, not in the mqm group, to publish and subscribe to the MQTTExample topic, do the following:
    1. Authorize the user to publish and subscribe to the topic MQTTExampleTopic:
      setmqaut -m qMgrName -t topic -n MQTTExampleTopic -p User ID -all +pub +sub
      
    2. Authorize the user to put a message onto the SYSTEM.MQTT.TRANSMIT.QUEUE:
      setmqaut -m qMgrName -t q -n SYSTEM.MQTT.TRANSMIT.QUEUE -p User ID -all +put
      

  6. Publish Hello World! to the topic MQTT Example using IBM MQ Explorer.
    1. Click the Queue Managers\QmgrName\Topics folder in the IBM MQ Explorer.
    2. Right-click MQTTExampleTopic > Test publication...
    3. Type Hello World! into the Message data field > Publish message > Switch to the MQTT Client Utility window.

    The Client history records a Received event.


Use a queue manager alias

Publish a message to the MQTT client utility using IBM MQ Explorer without setting the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE.

The task is a continuation of the previous task, and uses a queue manager alias to avoid setting the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE.


Before starting

Complete either the task, Start task with no telemetry (MQXR) service yet defined or the task, Start task with a running telemetry (MQXR) service.


About this task

When an MQTT client creates a subscription, IBM MQ sends its response using ClientIdentifier, as the remote queue manager name. In this task, it uses the ClientIdentifier, MyClient.

If there is no transmission queue or queue manager alias called MyClient, the response is placed on the default transmission queue. By setting default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE, the MQTT client gets the response.

We can avoid setting the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE by using queue manager aliases. We must set up a queue manager alias for every ClientIdentifier. Typically, there are too many clients to make it practical to use queue manager aliases. Often ClientIdentifier is unpredictable, making it impossible to configure telemetry this way.

Nonetheless, in some circumstances you might have to configure the default transmission queue to something other than SYSTEM.MQTT.TRANSMIT.QUEUE. The steps in Procedure configure a queue manager alias instead of setting the default transmission queue to SYSTEM.MQTT.TRANSMIT.QUEUE.


Procedure

  1. Remove SYSTEM.MQTT.TRANSMIT.QUEUE as the default transmit queue.
    1. Right-click the Queue Managers\QmgrName folder > Properties...
    2. Click Communication in the navigator.
    3. Remove SYSTEM.MQTT.TRANSMIT.QUEUE from the Default transmission queue field > OK.

  2. Check that we can no longer create a subscription with the MQTT client utility:
    1. Click Connect.

      The Client history records a Connected event.

    2. Type MQTT Example into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribe failed and a Connection lost event.

  3. Create a queue manager alias for the ClientIdentifier, MyClient.
    1. Right-click the Queue Managers\QmgrName\Queues folder> New > Remote queue definition.
    2. Name the definition, MyClient > Next.
    3. Type MyClient in the Remote queue manager field.
    4. Type SYSTEM.MQTT.TRANSMIT.QUEUE in the Transmission queue field > Finish.

  4. Connect the MQTT client utility again.
    1. Check the Client identifier is set to MyClient.
    2. Connect

    The Client history records a Connected event.

  5. Create a subscription for MQTT Example using the MQTT client utility.
    1. Click Connect.

      The Client history records a Connected event.

    2. Type MQTT Example into the Subscription\Topic field> Subscribe.

    The Client history records a Subscribed event.

  6. Publish Hello World! to the topic MQTT Example using IBM MQ Explorer.
    1. Click the Queue Managers\QmgrName\Topics folder in the IBM MQ Explorer.
    2. Right-click MQTTExampleTopic > Test publication...
    3. Type Hello World! into the Message data field > Publish message > Switch to the MQTT Client Utility window.

    The Client history records a Received event.