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

JmsTemplate Overview

The JmsTemplate is the primary object used for sending messages and receiving messages synchronously (i.e., blocking while waiting to receive messages). There is a JMS template version for JMS 1.1 (JmsTemplate) and a version for JMS 1.0.2 (JmsTemplate102). Since most JMS providers and Java EE application servers now support JMS 1.1, we will be focusing our attention on the JMS 1.1 Spring objects. Using the JmsTemplate significantly reduces the development effort involved in sending and receiving messages. When using the JmsTemplate, you do not need to worry about connecting to the JMS provider, creating a JMS session (e.g., QueueSession), creating a message producer (e.g., QueueSender), or even creating a JMS message (e.g., TextMessage). The JmsTemplate can automatically convert String objects, Byte[] objects, Java objects, and java.util.Map objects into the corresponding JMS message object types. You can also provide your own message converter to provide custom converters for complex messages or other types of messages not supported by the default message converter. The following code example illustrates the simplicity of sending a simple text message using Spring:

public class SimpleJMSSender {

   public static void main(String[] args) {
     try {
       ApplicationContext ctx = 
           new ClassPathXmlApplicationContext("app-context.xml");
       JmsTemplate jmsTemplate = 
           (JmsTemplate)ctx.getBean("jmsTemplate");

       jmsTemplate.convertAndSend("This is easy!");
     }
     ...
   }
}

In this example, the ...

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