Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to browse the message based on MsgId or CorrelId from queue in pymqi

$
0
0
import pymqiqueue_manager = 'QM1'channel = 'DEV.APP.SVRCONN'host = '127.0.0.1'port = '1414'queue_name = 'TEST.1'message = 'Hello from Python 2!'conn_info = '%s(%s)' % (host, port)

First I did the PUT operation like the below code and I worked fine. I put for more 2000 messages

qmgr = pymqi.connect(queue_manager, channel, conn_info)queue = pymqi.Queue(qmgr, queue_name)queue.put(message)queue.close()qmgr.disconnect()

I tried the below code to get the first message It also worked fine. It gives me the first message. I don't know is the correct approach to get the first message.

queue = pymqi.Queue(qmgr, queue_name, pymqi.CMQC.MQOO_BROWSE)    gmo = pymqi.GMO()gmo.Options = pymqi.CMQC.MQGMO_WAIT | pymqi.CMQC.MQGMO_BROWSE_NEXT | pymqi.CMQC.MQGMO_NO_PROPERTIESgmo.WaitInterval = 5000md = pymqi.MD()md.Format = pymqi.CMQC.MQFMT_STRINGmessage = queue.get(None, md, gmo)print(message)   # b'Hello from Python 2!'print(md.MsgId.hex())  #'414d51204e41544d333030202020202817d9ff650a742f22'queue.close()qmgr.disconnect()

but when I tried below code it gives me correct message but I this is not the best solution because if I have 2000 messages then it will iterate until the msgId matches.

queue = pymqi.Queue(qmgr, queue_name, pymqi.CMQC.MQOO_BROWSE)gmo = pymqi.GMO()gmo.Options = pymqi.CMQC.MQGMO_WAIT | pymqi.CMQC.MQGMO_BROWSE_NEXT | pymqi.CMQC.MQGMO_NO_PROPERTIESgmo.WaitInterval = 5000user_MsgId = '414d51204e41544d333030202020202817d9ff650a742f22'overall_message = []keep_running = Truewhile keep_running:    md = pymqi.MD()    md.Format = pymqi.CMQC.MQFMT_STRING    message = queue.get(None, md, gmo)    print(md.MsgId.hex())    if md.MsgId.hex() != user_MsgId:        continue:    else:        overall_message.append(message)        breakqueue.close()qmgr.disconnect()

The above solution gives me correct message but when messages are more performance goes down.Can anyone please suggest better approach to browse the message by MsgId or CorrelId?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>