How to browse/get Nth message from a queue in QMGR ?

How to browse/get Nth message from a queue in QMGR ?
How to use MQ dmpmqsg/qload to delete old messages from a queue ?
Is there a way to delete a single message from an MQ queue?

Create a ABC local queue and send some sample messages .

bash-4.2$ runmqsc QM1
5724-H72 (C) Copyright IBM Corp. 1994, 2022.
Starting MQSC for queue manager QM1.


define ql(ABC)
     1 : define ql(ABC)
AMQ8006I: IBM MQ queue created.

       :
dis ql(ABC)
     2 : dis ql(ABC)
AMQ8409I: Display Queue details.
   QUEUE(ABC)                              TYPE(QLOCAL)
   ACCTQ(QMGR)                             ALTDATE(2022-05-21)
   ALTTIME(06.08.11)                       BOQNAME( )
   BOTHRESH(0)                             CLUSNL( )
   CLUSTER( )                              CLCHNAME( )
   CLWLPRTY(0)                             CLWLRANK(0)
   CLWLUSEQ(QMGR)                          CRDATE(2022-05-21)
   CRTIME(06.08.11)                        CURDEPTH(0)
   CUSTOM( )                               DEFBIND(OPEN)
   DEFPRTY(0)                              DEFPSIST(NO)
   DEFPRESP(SYNC)                          DEFREADA(NO)
   DEFSOPT(SHARED)                         DEFTYPE(PREDEFINED)
   DESCR( )                                DISTL(NO)
   GET(ENABLED)                            HARDENBO
   IMGRCOVQ(QMGR)                          INITQ( )
   IPPROCS(0)                              MAXDEPTH(5000)
   MAXMSGL(4194304)                        MAXFSIZE(DEFAULT)
   MONQ(QMGR)                              MSGDLVSQ(PRIORITY)
   NOTRIGGER                               NPMCLASS(NORMAL)
   OPPROCS(0)                              PROCESS( )
   PUT(ENABLED)                            PROPCTL(COMPAT)
   QDEPTHHI(80)                            QDEPTHLO(20)
   QDPHIEV(DISABLED)                       QDPLOEV(DISABLED)
   QDPMAXEV(ENABLED)                       QSVCIEV(NONE)
   QSVCINT(999999999)                      RETINTVL(999999999)
   SCOPE(QMGR)                             SHARE
   STATQ(QMGR)                             TRIGDATA( )
   TRIGDPTH(1)                             TRIGMPRI(0)
   TRIGTYPE(FIRST)                         USAGE(NORMAL)

       :
end
     3 : end
2 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.
-bash-4.2$

Put some 5 message in to the queue using amqspu sample program

-bash-4.2$ /opt/mqm/samp/bin/amqsput ABC QM1
Sample AMQSPUT0 start
target queue is ABC
1
2
3
4
5

Sample AMQSPUT0 end
-bash-4.2$

By default if we use any sameple program given in the IBM MQ the read is FIFO (First in first out ).
If we use amqsget it will read all the messages . I want to get 3rd message take out from the queue or Let say i want to browse only 3rd message from the queue .

First get the message id from the queue using dmpmqmsg command .

/opt/mqm/bin/dmpmqmsg -m QM1 -i ABC -f /tmp/message.txt

The dmpmqmsg command with the -i (input queue) option can be used to copy messages in a queue to a file. In this example, the messages in the queue named QUEUE01 on the queue manager named QM1 are copied to /tmp/message.txt. This will not remove the messages off the queue. The amqsget command can be used to GET the messages off the queue or the clear qlocal command can be used to purge the messages from the queue.

-bash-4.2$ -bash-4.2$ /opt/mqm/bin/dmpmqmsg -m QM1 -i ABC -f /tmp/message.txt
Read    - Files:   0  Messages:5  Bytes:5
Written - Files:   1  Messages:5  Bytes:5
-bash-4.2$
-bash-4.2$
-bash-4.2$ cat /tmp/message.txt
* DMPMQMSG Version:9.2.0.5 Created:Sat May 21 06:22:38 2022
* Qmgr  = QM1
* Queue = ABC

