3. Life Cycle of an Ultra Messaging JMS Application

Using the Ultra Messaging JMS API, you can write end-to-end messaging applications with the programming model shown in Ultra Messaging JMS Programming Architecture. This section discusses the following topics.

3.1. Producer Application

Producer applications take the following actions.

  1. Look-up ConnectionFactory. The Ultra Messaging JMS implementation supports JNDI lookup of a ConnectionFactory.

  2. Create a physical connection. The ConnectionFactory creates the Connection.

  3. Create logical session(s) of a Connection. Sessions are light-weight connections that can multiplex over a single physical Connection. Sessions provide the following.

    1. Concurrent use of the physical Connection across multiple threads (one session per thread) and thus are resource efficient.

    2. Delineation of work between multiple producers.

    3. A factory of producers.

  4. Create a Destination. You can create the destination programmatically or via JNDI lookup. The destination consists of a Topic or Queue name.

  5. Create a producer of a session and provide the destination.

  6. Create Messages. For each Message, set the business data and set the associated routing properties.

  7. Send Messages to the Destination address using the producer.

  8. Close Objects by destroying the Message, Destination(s), producer, session(s), and Connection.

The following simple JMS producer example application demonstrates how to program the above actions.

// Obtain a ConnectionFactory via lookup or direct instantiation
ConnectionFactory factory = (ConnectionFactory)jndiContext.lookup("uJMSConnectionFactory");
 
// Create a connection - assuming no username/password required for UM
Connection connection = factory.createConnection();

// Create a session
Session session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

// Create a topic destination
Destination destination = session.createTopic("TOPIC.1");

// Create a producer
MessageProducer msgProducer = session.createProducer(null);

// create a bytes message
BytesMessage msg = session.createBytesMessage();

byte[] buffer = {1,2,3,4,5};

msg.writeBytes(buffer);

// Publish the message
msgProducer.send(destination, msg);

// close the connection
connection.close();
           

3.2. Consumer Application

Consumer applications normally take the following actions.

  1. Look up ConnectionFactory. The Ultra Messaging JMS implementation supports JNDI lookup of a ConnectionFactory.

  2. Create a physical connection. The ConnectionFactory creates the Connection.

  3. Create logical session(s) of a Connection. Sessions are light-weight connections that can multiplex over a single physical Connection. Sessions provide the following.

    1. Concurrent use of the physical Connection across multiple threads (one session per thread) and thus are resource efficient

    2. Delineation of work between multiple consumers.

    3. A factory of consumers.

  4. Create a Destination. You can create the destination, which consists of a Topic/Queue name, programmatically or via JNDI/UMM lookup. The UMM repository contains a Wildcard designation for a Destination.

  5. Create a consumer of a session, providing the Destination created. If the messages are read asynchronously, register the listener call-back function and exception with the consumer.

  6. Read Messages from the Destination Address. For each destination address (absolute or wildcard), the read could be synchronous, the consumer could register a listener call-back function to asynchronously receive messages, or the consumer could also register a listener call-back exception function to asynchronously receive exceptions, business or technical.

  7. Process messages to access data and properties.

  8. Close Objects by destroying Message; Destination(s), consumer, session(s), Connection.

The following simple JMS consumer example application demonstrates how to program the above actions.

// Obtain a ConnectionFactory via lookup or direct instantiation
 ConnectionFactory factory = (ConnectionFactory)jndiContext.lookup("uJMSConnectionFactory");

// Create a connection - assuming no username/password required for UM
Connection connection = factory.createConnection();

// Create a session
Session session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

// Create a topic destination
Destination destination = session.createTopic("TOPIC.1");

// create the consumer 
MessageConsumer msgConsumer = session.createConsumer(destination);

// start the connection 
connection.start();

// read messages 
while(true)
{
    // receive the message 
        msg = msgConsumer.receive();
    if (msg == null)
        break;
}

// close the connection 
connection.close();
           

Copyright (c) 2004 - 2014 Informatica Corporation. All rights reserved.