spring

Spring JMS Example

Java Messaging Service (JMS) is a standard messaging API used to send and receive messages.

Spring simplifies the use of JMS API by providing another layer around the JMS layer.

This layer provides convenience methods for sending and receiving messages, as well as manages the creation and release of resources like the connection object.

The JmsTemplate class is the main class which we will be using often to work with the JMS API.

1. Dependencies

In order to send and receive JMS messages to and from a JMS message broker, we need to include the message service library. In this example we are using activeMq so our pom.xml will have dependencies related to spring as well as activeMq.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javacodegeeks.camel</groupId>
	<artifactId>springQuartzScheduler</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>4.1.5.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.1.5.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jms</artifactId>
			<version>4.1.5.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-all</artifactId>
			<version>5.12.0</version>
		</dependency>
	</dependencies>
	
</project>

2. Spring JmsTemplate Example

Spring provides JMS integration using JmsTemplate class. It helps eliminating the verbose and repetitive JMS code. JmsTemplate also takes care of creating a connection, obtaining a session, and the actual sending and receiving of messages. This helps the developer to just focus on the construction of message. If any JMS exception is thrown, it will be rethrown as unchecked exception as a subclass of JmsException.

Let’s start with the producer.

In the below class, notice the sendMessage() method. It delegates the call to JmsTemplate.send(). The call depends on the message destination, as well as a MessageCreator object, which creates the JMS message you are going to send. The MessageCreator object is usually implemented as an anonymous inner class. Here we are sending a text message.

SpringJmsProducer:

package com.javacodegeeks.spring.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class SpringJmsProducer {
	private JmsTemplate jmsTemplate;
	private Destination destination;
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
	
	public Destination getDestination() {
		return destination;
	}

	public void setDestination(Destination destination) {
		this.destination = destination;
	}

	public void sendMessage(final String msg) {
		System.out.println("Producer sends " + msg);
		jmsTemplate.send(destination, new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(msg);
			}});		
	}
}

In the consumer, we will receive the JMS message again with the help of the JMS template. In receiveMessage(), the call is delegated to JdbcTemplate.receive() method by providing a message destination. This method returns a JMS message of type javax.jms.Message. Since we know the message is a TextMessage we return the actual payload by calling textMessage.getText().

SpringJmsConsumer:

package com.javacodegeeks.spring.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.springframework.jms.core.JmsTemplate;

public class SpringJmsConsumer {
	private JmsTemplate jmsTemplate;
	private Destination destination;
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
	
	public Destination getDestination() {
		return destination;
	}

	public void setDestination(Destination destination) {
		this.destination = destination;
	}

	public String receiveMessage() throws JMSException {
		TextMessage textMessage = (TextMessage) jmsTemplate.receive(destination);		
		return textMessage.getText();
	}
}

3. Configuring JmsTemplate

In this section, we will configure a connection factory which we will use to create connection. The connection factory will help us connect to the message broker. Since we’re using ActiveMQ as our message broker, we’ll have to configure the JMS connection factory so that it knows how to connect to ActiveMQ. ActiveMQConnectionFactory is the JMS connection factory that comes with ActiveMQ.

The brokerURL property tells the connection factory where the message broker is located. The URL we are using is tcp://localhost:61616.

Next, we need to configure a destination. The destination can be either a queue or a topic, depending on the needs of the application.

Once we have configured, a connection factory and destination, we will configure the JmsTemplate bean. Since both our producer and consumer both are dependent on JmsTemplate, we need to inject the jmsTemplate bean in their definitions.

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL" value="tcp://localhost:61616" />
	</bean>
	<bean id="messageDestination" class="org.apache.activemq.command.ActiveMQQueue">
		<constructor-arg value="messageQueue1" />
	</bean>
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
	</bean>

	<bean id="springJmsProducer" class="com.javacodegeeks.spring.jms.SpringJmsProducer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
	
	<bean id="springJmsConsumer" class="com.javacodegeeks.spring.jms.SpringJmsConsumer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
</beans>

Let’s test the JMS Example.

In order for the producer and consumer to connect to the broker, we must have the broker started.

BrokerService broker = BrokerFactory.createBroker(new URI(
				"broker:(tcp://localhost:61616)"));