A VER 2
A RPT 0
A MST 8
A EXP -1
A FDB 0
A ENC 546
A CCS 1208
A FMT MQSTR
A PRI 0
A PER 0
A MSI 414D5120514D31202020202020202020FCB9886204DF8723
A COI 000000000000000000000000000000000000000000000000
A BOC 0
A RTQ
A RTM QM1
A USR mqm
A ACC 0339393700000000000000000000000000000000000000000000000000000006
A AIX 2020202020202020202020202020202020202020202020202020202020202020
A PAT 6
A PAN amqsput
A PTD 20220521
A PTT 10083806
A AOX 20202020
A GRP 000000000000000000000000000000000000000000000000
A MSQ 1
A OFF 0
A MSF 0
A ORL -1
X 31

A VER 2
A RPT 0
A MST 8
A EXP -1
A FDB 0
A ENC 546
A CCS 1208
A FMT MQSTR
A PRI 0
A PER 0
A MSI 414D5120514D31202020202020202020FCB9886205DF8723
A COI 000000000000000000000000000000000000000000000000
A BOC 0
A RTQ
A RTM QM1
A USR mqm
A ACC 0339393700000000000000000000000000000000000000000000000000000006
A AIX 2020202020202020202020202020202020202020202020202020202020202020
A PAT 6
A PAN amqsput
A PTD 20220521
A PTT 10083840
A AOX 20202020
A GRP 000000000000000000000000000000000000000000000000
A MSQ 1
A OFF 0
A MSF 0
A ORL -1
X 32

A VER 2
A RPT 0
A MST 8
A EXP -1
A FDB 0
A ENC 546
A CCS 1208
A FMT MQSTR
A PRI 0
A PER 0
A MSI 414D5120514D31202020202020202020FCB9886206DF8723
A COI 000000000000000000000000000000000000000000000000
A BOC 0
A RTQ
A RTM QM1
A USR mqm
A ACC 0339393700000000000000000000000000000000000000000000000000000006
A AIX 2020202020202020202020202020202020202020202020202020202020202020
A PAT 6
A PAN amqsput
A PTD 20220521
A PTT 10083872
A AOX 20202020
A GRP 000000000000000000000000000000000000000000000000
A MSQ 1
A OFF 0
A MSF 0
A ORL -1
X 33

A VER 2
A RPT 0
A MST 8
A EXP -1
A FDB 0
A ENC 546
A CCS 1208
A FMT MQSTR
A PRI 0
A PER 0
A MSI 414D5120514D31202020202020202020FCB9886207DF8723
A COI 000000000000000000000000000000000000000000000000
A BOC 0
A RTQ
A RTM QM1
A USR mqm
A ACC 0339393700000000000000000000000000000000000000000000000000000006
A AIX 2020202020202020202020202020202020202020202020202020202020202020
A PAT 6
A PAN amqsput
A PTD 20220521
A PTT 10083916
A AOX 20202020
A GRP 000000000000000000000000000000000000000000000000
A MSQ 1
A OFF 0
A MSF 0
A ORL -1
X 34

A VER 2
A RPT 0
A MST 8
A EXP -1
A FDB 0
A ENC 546
A CCS 1208
A FMT MQSTR
A PRI 0
A PER 0
A MSI 414D5120514D31202020202020202020FCB9886208DF8723
A COI 000000000000000000000000000000000000000000000000
A BOC 0
A RTQ
A RTM QM1
A USR mqm
A ACC 0339393700000000000000000000000000000000000000000000000000000006
A AIX 2020202020202020202020202020202020202020202020202020202020202020
A PAT 6
A PAN amqsput
A PTD 20220521
A PTT 10084025
A AOX 20202020
A GRP 000000000000000000000000000000000000000000000000
A MSQ 1
A OFF 0
A MSF 0
A ORL -1
X 35

-bash-4.2$
-bash: -bash-4.2$: 

