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 26 import org.apache.activemq.ActiveMQConnectionFactory; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 33 public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTestSupport { 34 35 protected static final Log log = LogFactory.getLog(JmsTopicSendReceiveWithTwoConnectionsTest.class); 36 37 protected Connection sendConnection; 38 protected Connection receiveConnection; 39 protected Session receiveSession; 40 41 46 protected void setUp() throws Exception { 47 super.setUp(); 48 49 connectionFactory = createConnectionFactory(); 50 51 log.info("Creating send connection"); 52 sendConnection = createSendConnection(); 53 log.info("Starting send connection"); 54 sendConnection.start(); 55 56 log.info("Creating receive connection"); 57 receiveConnection = createReceiveConnection(); 58 log.info("Starting receive connection"); 59 receiveConnection.start(); 60 61 log.info("Created sendConnection: " + sendConnection); 62 log.info("Created receiveConnection: " + receiveConnection); 63 64 session = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); 65 receiveSession = receiveConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); 66 67 log.info("Created sendSession: " + session); 68 log.info("Created receiveSession: " + receiveSession); 69 70 producer = session.createProducer(null); 71 producer.setDeliveryMode(deliveryMode); 72 73 log.info("Created producer: " + producer + " delivery mode = " + 74 (deliveryMode == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT")); 75 76 if (topic) { 77 consumerDestination = session.createTopic(getConsumerSubject()); 78 producerDestination = session.createTopic(getProducerSubject()); 79 } 80 else { 81 consumerDestination = session.createQueue(getConsumerSubject()); 82 producerDestination = session.createQueue(getProducerSubject()); 83 } 84 85 log.info("Created consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass()); 86 log.info("Created producer destination: " + producerDestination + " of type: " + producerDestination.getClass()); 87 88 consumer = createConsumer(); 89 consumer.setMessageListener(this); 90 91 log.info("Started connections"); 92 } 93 94 protected MessageConsumer createConsumer() throws JMSException { 95 return receiveSession.createConsumer(consumerDestination); 96 } 97 98 101 protected void tearDown() throws Exception { 102 session.close(); 103 receiveSession.close(); 104 sendConnection.close(); 105 receiveConnection.close(); 106 } 107 108 114 protected Connection createReceiveConnection() throws Exception { 115 return createConnection(); 116 } 117 118 124 protected Connection createSendConnection() throws Exception { 125 return createConnection(); 126 } 127 128 133 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { 134 return new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); 135 } 136 } 137 | Popular Tags |