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 31 public class Producer{ 32 protected Connection connection; 33 protected MessageProducer producer; 34 public Producer(ConnectionFactory fac,Destination dest) throws JMSException { 35 connection=fac.createConnection(); 36 Session s=connection.createSession(false,Session.AUTO_ACKNOWLEDGE); 37 producer=s.createProducer(dest); 38 } 39 public void setDeliveryMode(int mode) throws JMSException { 40 producer.setDeliveryMode(mode); 41 } 42 public void start() throws JMSException { 43 connection.start(); 44 } 45 public void stop() throws JMSException { 46 connection.stop(); 47 } 48 public void shutDown() throws JMSException { 49 connection.close(); 50 } 51 52 public void sendMessage(Message msg) throws JMSException { 53 sendMessage(msg, null,0); 54 } 55 56 60 public void sendMessage(Message msg, String headerName, long headerValue) throws JMSException { 61 if(headerName != null) { 62 msg.setLongProperty(headerName, headerValue); 63 } 64 65 producer.send(msg); 66 67 } 68 69 } 70 | Popular Tags |