Message listeners

Note: This section does not apply to the C code base.
MQe 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 );
The following parameters are passed to the addMessageListener() method:
  • The name of the queue on which to listen for message operations
  • A callback object that implements MQeMessageListenerInterface
  • An MQeFields object containing a message filter

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:
  • The name of the queue on which the message arrived
  • The UID of the message
  • The messageID
  • The correlationID
  • Message priority
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.

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.