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.
Producer applications take the following actions.
Look-up ConnectionFactory. The Ultra Messaging JMS implementation supports JNDI lookup of a ConnectionFactory.
Create a physical connection. The ConnectionFactory creates the Connection.
Create logical session(s) of a Connection. Sessions are light-weight connections that can multiplex over a single physical Connection. Sessions provide the following.
Concurrent use of the physical Connection across multiple threads (one session per thread) and thus are resource efficient.
Delineation of work between multiple producers.
A factory of producers.
Create a Destination. You can create the destination programmatically or via JNDI lookup. The destination consists of a Topic or Queue name.
Create a producer of a session and provide the destination.
Create Messages. For each Message, set the business data and set the associated routing properties.
Send Messages to the Destination address using the producer.
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();
Consumer applications normally take the following actions.
Look up ConnectionFactory. The Ultra Messaging JMS implementation supports JNDI lookup of a ConnectionFactory.
Create a physical connection. The ConnectionFactory creates the Connection.
Create logical session(s) of a Connection. Sessions are light-weight connections that can multiplex over a single physical Connection. Sessions provide the following.
Concurrent use of the physical Connection across multiple threads (one session per thread) and thus are resource efficient
Delineation of work between multiple consumers.
A factory of consumers.
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.
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.
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.
Process messages to access data and properties.
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.