Understanding Spring JMS using the JMS API

In the Java world, one of the most popular APIs for asynchronous communication is JMS (short for Java Messaging Service).

The JMS API defines the API for Java applications to communicate in a loosely coupled asynchronous approach by sending and receiving messages over message brokers. ActiveMQ is one of the most popular JMS-compliant message brokers.

Spring JMS simplifies JMS communication in Spring applications.

The following example shows a simple class sending a JMS message using Spring JMS:

public class SendJMSMessage {
@Autowired
private JmsTemplate jmsTemplate;

@Autowired
private Queue queue;
public void simpleSend() {
this.jmsTemplate.send(queue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("Send Message");
}
});
}
}

JmsTemplate is a helper class that provides methods that can send and receive messages over message brokers. Queue is the representation for the message broker.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset