1 18 package org.apache.activemq.test; 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 consumeSession = createConsumerSession(); 49 50 log.info("Created session: " + session); 51 log.info("Created consumeSession: " + consumeSession); 52 producer = session.createProducer(null); 53 producer.setDeliveryMode(deliveryMode); 54 55 log.info("Created producer: " + producer + " delivery mode = " + 56 (deliveryMode == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT")); 57 58 if (topic) { 59 consumerDestination = session.createTopic(getConsumerSubject()); 60 producerDestination = session.createTopic(getProducerSubject()); 61 } 62 else { 63 consumerDestination = session.createQueue(getConsumerSubject()); 64 producerDestination = session.createQueue(getProducerSubject()); 65 } 66 67 log.info("Created consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass()); 68 log.info("Created producer destination: " + producerDestination + " of type: " + producerDestination.getClass()); 69 consumer = createConsumer(); 70 consumer.setMessageListener(this); 71 connection.start(); 72 73 log.info("Created connection: " + connection); 74 } 75 76 protected void tearDown() throws Exception { 77 log.info("Dumping stats..."); 78 81 log.info("Closing down connection"); 82 83 84 session.close(); 85 connection.close(); 86 } 87 88 94 protected Session createConsumerSession() throws JMSException { 95 if (useSeparateSession) { 96 return connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 97 } 98 else { 99 return session; 100 } 101 } 102 103 109 protected MessageConsumer createConsumer() throws JMSException { 110 if (durable) { 111 log.info("Creating durable consumer"); 112 return consumeSession.createDurableSubscriber((Topic ) consumerDestination, getName()); 113 } 114 return consumeSession.createConsumer(consumerDestination); 115 } 116 } 117 | Popular Tags |