{"id":27968,"date":"2015-10-16T15:00:39","date_gmt":"2015-10-16T12:00:39","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=27968"},"modified":"2015-10-15T22:11:42","modified_gmt":"2015-10-15T19:11:42","slug":"spring-jms-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/","title":{"rendered":"Spring JMS Example"},"content":{"rendered":"<p>Java Messaging Service (JMS) is a standard messaging API used to send and receive messages.<\/p>\n<p>Spring simplifies the use of JMS API by providing another layer around the JMS layer.<\/p>\n<p>This layer provides convenience methods for sending and receiving messages, as well as manages the creation and release of resources like the connection object.<\/p>\n<p>The <code>JmsTemplate<\/code> class is the main class which we will be using often to work with the JMS API.<\/p>\n<h2>1. Dependencies<\/h2>\n<p>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.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t&lt;groupId&gt;com.javacodegeeks.camel&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;springQuartzScheduler&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-core&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;4.1.5.RELEASE&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;4.1.5.RELEASE&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-jms&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;4.1.5.RELEASE&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.apache.activemq&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;activemq-all&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;5.12.0&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t&lt;\/dependencies&gt;\r\n\t\r\n&lt;\/project&gt;\r\n<\/pre>\n<h2>2. Spring JmsTemplate Example<\/h2>\n<p>Spring provides JMS integration using <code>JmsTemplate<\/code> class. It helps eliminating the verbose and repetitive JMS code. <code>JmsTemplate<\/code> 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 <code>JmsException<\/code>.<\/p>\n<p>Let&#8217;s start with the producer.<\/p>\n<p>In the below class, notice the sendMessage() method. It delegates the call to <code>JmsTemplate.send()<\/code>. 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.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsProducer:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport javax.jms.Destination;\r\nimport javax.jms.JMSException;\r\nimport javax.jms.Message;\r\nimport javax.jms.Session;\r\n\r\nimport org.springframework.jms.core.JmsTemplate;\r\nimport org.springframework.jms.core.MessageCreator;\r\n\r\npublic class SpringJmsProducer {\r\n\tprivate JmsTemplate jmsTemplate;\r\n\tprivate Destination destination;\r\n\t\r\n\tpublic JmsTemplate getJmsTemplate() {\r\n\t\treturn jmsTemplate;\r\n\t}\r\n\r\n\tpublic void setJmsTemplate(JmsTemplate jmsTemplate) {\r\n\t\tthis.jmsTemplate = jmsTemplate;\r\n\t}\r\n\t\r\n\tpublic Destination getDestination() {\r\n\t\treturn destination;\r\n\t}\r\n\r\n\tpublic void setDestination(Destination destination) {\r\n\t\tthis.destination = destination;\r\n\t}\r\n\r\n\tpublic void sendMessage(final String msg) {\r\n\t\tSystem.out.println(\"Producer sends \" + msg);\r\n\t\tjmsTemplate.send(destination, new MessageCreator() {\r\n\t\t\tpublic Message createMessage(Session session) throws JMSException {\r\n\t\t\t\treturn session.createTextMessage(msg);\r\n\t\t\t}});\t\t\r\n\t}\r\n}\r\n<\/pre>\n<p>In the consumer, we will receive the JMS message again with the help of the JMS template. In <code>receiveMessage()<\/code>, the call is delegated to <code>JdbcTemplate.receive()<\/code> method by providing a message destination. This method returns a JMS message of type <code>javax.jms.Message<\/code>. Since we know the message is a <code>TextMessage<\/code> we return the actual payload by calling <code>textMessage.getText()<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsConsumer:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport javax.jms.Destination;\r\nimport javax.jms.JMSException;\r\nimport javax.jms.TextMessage;\r\n\r\nimport org.springframework.jms.core.JmsTemplate;\r\n\r\npublic class SpringJmsConsumer {\r\n\tprivate JmsTemplate jmsTemplate;\r\n\tprivate Destination destination;\r\n\t\r\n\tpublic JmsTemplate getJmsTemplate() {\r\n\t\treturn jmsTemplate;\r\n\t}\r\n\r\n\tpublic void setJmsTemplate(JmsTemplate jmsTemplate) {\r\n\t\tthis.jmsTemplate = jmsTemplate;\r\n\t}\r\n\t\r\n\tpublic Destination getDestination() {\r\n\t\treturn destination;\r\n\t}\r\n\r\n\tpublic void setDestination(Destination destination) {\r\n\t\tthis.destination = destination;\r\n\t}\r\n\r\n\tpublic String receiveMessage() throws JMSException {\r\n\t\tTextMessage textMessage = (TextMessage) jmsTemplate.receive(destination);\t\t\r\n\t\treturn textMessage.getText();\r\n\t}\r\n}\r\n<\/pre>\n<h2>3. Configuring JmsTemplate<\/h2>\n<p>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\u2019re using ActiveMQ as our message broker, we\u2019ll have to configure the JMS connection factory so that it knows how to connect to ActiveMQ. <code>ActiveMQConnectionFactory<\/code> is the JMS connection factory that comes with ActiveMQ.<\/p>\n<p>The brokerURL property tells the connection factory where the message broker is located. The URL we are using is <code>tcp:\/\/localhost:61616<\/code>.<\/p>\n<p>Next, we need to configure a destination. The destination can be either a queue or a topic, depending on the needs of the application.<\/p>\n<p>Once we have configured, a connection factory and destination, we will configure the <code>JmsTemplate<\/code> bean. Since both our producer and consumer both are dependent on JmsTemplate, we need to inject the <code>jmsTemplate<\/code> bean in their definitions.<\/p>\n<p><span style=\"text-decoration: underline\"><em>applicationContext.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n\t&lt;bean id=\"connectionFactory\" class=\"org.apache.activemq.ActiveMQConnectionFactory\"&gt;\r\n\t\t&lt;property name=\"brokerURL\" value=\"tcp:\/\/localhost:61616\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"messageDestination\" class=\"org.apache.activemq.command.ActiveMQQueue\"&gt;\r\n\t\t&lt;constructor-arg value=\"messageQueue1\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"jmsTemplate\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n\t&lt;bean id=\"springJmsProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsProducer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsConsumer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>Let&#8217;s test the JMS Example.<\/p>\n<p>In order for the producer and consumer to connect to the broker, we must have the broker started.<\/p>\n<pre class=\"brush:java\">BrokerService broker = BrokerFactory.createBroker(new URI(\r\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\r\nbroker.start();\r\n<\/pre>\n<p>Next, we load the spring application context. Once we have the context, we get the producer bean and call <code>springJmsProducer.sendMessage(\"Hi\")<\/code>. 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 <code>springJmsConsumer.receiveMessage()<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport java.net.URI;\r\nimport java.net.URISyntaxException;\r\n\r\nimport org.apache.activemq.broker.BrokerFactory;\r\nimport org.apache.activemq.broker.BrokerService;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\npublic class SpringJmsExample {\r\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\r\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\r\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\r\n\t\tbroker.start();\r\n\t\tClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(\r\n\t\t\t\t\"applicationContext.xml\");\r\n\r\n\t\ttry {\r\n\t\t\tSpringJmsProducer springJmsProducer = (SpringJmsProducer) context\r\n\t\t\t\t\t.getBean(\"springJmsProducer\");\r\n\t\t\tspringJmsProducer.sendMessage(\"Hi\");\r\n\r\n\t\t\tSpringJmsConsumer springJmsConsumer = (SpringJmsConsumer) context\r\n\t\t\t\t\t.getBean(\"springJmsConsumer\");\r\n\t\t\tSystem.out.println(\"Consumer receives \" + springJmsConsumer.receiveMessage());\r\n\t\t} finally {\r\n\t\t\tbroker.stop();\r\n\t\t\tcontext.close();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] started\r\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\KahaDB]\r\n INFO | KahaDB is version 6\r\n INFO | Recovering from the journal @1:1580\r\n INFO | Recovery replayed 1 operations from the journal in 0.01 seconds.\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is starting\r\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) started\r\n INFO | For help or more information please see: http:\/\/activemq.apache.org\r\n 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\r\nProducer sends Hi\r\nConsumer receives Hi\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is shutting down\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] stopped\r\n INFO | Stopping async queue tasks\r\n INFO | Stopping async topic tasks\r\n INFO | Stopped KahaDB\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) uptime 1.433 seconds\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56935-1444920918425-0:1) is shutdown\r\n<\/pre>\n<h2>4. Spring JmsGatewaySupport Example<\/h2>\n<p>In this example, our producer and consumer beans will extend <code>JmsGatewaySupport<\/code> 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.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsGatewayProducer:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport javax.jms.JMSException;\r\nimport javax.jms.Message;\r\nimport javax.jms.Session;\r\n\r\nimport org.springframework.jms.core.MessageCreator;\r\nimport org.springframework.jms.core.support.JmsGatewaySupport;\r\n\r\npublic class SpringJmsGatewayProducer extends JmsGatewaySupport {\r\n\tpublic void sendMessage(final String msg) {\r\n\t\tSystem.out.println(\"Producer sends \" + msg);\r\n\t\tgetJmsTemplate().send(new MessageCreator() {\r\n\t\t\tpublic Message createMessage(Session session) throws JMSException {\r\n\t\t\t\treturn session.createTextMessage(msg);\r\n\t\t\t}});\t\t\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsGatewayConsumer:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport javax.jms.JMSException;\r\nimport javax.jms.TextMessage;\r\n\r\nimport org.springframework.jms.core.support.JmsGatewaySupport;\r\n\r\npublic class SpringJmsGatewayConsumer extends JmsGatewaySupport {\r\n\tpublic String receiveMessage() throws JMSException {\r\n\t\tTextMessage textMessage = (TextMessage) getJmsTemplate().receive();\t\t\r\n\t\treturn textMessage.getText();\t\t\r\n\t}\r\n}\r\n<\/pre>\n<p>In <code>jmsTemplateWithDefaultDestination<\/code>, we have specified a default message destination so now we don&#8217;t have inject the destination to our producer and consumer beans.<\/p>\n<p><span style=\"text-decoration: underline\"><em>applicationContext.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n\t&lt;bean id=\"connectionFactory\" class=\"org.apache.activemq.ActiveMQConnectionFactory\"&gt;\r\n\t\t&lt;property name=\"brokerURL\" value=\"tcp:\/\/localhost:61616\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"messageDestination\" class=\"org.apache.activemq.command.ActiveMQQueue\"&gt;\r\n\t\t&lt;constructor-arg value=\"messageQueue1\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"jmsTemplate\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n\t&lt;bean id=\"springJmsProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsProducer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsConsumer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n        &lt;bean id=\"jmsTemplateWithDefaultDestination\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t\t&lt;property name=\"defaultDestinationName\" value=\"messageQueue2\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n        &lt;bean id=\"springJmsGatewayProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsGatewayProducer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsGatewayConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsGatewayConsumer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>Let&#8217;s retest the example now with enhanced producer and consumer beans.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsGatewaySupportExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport java.net.URI;\r\nimport java.net.URISyntaxException;\r\n\r\nimport org.apache.activemq.broker.BrokerFactory;\r\nimport org.apache.activemq.broker.BrokerService;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\npublic class SpringJmsGatewaySupportExample {\r\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\r\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\r\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\r\n\t\tbroker.start();\r\n\t\tClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(\r\n\t\t\t\t\"applicationContext.xml\");\r\n\r\n\t\ttry {\r\n\t\t\tSpringJmsGatewayProducer springJmsProducer = (SpringJmsGatewayProducer) context\r\n\t\t\t\t\t.getBean(\"springJmsGatewayProducer\");\r\n\t\t\tspringJmsProducer.sendMessage(\"Hi\");\r\n\r\n\t\t\tSpringJmsGatewayConsumer springJmsConsumer = (SpringJmsGatewayConsumer) context\r\n\t\t\t\t\t.getBean(\"springJmsGatewayConsumer\");\r\n\t\t\tSystem.out.println(\"Consumer receives \" + springJmsConsumer.receiveMessage());\r\n\t\t} finally {\r\n\t\t\tbroker.stop();\r\n\t\t\tcontext.close();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] started\r\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\KahaDB]\r\n INFO | KahaDB is version 6\r\n INFO | Recovering from the journal @1:6816\r\n INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is starting\r\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) started\r\n INFO | For help or more information please see: http:\/\/activemq.apache.org\r\n 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\r\nProducer sends Hi\r\nConsumer receives Hi\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is shutting down\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] stopped\r\n INFO | Stopping async queue tasks\r\n INFO | Stopping async topic tasks\r\n INFO | Stopped KahaDB\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) uptime 1.409 seconds\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-58078-1444922028793-0:1) is shutdown\r\n<\/pre>\n<h2>5. Message Converter<\/h2>\n<p>In this example, we will send\/receive a custom message <code>Person<\/code> bean. We want spring to transform the person object to the <code>Message<\/code> and convert the received <code>Message<\/code> object back to <code>Person<\/code> 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.<\/p>\n<p>Let&#8217;s now implement our own <code>MessageConverter<\/code> to handle the raw JMS messages by yourself. Spring\u2019s 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 <code>convertAndSend()<\/code> and <code>receiveAndConvert()<\/code> methods, and the map will be converted to\/from MapMessage.<\/p>\n<p>Here is the person bean.<\/p>\n<p><em><span style=\"text-decoration: underline\">Person:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\npublic class Person {\r\n\tprivate String name;\r\n\tprivate Integer age;\r\n\tpublic Person(String name, Integer age) {\r\n\t\tthis.name = name;\r\n\t\tthis.age = age;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic Integer getAge() {\r\n\t\treturn age;\r\n\t}\r\n\tpublic String toString() {\r\n\t\treturn \"Person: name(\" + name + \"), age(\" + age + \")\";\r\n\t}\r\n}\r\n<\/pre>\n<p>Next, our own message converter.<\/p>\n<p><em><span style=\"text-decoration: underline\">PersonMessageConverter:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport javax.jms.JMSException;\r\nimport javax.jms.MapMessage;\r\nimport javax.jms.Message;\r\nimport javax.jms.Session;\r\n\r\nimport org.springframework.jms.support.converter.MessageConversionException;\r\nimport org.springframework.jms.support.converter.MessageConverter;\r\n\r\npublic class PersonMessageConverter implements MessageConverter{\r\n\r\n\tpublic Message toMessage(Object object, Session session)\r\n\t\t\tthrows JMSException, MessageConversionException {\t\t\r\n\t\tPerson person = (Person) object;\r\n\t\tMapMessage message = session.createMapMessage();\r\n\t\tmessage.setString(\"name\", person.getName());\r\n\t\tmessage.setInt(\"age\", person.getAge());\r\n\t\treturn message;\r\n\t}\r\n\r\n\tpublic Object fromMessage(Message message) throws JMSException,\r\n\t\t\tMessageConversionException {\r\n\t\tMapMessage mapMessage = (MapMessage) message;\r\n\t\tPerson person = new Person(mapMessage.getString(\"name\"), mapMessage.getInt(\"age\"));\r\n\t\treturn person;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>The producer will use person object, convert it to a map object an then call <code>getJmsTemplate().convertAndSend(map)<\/code>.<\/p>\n<p><em><span style=\"text-decoration: underline\">SpringJmsPersonProducer:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\nimport org.springframework.jms.core.support.JmsGatewaySupport;\r\n\r\npublic class SpringJmsPersonProducer extends JmsGatewaySupport {\r\n\tpublic void sendMessage(final Person person) {\r\n\t\tSystem.out.println(\"Producer sends \" + person);\r\n\t\tMap map = new HashMap();\r\n\t\tmap.put(\"name\", person.getName());\r\n\t\tmap.put(\"age\", person.getAge());\r\n\t\tgetJmsTemplate().convertAndSend(map);\t\r\n\t}\r\n}\r\n<\/pre>\n<p>The consumer will call <code>getJmsTemplate().receiveAndConvert()<\/code> to retrieve the map object and then use it to reconstruct the person object.<\/p>\n<p><em><span style=\"text-decoration: underline\">SpringJmsPersonConsumer:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport java.util.Map;\r\n\r\nimport javax.jms.JMSException;\r\n\r\nimport org.springframework.jms.core.support.JmsGatewaySupport;\r\n\r\npublic class SpringJmsPersonConsumer extends JmsGatewaySupport {\r\n\tpublic Person receiveMessage() throws JMSException {\r\n\t\tMap map = (Map) getJmsTemplate().receiveAndConvert();\r\n\t\tPerson person = new Person((String) map.get(\"name\"), (Integer) map.get(\"age\"));\r\n\t\treturn person;\t\r\n\t}\r\n}\r\n<\/pre>\n<p>We will now configure the above beans in application context.<\/p>\n<p><span style=\"text-decoration: underline\"><em>applicationContext.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n\t&lt;bean id=\"connectionFactory\" class=\"org.apache.activemq.ActiveMQConnectionFactory\"&gt;\r\n\t\t&lt;property name=\"brokerURL\" value=\"tcp:\/\/localhost:61616\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"messageDestination\" class=\"org.apache.activemq.command.ActiveMQQueue\"&gt;\r\n\t\t&lt;constructor-arg value=\"messageQueue1\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t&lt;bean id=\"jmsTemplate\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n\t&lt;bean id=\"springJmsProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsProducer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsConsumer\"&gt;\r\n\t\t&lt;property name=\"destination\" ref=\"messageDestination\" \/&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplate\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n        &lt;bean id=\"jmsTemplateWithDefaultDestination\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t\t&lt;property name=\"defaultDestinationName\" value=\"messageQueue2\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n        &lt;bean id=\"springJmsGatewayProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsGatewayProducer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsGatewayConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsGatewayConsumer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsPersonProducer\" class=\"com.javacodegeeks.spring.jms.SpringJmsPersonProducer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"springJmsPersonConsumer\" class=\"com.javacodegeeks.spring.jms.SpringJmsPersonConsumer\"&gt;\r\n\t\t&lt;property name=\"jmsTemplate\" ref=\"jmsTemplateWithDefaultDestination\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"jmsTemplateWithMsgConverter\" class=\"org.springframework.jms.core.JmsTemplate\"&gt;\r\n\t\t&lt;property name=\"connectionFactory\" ref=\"connectionFactory\" \/&gt;\r\n\t\t&lt;property name=\"receiveTimeout\" value=\"10000\" \/&gt;\r\n\t\t&lt;property name=\"defaultDestinationName\" value=\"messageQueue2\" \/&gt;\r\n\t\t&lt;property name=\"messageConverter\" ref=\"personMessageConverter\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"personMessageConverter\" class=\"com.javacodegeeks.spring.jms.PersonMessageConverter\" \/&gt;\r\n\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>Let&#8217;s now try to send a person object and receive it back.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SpringJmsMessageConverterExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.spring.jms;\r\n\r\nimport java.net.URI;\r\nimport java.net.URISyntaxException;\r\n\r\nimport org.apache.activemq.broker.BrokerFactory;\r\nimport org.apache.activemq.broker.BrokerService;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\npublic class SpringJmsMessageConverterExample {\r\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\r\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\r\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\r\n\t\tbroker.start();\r\n\t\tClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(\r\n\t\t\t\t\"applicationContext.xml\");\r\n\r\n\t\ttry {\r\n\t\t\tSpringJmsPersonProducer springJmsProducer = (SpringJmsPersonProducer) context\r\n\t\t\t\t\t.getBean(\"springJmsPersonProducer\");\r\n\t\t\tspringJmsProducer.sendMessage(new Person(\"Joe\", 32));\r\n\r\n\t\t\tSpringJmsPersonConsumer springJmsConsumer = (SpringJmsPersonConsumer) context\r\n\t\t\t\t\t.getBean(\"springJmsPersonConsumer\");\r\n\t\t\tSystem.out.println(\"Consumer receives \" + springJmsConsumer.receiveMessage());\r\n\t\t} finally {\r\n\t\t\tbroker.stop();\r\n\t\t\tcontext.close();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] started\r\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\KahaDB]\r\n INFO | KahaDB is version 6\r\n INFO | Recovering from the journal @1:9020\r\n INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is starting\r\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) started\r\n INFO | For help or more information please see: http:\/\/activemq.apache.org\r\n 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\r\nProducer sends Person: name(Joe), age(32)\r\nConsumer receives Person: name(Joe), age(32)\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is shutting down\r\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\r\n INFO | PListStore:[C:\\javacodegeeks_ws\\springJmsExample\\activemq-data\\localhost\\tmp_storage] stopped\r\n INFO | Stopping async queue tasks\r\n INFO | Stopping async topic tasks\r\n INFO | Stopped KahaDB\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) uptime 1.406 seconds\r\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-59623-1444923537588-0:1) is shutdown\r\n<\/pre>\n<h2>6. Download Eclipse Project<\/h2>\n<p>This was an example about Spring JMS. <\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/springJmsExample.zip\"><strong>springJmsExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip;<\/p>\n","protected":false},"author":38,"featured_media":1248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-27968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring JMS Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"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\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring JMS Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"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\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-16T12:00:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ram Mokkapaty\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ram Mokkapaty\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\"},\"author\":{\"name\":\"Ram Mokkapaty\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\"},\"headline\":\"Spring JMS Example\",\"datePublished\":\"2015-10-16T12:00:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\"},\"wordCount\":835,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"articleSection\":[\"spring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\",\"name\":\"Spring JMS Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"datePublished\":\"2015-10-16T12:00:39+00:00\",\"description\":\"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\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"spring\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Spring JMS Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\",\"name\":\"Ram Mokkapaty\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg\",\"caption\":\"Ram Mokkapaty\"},\"description\":\"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.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/in.linkedin.com\/pub\/ram-satish-mokkapaty\/18\/123\/52b\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ram-mokkapaty\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring JMS Example - Java Code Geeks","description":"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","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/","og_locale":"en_US","og_type":"article","og_title":"Spring JMS Example - Java Code Geeks","og_description":"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","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-10-16T12:00:39+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Ram Mokkapaty","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ram Mokkapaty","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/"},"author":{"name":"Ram Mokkapaty","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8"},"headline":"Spring JMS Example","datePublished":"2015-10-16T12:00:39+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/"},"wordCount":835,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","articleSection":["spring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/","name":"Spring JMS Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","datePublished":"2015-10-16T12:00:39+00:00","description":"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","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-jms-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"spring","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/"},{"@type":"ListItem","position":5,"name":"Spring JMS Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8","name":"Ram Mokkapaty","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg","caption":"Ram Mokkapaty"},"description":"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.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/in.linkedin.com\/pub\/ram-satish-mokkapaty\/18\/123\/52b"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ram-mokkapaty\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=27968"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27968\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1248"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=27968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=27968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=27968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}