JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle GlassFish Server Message Queue 4.5 Developer's Guide for Java Clients
search filter icon
search icon

Document Information

Preface

1.  Overview

2.  Using the Java API

3.  Message Queue Clients: Design and Features

Client Design Considerations

Developing Portable Clients

Choosing Messaging Domains

Connections and Sessions

Producers and Consumers

Assigning Client Identifiers

Message Order and Priority

Using Selectors Efficiently

Balancing Reliability and Performance

Managing Client Threads

JMS Threading Restrictions

Thread Allocation for Connections

Managing Memory and Resources

Managing Memory

Managing Message Size

Message Compression

Advantages and Limitations of Compression

Compression Examples

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

Factors Affecting Performance

Delivery Mode (Persistent/Nonpersistent)

Use of Transactions

Acknowledgment Mode

Durable vs. Nondurable Subscriptions

Use of Selectors (Message Filtering)

Message Size

Message Body Type

Connection Event Notification

Connection Events

Creating an Event Listener

Event Listener Examples

Consumer Event Notification

Consumer Events

Creating a Consumer Event Listener

Consumer Event Listener Examples

Client Connection Failover (Auto-Reconnect)

Enabling Auto-Reconnect

Single-Broker Auto-Reconnect

Parallel Broker Auto-Reconnect

Clustered-Broker Auto-Reconnect

Auto-Reconnect Behaviors

Auto-Reconnect Limitations

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

Failover Producer Example

Failover Consumer Example

Custom Client Acknowledgment

Using Client Acknowledge Mode

Using No Acknowledge Mode

Schema Validation of XML Payload Messages

Communicating with C Clients

Client Runtime Logging

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

5.  Working with SOAP Messages

6.  Embedding a Message Queue Broker in a Java Client

A.  Warning Messages and Client Error Codes

Index

Consumer Event Notification

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.

Consumer Events

The following table lists and describes the events that can be returned by the event listener.

Table 3-6 Cnsumer Notification Events

Event Type
Meaning
ConsumerEvent
This event is generated when consumer existence changes on a destination. The event has two possible event codes: CONSUMER_READY and CONSUMER_NOT_READY.

Creating a Consumer Event Listener

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

Consumer Event Listener Examples

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;
      }
    }
  }
}