1 18 package org.apache.activemq.tool; 19 20 import javax.jms.Connection ; 21 import javax.jms.ConnectionFactory ; 22 import javax.jms.DeliveryMode ; 23 import javax.jms.Destination ; 24 import javax.jms.JMSException ; 25 import javax.jms.Message ; 26 import javax.jms.MessageProducer ; 27 import javax.jms.Session ; 28 29 32 public class MemProducer { 33 protected Connection connection; 34 protected MessageProducer producer; 35 36 public MemProducer(ConnectionFactory fac, Destination dest) throws JMSException { 37 connection = fac.createConnection(); 38 Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 39 producer = s.createProducer(dest); 40 } 41 42 public void setDeliveryMode(int mode) throws JMSException { 43 producer.setDeliveryMode(mode); 44 } 45 46 public void start() throws JMSException { 47 connection.start(); 48 } 49 50 public void stop() throws JMSException { 51 connection.stop(); 52 } 53 54 public void shutDown() throws JMSException { 55 connection.close(); 56 } 57 58 public void sendMessage(Message msg) throws JMSException { 59 sendMessage(msg, null, 0); 60 } 61 62 66 public void sendMessage(Message msg, String headerName, long headerValue) throws JMSException { 67 if (headerName != null) { 68 msg.setLongProperty(headerName, headerValue); 69 } 70 71 producer.send(msg); 72 73 } 74 75 } 76 | Popular Tags |