#include <hmq.h> MQEINT32 MQeQMgrDeleteMsgs( MQEHSESS hSess, MQECHAR * pQMName, MQECHAR * pQName, MQEHFIELDS pMsgs[], MQEINT32 nMsgs, MQEINT32 * pCompCode, MQEINT32 * pReason)
If an entry in the pMsgs[] is a NULL, this NULL entry is skipped and the delete operation continues on to the next entry in the array. The delete operation stops when it encounters an exception, and any remaining message object handles not processed are left as-is and remain on the queue.
MQeFieldsFree() is used to release MQeFields handles stored in this array.
#include <hmq.h> MQEHSESS hSess; MQCHAR * qm, *q; MQEHFIELDS hFilter = MQEHANDLE_NULL; MQEINT32 i, n, nMsgs; MQEINT32 compcode; MQEINT32 reason; MQEBMO bmo = MQEBMO_DEFAULT; MQEHFIELDS pMsgs[2]; qm = "aQM"; q = "QQ"; hSess = MQeInitialize("MyAppsName", &compcode, &reason); /* Max. number of messages to get at a time for this run */ nMsgs = 2; bmo.cookie.hi = bmo.cookie.lo = 0; bmo.lockId.hi = bmo.lockId.lo = 0; bmo.option |= MQE_QMGR_OPTION_BROWSE_LOCK; /* Browse nMsgs at a time until no messages are left */ while (1) { /* do forever */ /* Browse the nMsgs matching messages */ n = MQeQMgrBrowseMsgs( hSess, qm, q, &bmo, hFilter, pMsgs, nMsgs, &cookie, &compcode, &reason); if (n==0) { /* Any resources held by the cookie /* has been released already */ break; } for(i=0; i<n; i++) { /* Process the message objects in pMsgs[] */ } /* Delete the n locked messages in pMsgs[] */ MQeQMgrDeleteMsgs( hSess, qm, q, pMsgs, n, &compcode, &reason); /* free pMsgs[] handle resources */ for(i=0; i<n; i++) { MQeFieldsFree(hSess, pMsgs[i], &compcode, &reason); } }; MQeTerminate(hSess, &compcode, &reason);