broker.start();

Next, we load the spring application context. Once we have the context, we get the producer bean and call springJmsProducer.sendMessage("Hi"). This will send the message to the configured destination. In order to receive the message from the destination, we get the consumer bean and call springJmsConsumer.receiveMessage().

SpringJmsExample:

package com.javacodegeeks.spring.jms;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringJmsExample {
	public static void main(String[] args) throws URISyntaxException, Exception {
		BrokerService broker = BrokerFactory.createBroker(new URI(
				"broker:(tcp://localhost:61616)"));
		broker.start();
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");

		try {
			SpringJmsProducer springJmsProducer = (SpringJmsProducer) context
					.getBean("springJmsProducer");
			springJmsProducer.sendMessage("Hi");

			SpringJmsConsumer springJmsConsumer = (SpringJmsConsumer) context
					.getBean("springJmsConsumer");
			System.out.println("Consumer receives " + springJmsConsumer.receiveMessage());
		} finally {
			broker.stop();
			context.close();
		}
	}
}

Output:

 INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB]
 INFO | KahaDB is version 6
 INFO | Recovering from the journal @1:1580
 INFO | Recovery replayed 1 operations from the journal in 0.01 seconds.
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is starting
 INFO | Listening for connections at: tcp://127.0.0.1:61616
 INFO | Connector tcp://127.0.0.1:61616 started
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB only has 56897 mb of usable space - resetting to maximum available disk space: 56897 mb
Producer sends Hi
Consumer receives Hi
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is shutting down
 INFO | Connector tcp://127.0.0.1:61616 stopped
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] stopped
 INFO | Stopping async queue tasks
 INFO | Stopping async topic tasks
 INFO | Stopped KahaDB
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) uptime 1.433 seconds
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is shutdown

4. Spring JmsGatewaySupport Example

In this example, our producer and consumer beans will extend JmsGatewaySupport to access the JMS template. We will inject the JmsTemplate bean as usual to our producer and consumer beans. With this change, we can get rid of the private field jmsTemplate and its setter method from both the producer and consumer classes.

SpringJmsGatewayProducer:

package com.javacodegeeks.spring.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.support.JmsGatewaySupport;

public class SpringJmsGatewayProducer extends JmsGatewaySupport {
	public void sendMessage(final String msg) {
		System.out.println("Producer sends " + msg);
		getJmsTemplate().send(new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(msg);
			}});		
	}
}

SpringJmsGatewayConsumer:

package com.javacodegeeks.spring.jms;

import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.springframework.jms.core.support.JmsGatewaySupport;

public class SpringJmsGatewayConsumer extends JmsGatewaySupport {
	public String receiveMessage() throws JMSException {
		TextMessage textMessage = (TextMessage) getJmsTemplate().receive();		
		return textMessage.getText();		
	}
}

In jmsTemplateWithDefaultDestination, we have specified a default message destination so now we don’t have inject the destination to our producer and consumer beans.

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL" value="tcp://localhost:61616" />
	</bean>
	<bean id="messageDestination" class="org.apache.activemq.command.ActiveMQQueue">
		<constructor-arg value="messageQueue1" />
	</bean>
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
	</bean>

	<bean id="springJmsProducer" class="com.javacodegeeks.spring.jms.SpringJmsProducer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
	
	<bean id="springJmsConsumer" class="com.javacodegeeks.spring.jms.SpringJmsConsumer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
	
        <bean id="jmsTemplateWithDefaultDestination" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
		<property name="defaultDestinationName" value="messageQueue2" />
	</bean>
	
        <bean id="springJmsGatewayProducer" class="com.javacodegeeks.spring.jms.SpringJmsGatewayProducer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
	
	<bean id="springJmsGatewayConsumer" class="com.javacodegeeks.spring.jms.SpringJmsGatewayConsumer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
</beans>

Let’s retest the example now with enhanced producer and consumer beans.

SpringJmsGatewaySupportExample:

