1 17 package org.apache.activemq.broker.virtual; 18 19 import org.apache.activemq.EmbeddedBrokerTestSupport; 20 import org.apache.activemq.command.ActiveMQQueue; 21 import org.apache.activemq.command.ActiveMQTopic; 22 import org.apache.activemq.spring.ConsumerBean; 23 24 import javax.jms.Connection ; 25 import javax.jms.MessageConsumer ; 26 import javax.jms.MessageProducer ; 27 import javax.jms.Session ; 28 29 33 public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport { 34 35 private Connection connection; 36 37 public void testVirtualTopicCreation() throws Exception { 38 if (connection == null) { 39 connection = createConnection(); 40 } 41 connection.start(); 42 43 ConsumerBean messageList = new ConsumerBean(); 44 messageList.setVerbose(true); 45 46 String queueAName = getVirtualTopicConsumerName(); 47 ActiveMQQueue queue1 = new ActiveMQQueue(queueAName); 49 ActiveMQQueue queue2 = new ActiveMQQueue(queueAName); 50 51 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 52 MessageConsumer c1 = session.createConsumer(queue1); 53 MessageConsumer c2 = session.createConsumer(queue2); 54 55 c1.setMessageListener(messageList); 56 c2.setMessageListener(messageList); 57 58 MessageProducer producer = session.createProducer(new ActiveMQTopic(getVirtualTopicName())); 60 assertNotNull(producer); 61 62 int total = 10; 63 for (int i = 0; i < total; i++) { 64 producer.send(session.createTextMessage("message: " + i)); 65 } 66 67 messageList.assertMessagesArrived(total); 68 } 69 70 71 protected String getVirtualTopicName() { 72 return "VirtualTopic.TEST"; 73 } 74 75 76 protected String getVirtualTopicConsumerName() { 77 return "Consumer.A.VirtualTopic.TEST"; 78 } 79 80 81 protected void tearDown() throws Exception { 82 if (connection != null) { 83 connection.close(); 84 } 85 super.tearDown(); 86 } 87 } 88 | Popular Tags |