MQeQMgrDeleteMsgs

Description
Deletes the messages on a queue identified by the unique identifier of each message. The unique identifier is a combination of an 8 bytes integer unique ID and the origin queue manager name of the messages. The application is responsible for calling the MQeFieldsFree() to free the message object handles in the input array.

Syntax
#include <hmq.h> 
MQEINT32 MQeQMgrDeleteMsgs( MQEHSESS hSess, MQECHAR * pQMName, 
                            MQECHAR * pQName,  MQEHFIELDS pMsgs[], 
                            MQEINT32 nMsgs, MQEINT32 * pCompCode, 
                            MQEINT32 * pReason) 

Parameters

MQEHSESS hSess - input
This session handle, returned by MQeInitialize.

MQECHAR * pQMName - input
A null terminated string containing the name of the queue manager.

MQECHAR * pQName - input
A null terminated string containing the name of the queue.

MQEINT32 pMsgs[] - input
An array of message object handles to be deleted. To delete messages that are returned by a browse-and-lock function call, the messages object handles should be the input in this array. The queue manager extracts the unique identifier (UID) of each message object handle and sends it to the queue manager. The unique identifier of a message object is a 64 bit unique value and the string name of the origin queue manager. The rest of the fields in the message object are ignored.

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.

MQEINT32 nMsgs - input
The number of array elements in the pMsgs[] array, including elements that are NULL.

MQEINT32 * pCompCode - output
MQECC_OK, MQECC_WARNING or MQECC_ERROR.

MQEINT32 * pReason - output
If the returned *pCompCode equals MQECC_ERROR, *pReason may have any of the following values:

MQE_EXCEPT_INVALID_HANDLE

MQE_EXCEPT_INVALID_ARGUMENT

MQE_EXCEPT_QMGR_INVALID_QMGR_NAME

MQE_EXCEPT_QMGR_INVALID_Q_NAME

MQE_EXCEPT_QMGR_UNKNOWN_QMGR

MQE_EXCEPT_QMGR_Q_DOES_NOT_EXIST

MQE_EXCEPT_Q_NO_MSG_AVAILABLE

MQE_EXCEPT_Q_NO_MATCHING_MSG
Could not find the message on the queue, and therefore, no message is deleted.

MQE_EXCEPT_NETWORK_ERROR_OPEN|READ|WRITE

Return Value

MQEINT32
The number of the array entries successfully processed, including the NULL entries.

Example
#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);

See Also


© IBM Corporation 2002. All Rights Reserved