PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/jcg-andygene-web-archetype/src/main/resources/archetype-resources/src/main/java/jms/MyQueueSender.java

http://jcg-andygene-web.googlecode.com/
Java | 51 lines | 42 code | 9 blank | 0 comment | 0 complexity | 5138c171fe1e498cccc84d364b72bd5a MD5 | raw file
 1#set( $symbol_pound = '#' )
 2#set( $symbol_dollar = '$' )
 3#set( $symbol_escape = '\' )
 4package ${package}.jms;
 5
 6import javax.jms.DeliveryMode;
 7import javax.jms.JMSException;
 8import javax.jms.Message;
 9import javax.jms.Session;
10import javax.jms.TextMessage;
11
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14import org.springframework.beans.factory.annotation.Autowired;
15import org.springframework.jms.core.JmsTemplate;
16import org.springframework.jms.core.MessageCreator;
17import org.springframework.stereotype.Component;
18
19@Component("myQueueSender")
20public class MyQueueSender {
21	
22	private Logger log = LoggerFactory.getLogger(MyQueueSender.class);
23	
24	@Autowired
25	private JmsTemplate jmsTemplate;
26	
27	public void sendMessage(final String myMessage) {
28		MessageCreator messageCreator = new MessageCreator() {
29            public Message createMessage(Session session)
30	            {
31	                TextMessage message = null;
32	                try 
33	                {
34	                    message = session.createTextMessage();
35	                    message.setText(myMessage);
36	                }
37	                catch (JMSException e)
38	                {
39	                    log.error("Error Sending Message",e);
40	                }
41	                return message;
42	        }
43
44
45		};
46		jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);
47		jmsTemplate.send("myDestination", messageCreator);
48		log.info("Message Send");
49	}
50
51}