Refactor spring-jms code samples
This commit is contained in:
parent
1296f2e40f
commit
64d5a03863
1
pom.xml
1
pom.xml
|
@ -90,6 +90,7 @@
|
|||
<module>spring-hibernate3</module>
|
||||
<module>spring-hibernate4</module>
|
||||
<module>spring-jpa</module>
|
||||
<module>spring-jms</module>
|
||||
<module>spring-katharsis</module>
|
||||
<module>spring-mockito</module>
|
||||
<module>spring-mvc-java</module>
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package com.baeldung.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;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class SampleJMSExample {
|
||||
public static void main(String[] args) throws URISyntaxException, Exception {
|
||||
public static void main(String[] args) throws Exception {
|
||||
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:61616)"));
|
||||
broker.start();
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
|
|
@ -1,20 +1,16 @@
|
|||
package com.baeldung.spring.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.MessageCreator;
|
||||
|
||||
import javax.jms.*;
|
||||
|
||||
public class SampleJmsMessageSender {
|
||||
|
||||
private JmsTemplate jmsTemplate;
|
||||
private Queue queue;
|
||||
|
||||
public void setConnectionFactory(ConnectionFactory cf) {
|
||||
public void createJmsTemplate(ConnectionFactory cf) {
|
||||
this.jmsTemplate = new JmsTemplate(cf);
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package com.baeldung.spring.jms;
|
||||
|
||||
import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
|
||||
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 SampleMessageConverter implements MessageConverter {
|
||||
|
||||
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||
|
@ -20,8 +20,7 @@ public class SampleMessageConverter implements MessageConverter {
|
|||
|
||||
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
|
||||
MapMessage mapMessage = (MapMessage) message;
|
||||
Employee person = new Employee(mapMessage.getString("name"), mapMessage.getInt("age"));
|
||||
return person;
|
||||
return new Employee(mapMessage.getString("name"), mapMessage.getInt("age"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue