If a C application registers a message listener function and context data with a message consumer, or if a C++ application registers a message listener with a message consumer, the application can receive messages asynchronously.
When a message arrives for a message consumer, XMS delivers the message to a C application by calling the message listener function, passing a pointer to the context data as one parameter and the handle for the message as the other parameter. XMS delivers the message to a C++ application by calling the onMessage() method of the message listener, passing a pointer to the message as a parameter.
XMS uses one thread to handle all asynchronous message delivery for a session. This means that only one message listener function or one onMessage() method can run at a time. If more than one message consumer in a session is receiving messages asynchronously, and a message listener function or onMessage() method is currently delivering a message to one message consumer, then any other message consumers that are waiting for the same message must continue to wait. Other messages that are waiting to be delivered to the session must also continue to wait.
If an application requires concurrent delivery of messages, it must create more than one session, so that XMS uses more than one thread to handle asynchronous message delivery. In this way, more than one message listener function or onMessage() method can run concurrently.
WebSphere MQ V7.0 and above also supports asynchronous message consumption. An application can register a callback function for a destination. When a suitable message is sent to the destination, WebSphere MQ calls the function and passes the message as a parameter. The function then processes the message asynchronously. In previous releases of WebSphere MQ, this feature was available only when using WebSphere MQ classes for JMS and Message Service Client for C/C++.
Message Service Client for C/C++ has been changed to use this new feature in WebSphere MQ V7.1. The implementation of XMS message listeners is now a more natural fit with WebSphere MQ. Message Service Client for C/C++ no longer has to find a destination to check whether a suitable message has been sent to the destination. The performance of XMS message listeners is improved as a result, particularly when an application uses multiple message listeners in a session to monitor multiple destinations. Message throughput is increased, and the time taken to deliver a message to a message listener after it has arrived at a destination is reduced.
For more information about using message listener functions in a C application, see Message listener functions in C. If you are using C++, see Message listeners in C++.