package com.javacodegeeks.spring.jms;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringJmsGatewaySupportExample {
	public static void main(String[] args) throws URISyntaxException, Exception {
		BrokerService broker = BrokerFactory.createBroker(new URI(
				"broker:(tcp://localhost:61616)"));
		broker.start();
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");

		try {
			SpringJmsGatewayProducer springJmsProducer = (SpringJmsGatewayProducer) context
					.getBean("springJmsGatewayProducer");
			springJmsProducer.sendMessage("Hi");

			SpringJmsGatewayConsumer springJmsConsumer = (SpringJmsGatewayConsumer) context
					.getBean("springJmsGatewayConsumer");
			System.out.println("Consumer receives " + springJmsConsumer.receiveMessage());
		} finally {
			broker.stop();
			context.close();
		}
	}
}

Output:

 INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB]
 INFO | KahaDB is version 6
 INFO | Recovering from the journal @1:6816
 INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is starting
 INFO | Listening for connections at: tcp://127.0.0.1:61616
 INFO | Connector tcp://127.0.0.1:61616 started
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB only has 56898 mb of usable space - resetting to maximum available disk space: 56898 mb
Producer sends Hi
Consumer receives Hi
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is shutting down
 INFO | Connector tcp://127.0.0.1:61616 stopped
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] stopped
 INFO | Stopping async queue tasks
 INFO | Stopping async topic tasks
 INFO | Stopped KahaDB
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) uptime 1.409 seconds
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is shutdown

5. Message Converter

In this example, we will send/receive a custom message Person bean. We want spring to transform the person object to the Message and convert the received Message object back to Person bean. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received to a business object and the translation of a business object to a JMS message.

Let’s now implement our own MessageConverter to handle the raw JMS messages by yourself. Spring’s JMS template can help you convert JMS messages to and from Java objects using a message converter which we will configure in our spring application context. In order to send and receive a map message, we will use the convertAndSend() and receiveAndConvert() methods, and the map will be converted to/from MapMessage.

Here is the person bean.

Person:

package com.javacodegeeks.spring.jms;

public class Person {
	private String name;
	private Integer age;
	public Person(String name, Integer age) {
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public Integer getAge() {
		return age;
	}
	public String toString() {
		return "Person: name(" + name + "), age(" + age + ")";
	}
}

Next, our own message converter.

PersonMessageConverter:

package com.javacodegeeks.spring.jms;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

public class PersonMessageConverter implements MessageConverter{

	public Message toMessage(Object object, Session session)
			throws JMSException, MessageConversionException {		
		Person person = (Person) object;
		MapMessage message = session.createMapMessage();
		message.setString("name", person.getName());
		message.setInt("age", person.getAge());
		return message;
	}

	public Object fromMessage(Message message) throws JMSException,
			MessageConversionException {
		MapMessage mapMessage = (MapMessage) message;
		Person person = new Person(mapMessage.getString("name"), mapMessage.getInt("age"));
		return person;
	}

}

The producer will use person object, convert it to a map object an then call getJmsTemplate().convertAndSend(map).

SpringJmsPersonProducer:

package com.javacodegeeks.spring.jms;

import java.util.HashMap;
import java.util.Map;

import org.springframework.jms.core.support.JmsGatewaySupport;

public class SpringJmsPersonProducer extends JmsGatewaySupport {
	public void sendMessage(final Person person) {
		System.out.println("Producer sends " + person);
		Map map = new HashMap();
		map.put("name", person.getName());
		map.put("age", person.getAge());
		getJmsTemplate().convertAndSend(map);	
	}
}

The consumer will call getJmsTemplate().receiveAndConvert() to retrieve the map object and then use it to reconstruct the person object.

SpringJmsPersonConsumer:

package com.javacodegeeks.spring.jms;

import java.util.Map;

import javax.jms.JMSException;

import org.springframework.jms.core.support.JmsGatewaySupport;

public class SpringJmsPersonConsumer extends JmsGatewaySupport {
	public Person receiveMessage() throws JMSException {
		Map map = (Map) getJmsTemplate().receiveAndConvert();
		Person person = new Person((String) map.get("name"), (Integer) map.get("age"));
		return person;	
	}
}

We will now configure the above beans in application context.

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL" value="tcp://localhost:61616" />
	</bean>
	<bean id="messageDestination" class="org.apache.activemq.command.ActiveMQQueue">
		<constructor-arg value="messageQueue1" />
	</bean>
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
	</bean>

