1 18 package org.apache.activemq; 19 20 import javax.jms.Connection ; 21 import javax.jms.Message ; 22 import javax.jms.MessageConsumer ; 23 import javax.jms.MessageListener ; 24 import javax.jms.MessageProducer ; 25 import javax.jms.Queue ; 26 import javax.jms.Session ; 27 28 31 public class JmsAutoAckListenerTest extends TestSupport implements MessageListener { 32 33 private Connection connection; 34 35 protected void setUp() throws Exception { 36 super.setUp(); 37 connection = createConnection(); 38 } 39 40 43 protected void tearDown() throws Exception { 44 if (connection != null) { 45 connection.close(); 46 connection = null; 47 } 48 super.tearDown(); 49 } 50 51 56 public void testAckedMessageAreConsumed() throws Exception { 57 connection.start(); 58 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 59 Queue queue = session.createQueue("test"); 60 MessageProducer producer = session.createProducer(queue); 61 producer.send(session.createTextMessage("Hello")); 62 63 MessageConsumer consumer = session.createConsumer(queue); 65 consumer.setMessageListener(this); 66 67 Thread.sleep(10000); 68 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 69 consumer = session.createConsumer(queue); 71 Message msg = consumer.receive(1000); 72 assertNull(msg); 73 74 75 session.close(); 76 } 77 78 79 public void onMessage(Message message){ 80 assertNotNull(message); 81 82 83 } 84 } 85 | Popular Tags |