Skip Navigation Links | |
Exit Print View | |
Oracle GlassFish Server Message Queue 4.5 Developer's Guide for Java Clients |
3. Message Queue Clients: Design and Features
Balancing Reliability and Performance
Thread Allocation for Connections
Advantages and Limitations of Compression
Managing the Dead Message Queue
Managing Physical Destination Limits
Programming Issues for Message Consumers
Using the Client Runtime Ping Feature
Preventing Message Loss for Synchronous Consumers
Synchronous Consumption in Distributed Applications
Delivery Mode (Persistent/Nonpersistent)
Durable vs. Nondurable Subscriptions
Use of Selectors (Message Filtering)
Client Connection Failover (Auto-Reconnect)
Parallel Broker Auto-Reconnect
Clustered-Broker Auto-Reconnect
Handling Exceptions When Failover Occurs
Handling Exceptions in a Transacted Session
Transacted Session: Failover Producer Example
Transacted Session: Failover Consumer Example
Handling Exceptions in a Non-Transacted Session
Schema Validation of XML Payload Messages
Logging Name Spaces, Levels, and Activities
Using the JRE Logging Configuration File
Using a Logging Configuration File for a Specific Application
Setting the Logging Configuration Programmatically
4. Using the Metrics Monitoring API
6. Embedding a Message Queue Broker in a Java Client
Consumer event notifications allow a Message Queue client to listen for the existence of consumers on a destination. Thus, for example, a producer client can start or stop producing messages to a given destination based on the existence of consumers on the destination.
The following sections describe the events that can trigger notification and explain how you can create an event listener.
The following table lists and describes the events that can be returned by the event listener.
Table 3-6 Cnsumer Notification Events
|
The following code example illustrates how you set and remove a consumer event listener. Whenever a consumer event occurs, the event listener's onEvent method will be invoked by the client runtime.
//create an MQ connection factory. com.sun.messaging.ConnectionFactory factory = new com.sun.messaging.ConnectionFactory(); //create an MQ connection. com.sun.messaging.jms.Connection connection = (com.sun.messaging.jms.Connection)factory.createConnection(); //create an MQ session com.sun.messaging.jms.Session session = (com.sun.messaging.jms.Session)connection.createSession(false, Session.AUTO_ACKNOWLEDGE); //create a queue com.sun.messaging.Queue queue = (com.sun.messaging.Queue)session.createQueue(strQueueName); //construct an MQ event listener. The listener implements //com.sun.messaging.jms.notification.EventListener interface. com.sun.messaging.jms.notification.EventListener consEvtListener = new MyConsumerEventListener(); //set consumer event listener. connection.setConsumerEventListener ( (com.sun.messaging.Destination)queue, consEvtListener ); //perform activities //remove consumer event listener. connection.removeConsumerEventListener ( (com.sun.messaging.Destination)queue );
In this example, an application chooses to have its event listener set a boolean flag to give ongoing consumer availability information.
public class MyEventListener implements com.sun.messaging.jms.notification.EventListener { boolean consumerReady = false; MyEventListener(){ consumerReady = false; } public void onEvent(com.sun.messaging.jms.notification.Event evt) { if (evt.getEventCode().equals( com.sun.messaging.jms.notification.ConsumerEvent.CONSUMER_NOT_READY )) { synchronized(this){ consumerReady=false; } } else if (evt.getEventCode().equals( com.sun.messaging.jms.notification.ConsumerEvent.CONSUMER_READY )) { synchronized(this){ consumerReady=true; } } } }