IBM Support

How to browse messages published for a topic

White Papers


Abstract

You are familiar with the concept of browsing a message from a queue in a nondestructive manner.
You want to perform a similar action on the messages that are published for a topic in MQ V7, but you do not want to create a subscriber for that topic.

Content

If you want to be able to browse the messages that are published for a topic, one way is for you to create a durable or non-durable subscriber that uses the destination class (destclas) of "provided" and a destination queue. In that way you can get a copy of these messages in a queue and browse them from the queue by using amqsbcg or the MQ Explorer.

How to invoke amqsbcg

First, let's talk about an important parameter that needs to be passed to amqsbcg, the sample utility that browses all the messages in a queue, in a non-destructive manner.

In most of the scenarios mentioned later on, the utility "amqsbcg" can be used on the appropriate queue to browse messages published for a topic.

But if you use the normal way to invoke this utility, you will not see the topic name in the output:
amqsbcg QueueName QMgrName

The name of the topic is stored in the message as a message property and this property is NOT shown when doing a normal amqsbcg. In order to show the message property, it is necessary to invoke amqsbcg with an extra parameter: number 1 at the end, which instructs amqsbcg to display the message properties.
amqsbcg QueueName QMgrName 1

The following is a sample output, notice the special section called "Message properties":

 MQGET of message number 3
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0...

  GroupId : X'000000000000000000000000000000000000000000000000'
  MsgSeqNumber   : '1'
  Offset         : '0'
  MsgFlags       : '0'
  OriginalLength : '-1'

****Message properties****

  MQTopicString : 'topic1'

****   Message      ****

 length - 5 bytes

00000000:  7465 7374 32                            'test2           '


There are several scenarios that are explored in detail in this document

1.a) A message is published for a topic and there are no subscribers to it. The default is to use the non-retained mode.

Action: It is not possible to browse it.

1.b) Similar to case 1.a, but this time, the message is published with the "retain" mode. There can be only one retained message for a topic and thus, it overwrites the previous retained message for the topic.

Action: The retained message is stored in the following system queue:
SYSTEM.RETAINED.PUB.QUEUE
You can use the sample code "amqsbcg" or the function "Browse Messages ..." from the MQ Explorer V7 GUI.

Notes:
a) The storage of retained messages is the same, regardless of the presence of subscribers or the type of subscribers (durable, non-durable).
b) Do NOT attempt to delete messages from the SYSTEM.* queues.


2) A message is published for a topic and there is a subscriber that was created using the default mode of "non-durable" and the destination class of "managed".
This is the type of subscriber that is used with the sample code "amqssub" or the function "Test Subscription..." from the GUI.

Action: The published message is stored briefly in a temporary dynamic queue that has the name format of:
SYSTEM.MANAGED.NDURABLE.<identifier>
However, the message is immediately delivered to the subscriber.
Thus, it is not possible to browse these messages from the temporary dynamic queue.


3) A message is published for a topic and there is a subscriber that was created using the "durable" mode and the destination class of "managed".
This subscriber could be defined via the GUI or the runmqsc command:
define sub(subscriberName) topicstr(sports/swim) destclas(managed)

Action: The published message is stored in a permanent dynamic queue that has the name format of:
SYSTEM.MANAGED.DURABLE.<identifier>
You can use the sample code "amqsbcg" or the function "Browse Messages ..." from the MQ Explorer V7 GUI.

Question: How to find out the actual queue? That is, how to obtain the "identifier"?
Use runmqsc or the MQ Explorer and show the Destination Name of the temporary queue.
For example, a subscriber was created using the above "define sub" command and the output of the display is shown below.
display sub('subtopic1') all
2 : display sub('subtopic1') all
AMQ8096: WebSphere MQ subscription inquired.
   SUBID(414D5120514D5F414E47454C49544F20EE812B4D2000518C)
   SUB(subtopic1)                          TOPICSTR(topic1)
   TOPICOBJ(topic1)
   DEST(SYSTEM.MANAGED.DURABLE.4D2B81EE8B510020)
   SELECTOR( )                             SELTYPE(NONE)
   USERDATA( )
   PUBACCT(16010515000000BA1E06D2603C3514885EDBC2EF03000000000000000000000B)
   DESTCORL(414D5120514D5F414E47454C49544F20EE812B4D2000518C)
   DESTCLAS(MANAGED)                       DURABLE(YES)
