From 65cd2dfb064dcae0c98112d4b37c470e59385e38 Mon Sep 17 00:00:00 2001 From: Kiran Date: Wed, 12 Oct 2016 12:08:13 -0400 Subject: [PATCH] Code refactored and updated (#746) * Updated indentation and refactored code * Updated indentation and refactored code * Updated indentation and refactored code * Updated indentation and refactored code * Updated indentation * Updated indentation and refactored code * Updated indentation and refactored code --- spring-jms/pom.xml | 27 +++++----- .../spring/jms/SampleJmsMessageSender.java | 6 +-- .../baeldung/spring/jms/SampleListener.java | 17 +++--- .../src/main/resources/EmbeddedActiveMQ.xml | 27 +++++----- .../src/main/resources/applicationContext.xml | 53 +++++++++++-------- .../jms/MapMessageConvertAndSendTest.java | 6 +-- 6 files changed, 76 insertions(+), 60 deletions(-) diff --git a/spring-jms/pom.xml b/spring-jms/pom.xml index b15c18f991..8e83f82f38 100644 --- a/spring-jms/pom.xml +++ b/spring-jms/pom.xml @@ -11,6 +11,7 @@ 4.3.2.RELEASE 5.12.0 + 4.12 @@ -29,7 +30,7 @@ junit junit - 4.12 + ${junit.version} test @@ -58,16 +59,16 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - spring-jms + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + spring-jms - \ No newline at end of file + diff --git a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java index 1ef3902a31..927762f05b 100644 --- a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java +++ b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java @@ -24,10 +24,6 @@ public class SampleJmsMessageSender { } public void sendMessage(final Employee employee) { - System.out.println("Jms Message Sender : " + employee); - Map map = new HashMap<>(); - map.put("name", employee.getName()); - map.put("age", employee.getAge()); - this.jmsTemplate.convertAndSend(map); + this.jmsTemplate.convertAndSend(employee); } } diff --git a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java index eb9d51160d..6d4bef5402 100644 --- a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java +++ b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java @@ -5,13 +5,21 @@ import org.springframework.jms.core.JmsTemplate; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; +import javax.jms.Queue; import javax.jms.TextMessage; import java.util.Map; public class SampleListener implements MessageListener { - public JmsTemplate getJmsTemplate() { - return getJmsTemplate(); + private JmsTemplate jmsTemplate; + private Queue queue; + + public void setJmsTemplate(JmsTemplate jmsTemplate) { + this.jmsTemplate = jmsTemplate; + } + + public void setQueue(Queue queue) { + this.queue = queue; } public void onMessage(Message message) { @@ -19,17 +27,14 @@ public class SampleListener implements MessageListener { try { String msg = ((TextMessage) message).getText(); - System.out.println("Message has been consumed : " + msg); } catch (JMSException ex) { throw new RuntimeException(ex); } - } else { - throw new IllegalArgumentException("Message Error"); } } public Employee receiveMessage() throws JMSException { - Map map = (Map) getJmsTemplate().receiveAndConvert(); + Map map = (Map) this.jmsTemplate.receiveAndConvert(); return new Employee((String) map.get("name"), (Integer) map.get("age")); } } diff --git a/spring-jms/src/main/resources/EmbeddedActiveMQ.xml b/spring-jms/src/main/resources/EmbeddedActiveMQ.xml index 6b419c3270..016b07e831 100644 --- a/spring-jms/src/main/resources/EmbeddedActiveMQ.xml +++ b/spring-jms/src/main/resources/EmbeddedActiveMQ.xml @@ -1,15 +1,18 @@ - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" + xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" + xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" + xmlns:amq="http://activemq.apache.org/schema/core" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://activemq.apache.org/schema/core + http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> + + + + + + + diff --git a/spring-jms/src/main/resources/applicationContext.xml b/spring-jms/src/main/resources/applicationContext.xml index d94eb4c371..28bf848e59 100644 --- a/spring-jms/src/main/resources/applicationContext.xml +++ b/spring-jms/src/main/resources/applicationContext.xml @@ -1,34 +1,45 @@ + xmlns:amq="http://activemq.apache.org/schema/core" 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-2.0.xsd + http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - + + + + +