Message listeners

Note:
This section does not apply to the C codebase.

WebSphere MQ Everyplace allows an application to listen for events occurring on queues. The application is able to specify message filters to identify the messages in which it is interested, as shown in the following Java example:

/* Create a filter for "Order" messages of priority 7	*/
MQeFields filter = new MQeFields();
filter.putAscii( "MsgType", "Order" );
filter.putByte( MQe.Msg_Priority, (byte)7 );
/* activate a listener on "MyQueue"				*/
qmgr.addMessageListener( this, "MyQueue", filter );
 

Listeners do not start automatically when you create a queue manager. A call to MQeAdministrator is required. However, listeners are persistent in the registry. This means that, once created, listeners that exist at queue manager start-up are started automatically.

The following parameters are passed to the addMessageListener() method:

When a message arrives on a queue with a listener attached, the queue manager calls the callback object that it was given when the message listener was created.

The following is an example of the way in which an application would normally handle message events in Java:

public void messageArrived(MQeMessageEvent msgEvent)			
	{
		String queueName =msgEvent.getQueueName();			
		if (queueName.equals("MyQueue"))
		{
	       	try									
	       	{									
			/*get message from queue */
			MQeMsgObject msg =qmgr.getMessage(null,queueName,
						msgEvent.getMsgFields(),null,0);	
			
			processMessage(msg );
	       	}									
	       	catch (MQeException  e)					
	      	{									
	     		...
	      	}									
		}
	}
 

messageArrived() is a method implemented in MQeMessageListenerInterface. The msgEvent parameter contains information about the message, including:

Message filters only work on local queues. A separate technique known as polling allows messages to be obtained as soon as they arrive on remote queues.



© IBM Corporation 2002. All Rights Reserved