Spring provides a JMS integration framework that simplifies the use of the JMS API, the JmsTemplate class is the core class which is available in spring JMS package. This class simplifies sending and receiving messages via simple spring configuration. In this example we will see how to send and receive a message to message broker using spring JmsTemplate and Apache activemq.
PrerequisiteStart ActiveMQ message broker.
1. Create a Maven project and add below dependencies
2. Create Spring configuration file (applicationContext.xml)
Configure Activmq and jms template beans here
3. Create a Main class to send and receive messages (MessageReceiver.java)
4. Run it
Run the MessageSender.java and we will see below output in the console and Active MQ broker