java - how to browse all messages from 2 different MQQueue in the same function? -


my purpose list down correlation ids of messages in set of mq queues in java application.

this code snippet

public void populatecorrelationids() throws mqexception{     int openoptions = mqconstants.mqoo_input_as_q_def | mqconstants.mqoo_output | mqconstants.mqoo_inquire | mqconstants.mqoo_browse;     string qnames[0] = bay10.cischgx.dfda;     string qnames[1] = baysf11.msfchgx.dfda;     mqmessage messageget = new mqmessage();     for(string q : qnames){         mqqueue dfdaq  = qmgr.accessqueue(q, openoptions);         mqgetmessageoptions gmo = new mqgetmessageoptions();         gmo.options = mqconstants.mqgmo_browse_first| mqconstants.mqgmo_wait;         gmo.waitinterval = 4000;         int j = dfdaq.getcurrentdepth();         for(int i=0;i<j;i++)         {             dfdaq.get(messageget,gmo);  //error generated here when getting message qnames[1]             byte[] correlid= messageget.correlationid;         }     } } 

below error getting --

mqje001: completion code '2', reason '2033'. com.ibm.mq.mqexception:  mqje001: completion code '2', reason '2033'. @     com.ibm.mq.mqdestination.getint(mqdestination.java:655) @  com.ibm.mq.mqdestination.get(mqdestination.java:459) @  utility.populatecorrelationids(utility.java:152) @  utility.main(utility.java:64) mqje001: completion code '2', reason '2033'. 

this error when run code. please note error occurs when message queue next queue. able browse messages first queue. browse first message in second queue above error. can in resolving error.

there multiple points note here:

the first 1 because initializing mqmessage object outside first for loop. has inside second for loop because mq fills object messageid, correlationid, message body among others when mqqueue.get call returns. if make get call again same mqmessage object instance, attempting message messageid of retrieved message. call fail 2033 reason code.

there few other points code.

1) have new mqgetmessageoptions() inside second for loop.

2) using browse_first option. browse fist message only. browse message, have get browse_next option. when open queue, browse cursor positioned logically before first message on queue. means if make get call after accessqueue call, can use mqgmo_browse_next option browse first message; not have use mqgmo_browse_first option

3) if queue opened browse only, there no need specifying mqconstants.mqoo_output | mqconstants.mqoo_inquire open options.

4) getcurrentdepth() method returns queue depth when call made. possible while application browsing, other application might messages same queue. in case, current queue depth change application not notified of change. instead of using dfdaq.getcurrentdepth(), can mqgmo_browse_next option in while loop. call return 2033 reason code when there no messages browse. can check reason code , exit out while loop.


Comments

Popular posts from this blog

python - Overwriting the save method of a Django model -

java - From File[] files to directory -