1 18 package org.apache.activemq; 19 20 import javax.jms.Connection ; 21 import javax.jms.JMSException ; 22 import javax.jms.Message ; 23 import javax.jms.MessageConsumer ; 24 import javax.jms.MessageProducer ; 25 import javax.jms.Queue ; 26 import javax.jms.Session ; 27 28 31 public class JmsAutoAckTest extends TestSupport { 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 JMSException { 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 Message msg = consumer.receive(1000); 66 assertNotNull(msg); 67 68 session.close(); 70 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 71 72 consumer = session.createConsumer(queue); 74 msg = consumer.receive(1000); 75 assertNull(msg); 76 77 session.close(); 78 } 79 80 81 } 82 | Popular Tags |