Skip to Content
Java EE 8 Development with Eclipse
book

Java EE 8 Development with Eclipse

by Ram Kulkarni
June 2018
Intermediate to advanced
596 pages
12h 39m
English
Packt Publishing
Content preview from Java EE 8 Development with Eclipse

Steps to send and receive messages using JMS

However, before we start using JMS APIs, let's take a look at the generic steps involved in using them. The following steps show how to send a message to a queue and receive it. Although the steps focus on queues, the steps for topics are similar, but with appropriate topic-related classes:

  1. Look up ConnectionFactory using JNDI:
InitialContext ctx = new InitialContext(); 
QueueConnectionFactory connectionFactory = (QueueConnectionFactory)initCtx.lookup("jndi_name_of_connection_factory"); 
  1. Create a JMS connection and start it:
QueueConnection con = connectionFactory.createQueueConnection(); 
con.start(); 
  1. Create a JMS session:
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ...
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

Java EE 8 Application Development

Java EE 8 Application Development

David R. Heffelfinger
Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Jonathan Wetherbee, Massimo Nardone, Chirag Rathod, Raghu Kodali

Publisher Resources

ISBN: 9781788833776Supplemental Content