1 18 package org.apache.activemq.spring; 19 20 import org.springframework.jms.core.JmsTemplate; 21 import org.springframework.jms.core.MessageCreator; 22 23 import javax.jms.Destination ; 24 import javax.jms.JMSException ; 25 import javax.jms.Message ; 26 import javax.jms.Session ; 27 import javax.jms.TextMessage ; 28 29 public class SpringProducer { 30 31 private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory 32 .getLog(SpringProducer.class); 33 34 private JmsTemplate template; 35 private Destination destination; 36 private int messageCount = 10; 37 38 39 public void start() throws JMSException { 40 for (int i = 0; i < messageCount; i++) { 41 final String text = "Text for message: " + i; 42 template.send(destination, new MessageCreator() { 43 public Message createMessage(Session session) throws JMSException { 44 log.info("Sending message: " + text); 45 TextMessage message = session.createTextMessage(text); 46 message.setStringProperty("next", "foo"); 47 return message; 48 } 49 }); 50 } 51 } 52 53 public void stop() throws JMSException { 54 } 55 56 59 public JmsTemplate getTemplate() { 60 return template; 61 } 62 63 public void setTemplate(JmsTemplate template) { 64 this.template = template; 65 } 66 67 public int getMessageCount() { 68 return messageCount; 69 } 70 71 public void setMessageCount(int messageCount) { 72 this.messageCount = messageCount; 73 } 74 75 public Destination getDestination() { 76 return destination; 77 } 78 79 public void setDestination(Destination destination) { 80 this.destination = destination; 81 } 82 } 83 | Popular Tags |