...
Notice the value of the field "DEST" (which is the Destination Name).
DEST(SYSTEM.MANAGED.DURABLE.4D2B81EE8B510020)
.
Thus, you can browse the messages on that queue. The 3rd parameter is the number 1, to display the message properties.

C:\> amqsbcg SYSTEM.MANAGED.DURABLE.4D2B81EE8B510020 QM_ANGELITO 1

AMQSBCG0 - starts here
**********************
 MQOPEN - 'SYSTEM.MANAGED.DURABLE.4D2B81EE8B510020'
 MQCRTMH

 MQGET of message number 1
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0
  Encoding : 273  CodedCharSetId : 1208
  Format : 'MQSTR   '
  Priority : 0  Persistence : 0
  MsgId : X'414D5120514D5F414E47454C49544F20EE812B4D2000518D'
  CorrelId : X'414D5120514D5F414E47454C49544F20EE812B4D2000518C'
  BackoutCount : 0
  ReplyToQ       : '                                                '
  ReplyToQMgr    : 'QM_ANGELITO                                     '
  ** Identity Context
  UserIdentifier : 'rivera      '
  AccountingToken :
   X'16010515000000BA1E06D2603C3514885EDBC2EF03000000000000000000000B'
  ApplIdentityData : '                                '
  ** Origin Context
  PutApplType    : '26'
  PutApplName    : 'QM_ANGELITO                 '
  PutDate  : '20110110'    PutTime  : '22043626'
  ApplOriginData : '    '

  GroupId : X'000000000000000000000000000000000000000000000000'
  MsgSeqNumber   : '1'
  Offset         : '0'
  MsgFlags       : '0'
  OriginalLength : '-1'

****Message properties****

  MQTopicString : 'topic1'
  MQIsRetained : TRUE

****   Message      ****

 length - 5 bytes

00000000:  7465 7374 32                            'test2           '

 No more messages
 MQDLTMH
 MQCLOSE
 MQDISC


4) A message is published for a topic and there is a subscriber that was created using the "durable" mode and the default destination class of "provided".
This subscriber could be defined via the GUI or the runmqsc command:
define sub(subscriberName) topicstr(sports/swim) destclas(provided) dest(QueueName)

Action: The published message is stored in the local queue specified by the destination name attribute, "dest", of the subscriber.
You can use the sample code "amqsbcg" or the function "Browse Messages ..." from the MQ Explorer V7 GUI.

For example, a subscriber was defined with a local queue that you have defined before "Q1": destclas(provided) dest(Q1)

You could use the following command to display the messages stored in that queue:

C:\> amqsbcg Q1 QM_ANGELITO 1

(See the output as in test case 3)


Additional information on durable and non-durable subscriptions

For more details see the MQ V7 product documentation:

Writing subscriber applications

WebSphere MQ 7.0.1 > WebSphere MQ > Publish⁄Subscribe User's Guide >
Writing publish/subscribe applications > Writing subscriber applications >
Example 2: Managed MQ subscriber

WebSphere MQ 7.0.1 > WebSphere MQ > Publish⁄Subscribe User's Guide >
Writing publish/subscribe applications > Writing subscriber applications >
Example 3: Unmanaged MQ subscriber

Original Publication Date

17 January 2011

[{"Product":{"code":"SSFKSJ","label":"WebSphere MQ"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"PubSub","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.0;7.5;7.1;7.0","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Product Synonym

WebSphere MQ WMQ

Document Information

More support for:
WebSphere MQ

Software version:
8.0, 7.5, 7.1, 7.0

Operating system(s):
AIX, HP-UX, Linux, Solaris, Windows

Document number:
599695

Modified date:
17 June 2018

UID

swg27020670