grep the messages id’s from /tmp/message.txt


-bash-4.2$ grep MSI /tmp/message.txt
A MSI 414D5120514D31202020202020202020FCB9886204DF8723
A MSI 414D5120514D31202020202020202020FCB9886205DF8723
A MSI 414D5120514D31202020202020202020FCB9886206DF8723
A MSI 414D5120514D31202020202020202020FCB9886207DF8723
A MSI 414D5120514D31202020202020202020FCB9886208DF8723
-bash-4.2$ 

Select the message parameter MSI from the above output 414D5120514D31202020202020202020FCB9886206DF8723 .

A MSI 414D5120514D31202020202020202020FCB9886206DF8723

5 Messages are still available in the queue .

dis qs(ABC)
     1 : dis qs(ABC)
AMQ8450I: Display queue status details.
   QUEUE(ABC)                              TYPE(QUEUE)
   CURDEPTH(5)                             CURFSIZE(1)
   CURMAXFS(2088960)                       IPPROCS(0)
   LGETDATE( )                             LGETTIME( )
   LPUTDATE(2022-05-21)                    LPUTTIME(06.08.40)
   MEDIALOG( )                             MONQ(HIGH)
   MSGAGE(1063)                            OPPROCS(0)
   QTIME( , )                              UNCOM(NO)
    [-i <Input Queue> (Browse)]
    [-I <Input Queue> (Get)]
-bash-4.2$ ./dmpmqmsg -m QM1 -gxm414D5120514D31202020202020202020FCB9886205DF8723 -i ABC -f /tmp/out.txt

5724-H72 (C) Copyright IBM Corp. 1994, 2022.
IBM MQ Queue Load/Unload Utility
Read    - Files:   0  Messages:1  Bytes:1
Written - Files:   1  Messages:1  Bytes:1
-bash-4.2$

use -gxm and append Message identifier . This will browse message if we use i and if we use I it will read message from the queue permanently.

bash-4.2$ runmqsc QM1
5724-H72 (C) Copyright IBM Corp. 1994, 2022.
Starting MQSC for queue manager QM1.


DISPLAY qs(ABC)
     1 : DISPLAY qs(ABC)
AMQ8450I: Display queue status details.
   QUEUE(ABC)                              TYPE(QUEUE)
   CURDEPTH(5)                             CURFSIZE(1)
   CURMAXFS(2088960)                       IPPROCS(0)
   LGETDATE( )                             LGETTIME( )
   LPUTDATE(2022-05-21)                    LPUTTIME(06.08.40)
   MEDIALOG( )                             MONQ(HIGH)
   MSGAGE(2620)                            OPPROCS(0)
   QTIME( , )                              UNCOM(NO)

       :
end
     2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
-bash-4.2$ 
-bash-4.2$ ./dmpmqmsg -m QM1 -gxm414D5120514D31202020202020202020FCB9886205DF8723 -I ABC

5724-H72 (C) Copyright IBM Corp. 1994, 2022.
IBM MQ Queue Load/Unload Utility
Read    - Files:   0  Messages:1  Bytes:1
-bash-4.2$

one message is read out which is in the 3rd place . Now see the curdepth from the queue

-bash-4.2$ runmqsc QM1
5724-H72 (C) Copyright IBM Corp. 1994, 2022.
Starting MQSC for queue manager QM1.


dis qs(ABC)
     1 : dis qs(ABC)
AMQ8450I: Display queue status details.
   QUEUE(ABC)                              TYPE(QUEUE)
   CURDEPTH(4)                             CURFSIZE(1)
   CURMAXFS(2088960)                       IPPROCS(0)
   LGETDATE(2022-05-21)                    LGETTIME(06.52.41)
   LPUTDATE(2022-05-21)                    LPUTTIME(06.08.40)
   MEDIALOG( )                             MONQ(HIGH)
   MSGAGE(2651)                            OPPROCS(0)
   QTIME(999999999, 999999999)             UNCOM(NO)
end
     2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
-bash-4.2$

Related Posts

Leave a Reply

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