	<bean id="springJmsProducer" class="com.javacodegeeks.spring.jms.SpringJmsProducer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
	
	<bean id="springJmsConsumer" class="com.javacodegeeks.spring.jms.SpringJmsConsumer">
		<property name="destination" ref="messageDestination" />
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>
	
        <bean id="jmsTemplateWithDefaultDestination" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
		<property name="defaultDestinationName" value="messageQueue2" />
	</bean>
	
        <bean id="springJmsGatewayProducer" class="com.javacodegeeks.spring.jms.SpringJmsGatewayProducer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
	
	<bean id="springJmsGatewayConsumer" class="com.javacodegeeks.spring.jms.SpringJmsGatewayConsumer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
	
	<bean id="springJmsPersonProducer" class="com.javacodegeeks.spring.jms.SpringJmsPersonProducer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
	
	<bean id="springJmsPersonConsumer" class="com.javacodegeeks.spring.jms.SpringJmsPersonConsumer">
		<property name="jmsTemplate" ref="jmsTemplateWithDefaultDestination" />
	</bean>
	
	<bean id="jmsTemplateWithMsgConverter" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="receiveTimeout" value="10000" />
		<property name="defaultDestinationName" value="messageQueue2" />
		<property name="messageConverter" ref="personMessageConverter" />
	</bean>
	
	<bean id="personMessageConverter" class="com.javacodegeeks.spring.jms.PersonMessageConverter" />

</beans>

Let’s now try to send a person object and receive it back.

SpringJmsMessageConverterExample:

package com.javacodegeeks.spring.jms;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringJmsMessageConverterExample {
	public static void main(String[] args) throws URISyntaxException, Exception {
		BrokerService broker = BrokerFactory.createBroker(new URI(
				"broker:(tcp://localhost:61616)"));
		broker.start();
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");

		try {
			SpringJmsPersonProducer springJmsProducer = (SpringJmsPersonProducer) context
					.getBean("springJmsPersonProducer");
			springJmsProducer.sendMessage(new Person("Joe", 32));

			SpringJmsPersonConsumer springJmsConsumer = (SpringJmsPersonConsumer) context
					.getBean("springJmsPersonConsumer");
			System.out.println("Consumer receives " + springJmsConsumer.receiveMessage());
		} finally {
			broker.stop();
			context.close();
		}
	}
}

Output:

 INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB]
 INFO | KahaDB is version 6
 INFO | Recovering from the journal @1:9020
 INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is starting
 INFO | Listening for connections at: tcp://127.0.0.1:61616
 INFO | Connector tcp://127.0.0.1:61616 started
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\KahaDB only has 56887 mb of usable space - resetting to maximum available disk space: 56887 mb
Producer sends Person: name(Joe), age(32)
Consumer receives Person: name(Joe), age(32)
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is shutting down
 INFO | Connector tcp://127.0.0.1:61616 stopped
 INFO | PListStore:[C:\javacodegeeks_ws\springJmsExample\activemq-data\localhost\tmp_storage] stopped
 INFO | Stopping async queue tasks
 INFO | Stopping async topic tasks
 INFO | Stopped KahaDB
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) uptime 1.406 seconds
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is shutdown

6. Download Eclipse Project

This was an example about Spring JMS.

Download
You can download the full source code of this example here: springJmsExample.zip

Ram Mokkapaty

Ram holds a master's degree in Machine Design from IT B.H.U. His expertise lies in test driven development and re-factoring. He is passionate about open source technologies and actively blogs on various java and open-source technologies like spring. He works as a principal Engineer in the logistics domain.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Priya
6 years ago

Java Message Service (JMS) is a specification for message passing and related operations among distributed software components. JMS vendors implement the specification, providing the requisite API library . thanks for sharing.

Kalyan
Kalyan
6 years ago

Nice article…. I found small correction. Under 2. Spring JmsTemplate Example section, in explanation of SpringJmsConsumer class, instead of JmsTemplate.receive() I see JdbcTemplate.receive() . Kindly correct the it in the explanation.

Back to top button