Search

Sunday, October 21, 2012

MQGET read in non-destructive way

MQGET OPTIONS to read Queue in Non Destructive Way

To delete from queue explicitly, developer needs to Read a queue, performing some other action and finally delete queue explicitly.

Steps:
During MQOPEN Call:
  •  Open Queue with MQOO_BROWSE option
  •   Check the message counter

During MQGET Call:
  • For the first message give MQGMO_BROWSE_FIRST as GMO option
  • Do again MQGET after you perform everything you need with MQGMO_MSG_UNDER_CURSOR option. This will delete message from queue. By this we ensure that all the business logic is done before we delete message from queue.
  • For next subequent messages give MQGMO_BROWSE_NEXT and again do step 2 to ensure delete.
Eg:


IF Message-Counter = 0 

       COMPUTE MQGMO-OPTIONS = MQGMO_NO_WAIT +

                               MQGMO_BROWSE_FIRST + MQGMO_CONVERT
       END-COMPUTE
ELSE
       COMPUTE MQGMO-OPTIONS = MQGMO_NO_WAIT +
      MQGMO_BROWSE_NEXT  + MQGMO_CONVERT
       END-COMPUTE     
END-IF  

Call this para after every browse:



COMPUTE MQGMO-OPTIONS = MQGMO-NO-WAIT + MQGMO-MSG-UNDER-CURSOR

END-COMPUTE

No comments:

Post a Comment