How to Put a message into one queue and generate duplicate message into Multiple queues .

We are using point-to-point and you want to create “duplicate” messages that will be stored in queues Q1 and Q2, when the message is put into the queue “DESTINATION”.This is possible with Alias TOPIC and TOPIC Objects

    	Alias TOPIC
             |
           TOPIC
       	     |		   
             ^
   SUBSCRIBER1 SUBSCRIBER2
         |          |
        Q1          Q2

amqsput sample to put a message to the DESTINATION queue, which in turn publishes the message into the topic T1 and the subscribers SUB1 and SUB2 receive the messages, which are stored in queues Q1 and Q2 respectively.

You could also publish directly into topic T1.A copy of the message will be placed on Q1 and Q2.

DEFINITIONS
------------------------------
  DEFINE QL(Q1)
  DEFINE QL(Q2)

  DEFINE TOPIC(T1) TOPICSTR('TOPIC1')
  DEFINE QALIAS(DESTINATION) TARGET(T1) TARGTYPE(TOPIC)

  DEFINE sub(SUB1) TOPICSTR('TOPIC1') DEST(Q1)
  DEFINE QL(Q1)
     1 : DEFINE QL(Q1)
AMQ8006I: IBM MQ queue created.
  DEFINE QL(Q2)
     2 :   DEFINE QL(Q2)
AMQ8006I: IBM MQ queue created.
DEFINE TOPIC(T1) TOPICSTR('TOPIC1')
     3 : DEFINE TOPIC(T1) TOPICSTR('TOPIC1')
AMQ8690I: IBM MQ topic created.
DEFINE QALIAS(DESTINATION) TARGET(T1) TARGTYPE(TOPIC)
     4 : DEFINE QALIAS(DESTINATION) TARGET(T1) TARGTYPE(TOPIC)
AMQ8006I: IBM MQ queue created.
DEFINE SUB(SUB1) TOPICSTR('TOPIC1') DEST(Q1)
     6 : DEFINE SUB(SUB1) TOPICSTR('TOPIC1') DEST(Q1)
AMQ8094I: IBM MQ subscription created.
DEFINE sub(SUB2) TOPICSTR('TOPIC1') DEST(Q2)
     7 : DEFINE sub(SUB2) TOPICSTR('TOPIC1') DEST(Q2)
AMQ8094I: IBM MQ subscription created.

Will try to put 10 messages with amqsput.have used shell script with amqsput here with below code snippet.

[mqm@ip-172-31-14-154 tmp]$ cat put.sh 
 #!/bin/bash
 for i in `seq 10` ; do
  echo "Sending $i message"
  echo "Test MSG $i" |/opt/mqm/samp/bin/amqsput DESTINATION APPQM1 >/dev/null 2>&1
 done 
[mqm@ip-172-31-14-154 tmp]$
[mqm@ip-172-31-14-154 tmp]$ sh put.sh 
Sending 1 message
Sending 2 message
Sending 3 message
Sending 4 message
Sending 5 message
Sending 6 message
Sending 7 message
Sending 8 message
Sending 9 message
Sending 10 message
[mqm@ip-172-31-14-154 tmp]$ 
mqm@ip-172-31-14-154 tmp]$ /opt/mqm/samp/bin/amqsget Q1 APPQM1
Sample AMQSGET0 start
message <Test MSG 1>
message <Test MSG 2>
message <Test MSG 3>
message <Test MSG 4>
message <Test MSG 5>
message <Test MSG 6>
message <Test MSG 7>
message <Test MSG 8>
message <Test MSG 9>
message <Test MSG 10>
no more messages
Sample AMQSGET0 end
[mqm@ip-172-31-14-154 tmp]$ 
[mqm@ip-172-31-14-154 tmp]$ /opt/mqm/samp/bin/amqsget Q2 APPQM1
Sample AMQSGET0 start
message <Test MSG 1>
message <Test MSG 2>
message <Test MSG 3>
message <Test MSG 4>
message <Test MSG 5>
message <Test MSG 6>
message <Test MSG 7>
message <Test MSG 8>
message <Test MSG 9>
message <Test MSG 10>
no more messages
Sample AMQSGET0 end
[mqm@ip-172-31-14-154 tmp]$ 

NOTE: Strictly speaking, the messages received by Q1 and Q2 are NOT truly identical. Even though they will have the same payload (text string ‘TEST’) and same characteristics, each message will have its own unique message-id in the Older MQ version’s .

Let us browse 1 message from each queue Q1 & Q2 see . In our case message-id is same . refer below .

[mqm@ip-172-31-14-154 tmp]$ /opt/mqm/samp/bin/amqsbcg Q1 APPQM1

AMQSBCG0 - starts here
**********************
 
 MQOPEN - 'Q1'
 
 
 MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0
  Encoding : 546  CodedCharSetId : 1208
  Format : 'MQSTR   '
  Priority : 0  Persistence : 0
  MsgId : X'414D5120415050514D312020202020208F57F95F01A60522'
  CorrelId : X'414D5120415050514D312020202020208F57F95F038E0522'
  BackoutCount : 0
  ReplyToQ       : '                                                '
  ReplyToQMgr    : 'APPQM1                                          '
  ** Identity Context
  UserIdentifier : 'mqm         '
  AccountingToken : 
   X'0339393200000000000000000000000000000000000000000000000000000006'
  ApplIdentityData : '                                '
  ** Origin Context
  PutApplType    : '26'
  PutApplName    : 'APPQM1                      '
  PutDate  : '20210109'    PutTime  : '07373811'
  ApplOriginData : '    '

  GroupId : X'000000000000000000000000000000000000000000000000'
  MsgSeqNumber   : '1'
  Offset         : '0'
  MsgFlags       : '0'
  OriginalLength : '-1'
 
****   Message      ****
 
 length - 7 of 7 bytes
 
00000000:  4142 4344 4546 47                                 'ABCDEFG         '
 
 
 
 No more messages 
 MQCLOSE
 MQDISC
[mqm@ip-172-31-14-154 tmp]$
[mqm@ip-172-31-14-154 tmp]$ /opt/mqm/samp/bin/amqsbcg Q2 APPQM1

AMQSBCG0 - starts here
**********************
 
 MQOPEN - 'Q2'
 
 
 MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0
  Encoding : 546  CodedCharSetId : 1208
  Format : 'MQSTR   '
  Priority : 0  Persistence : 0
  MsgId : X'414D5120415050514D312020202020208F57F95F00A60522'
  CorrelId : X'414D5120415050514D312020202020208F57F95F088E0522'
  BackoutCount : 0
  ReplyToQ       : '                                                '
  ReplyToQMgr    : 'APPQM1                                          '
  ** Identity Context
  UserIdentifier : 'mqm         '
  AccountingToken : 
   X'0339393200000000000000000000000000000000000000000000000000000006'
  ApplIdentityData : '                                '
  ** Origin Context
  PutApplType    : '26'
  PutApplName    : 'APPQM1                      '
  PutDate  : '20210109'    PutTime  : '07373811'
  ApplOriginData : '    '

  GroupId : X'000000000000000000000000000000000000000000000000'
  MsgSeqNumber   : '1'
  Offset         : '0'
  MsgFlags       : '0'
  OriginalLength : '-1'
 
****   Message      ****
 
 length - 7 of 7 bytes
 
00000000:  4142 4344 4546 47                                 'ABCDEFG         '
 
 
 
 No more messages 
 MQCLOSE
 MQDISC
[mqm@ip-172-31-14-154 tmp]$ 

That’s it now we have successfully able to send message to DESTINATION queue which in turn send to multiple queues .

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *