1 18 package org.apache.activemq; 19 20 import javax.jms.Connection ; 21 import javax.jms.DeliveryMode ; 22 import javax.jms.JMSException ; 23 import javax.jms.MessageConsumer ; 24 import javax.jms.Session ; 25 import javax.jms.Topic ; 26 27 30 public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport { 31 private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory 32 .getLog(JmsTopicSendReceiveTest.class); 33 34 protected Connection connection; 35 36 protected void setUp() throws Exception { 37 super.setUp(); 38 39 connectionFactory = createConnectionFactory(); 40 connection = createConnection(); 41 if (durable) { 42 connection.setClientID(getClass().getName()); 43 } 44 45 log.info("Created connection: " + connection); 46 47 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 48 49 log.info("Created session: " + session); 50 producer = session.createProducer(null); 51 producer.setDeliveryMode(deliveryMode); 52 53 log.info("Created producer: " + producer + " delivery mode = " + 54 (deliveryMode == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT")); 55 56 if (topic) { 57 consumerDestination = session.createTopic(getConsumerSubject()); 58 producerDestination = session.createTopic(getProducerSubject()); 59 } 60 else { 61 consumerDestination = session.createQueue(getConsumerSubject()); 62 producerDestination = session.createQueue(getProducerSubject()); 63 } 64 65 log.info("Created consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass()); 66 log.info("Created producer destination: " + producerDestination + " of type: " + producerDestination.getClass()); 67 consumer = createConsumer(); 68 consumer.setMessageListener(this); 69 connection.start(); 70 71 } 73 74 protected MessageConsumer createConsumer() throws JMSException { 75 if (durable) { 76 log.info("Creating durable consumer"); 77 return session.createDurableSubscriber((Topic ) consumerDestination, getName()); 78 } 79 return session.createConsumer(consumerDestination); 80 } 81 82 protected void tearDown() throws Exception { 83 log.info("Dumping stats..."); 84 86 log.info("Closing down connection"); 87 88 89 session.close(); 90 connection.close(); 91 } 92 93 } 94 | Popular Tags |