Skip to Main Content
Java Message Service, 2nd Edition
book

Java Message Service, 2nd Edition

by Mark Richards, Richard Monson-Haefel, David A Chappell
May 2009
Intermediate to advanced content levelIntermediate to advanced
330 pages
10h 34m
English
O'Reilly Media, Inc.
Content preview from Java Message Service, 2nd Edition

JMS Resources in Java EE

The two JMS resources that must be obtained from the JNDI context are the JMS destination (Queue and Topic) and the JMS connection factory (TopicConnectionFactory and QueueConnectionFactory). In previous examples in this book, these resources were obtained by first getting an InitialContext to the JMS provider and then performing a lookup using the published JNDI name. Keeping with our borrower and lender example from the previous chapters, let’s assume that we have a topic connection factory defined in the Java EE application server named “TopicCF,” and a topic used to publish prices also defined in the Java EE application server named “jms/Rates.” In previous examples, the constructor of the Lender class was where we established an InitialContext and obtained the TopicConnectionFactory and Topic via a JNDI lookup:

public class Lender {

   TopicConnection conn = null;
   TopicSession session = null;
   Topic ratesTopic = null;
   TopicPublisher publisher = null;
     
   public Lender() {
     try {

        Context ctx = new InitialContext();

        TopicConnectionFactory factory = (TopicConnectionFactory)
           ctx.lookup("TopicCF");
        conn = factory.createTopicConnection();
        conn.start();

        session = 
           conn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);

        ratesTopic = (Topic)ctx.lookup("jms/Rates");
        publisher = session.createPublisher(ratesTopic);

        ...
            
     } catch (JMSException jmse) {
        jmse.printStackTrace(); 
     } catch (NamingException jne) {
        jne.printStackTrace();
     }      
   }
   ...
}         

Within the Java EE environment, objects ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reactive Systems in Java

Reactive Systems in Java

Clement Escoffier, Ken Finnigan
Java 8 in Action

Java 8 in Action

Mario Fusco, Alan Mycroft, Raoul-Gabriel Urma
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9780596802264Supplemental ContentErrata Page