简体   繁体   中英

Listener for IBM MQ

I am trying to create a listener for IBM MQ queue , to read message when its put to the queue using native API.

Is it better to use Thread/TimerTask to perform the GET every second.

I need to use the CCDT , username and password for the authentication purpose.

Is there any default listener available? Reading from using below code

MQMessage theMessage    = new MQMessage();
MQGetMessageOptions mqGetMessageOptions = new MQGetMessageOptions();

mqGetMessageOptions.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
mqGetMessageOptions.matchOptions=MQC.MQMO_NONE;
mqGetMessageOptions.waitInterval=5000;
try{
        //read the message from queue          
queue.get(theMessage,mqGetMessageOptions);  
  mqGetMessageOptions.options = MQC.MQGMO_MSG_UNDER_CURSOR;

    queue.get(theMessage, mqGetMessageOptions);

Your code is browse the messages and not consuming them (big difference).

Second, you should always use the MQC.MQGMO_FAIL_IF_QUIESCING option. ie

mqGetMessageOptions.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_FAIL_IF_QUIESCING;

Third, do not use polling to access a queue - your thread/timer idea. It is a waste of resources. You already have a 5 second wait interval defined for the MQGET, if it is not long enough, then increase it to something more reasonable.

Finally, why did you tag this question with 'JMS'. There is nothing in your question related to JMS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM