I had this same problem since 4.1.0-incubator. Learned to make killing off the dead consumers in jconsole as part of my morning routine. Glad you put a test case. I hope this will get fixed. I took your post and setup an Issue: AMQ-1850.
Ossory wrote: > > Hi, > I have an issue where a JMS client attempts to receive messages from a > queue. The client fails due to a JVM crash and the JMS connection is not > closed. This leaves a consumer behind (that I can see in the ActiveMQ > admin console). If I restart the JMS client it fails to receive all of the > new messages that sent to the queue in question. > Using JMX to stop the open connections or closing ActiveMQ allows the > client to work again. > Is there a timeout value that you can apply to connections to avoid having > to do this? > Any help would be appreciated. > > I've created an artificial test case based on the behaviour I have seen in > ActiveMQ 5.1 on Windows XP. > The method jmsTest2 deliberately fails to close the connection. > > static final String PROVIDER_URL = "tcp://localhost:61616"; > static final String QUEUE = "queueA"; > > static void jmsTest() throws JMSException, NamingException { > Properties props = new Properties(); > props.setProperty(Context.INITIAL_CONTEXT_FACTORY, > "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); > props.setProperty(Context.PROVIDER_URL, PROVIDER_URL); > InitialContext ctx = new InitialContext(props); > QueueConnectionFactory cf = > (QueueConnectionFactory)ctx.lookup("ConnectionFactory"); > QueueConnection conn = cf.createQueueConnection(); > conn.start(); //this is required if you want to receive messages > using this connection > QueueSession sess = conn.createQueueSession(false, > Session.AUTO_ACKNOWLEDGE); > Queue qa = sess.createQueue(QUEUE); > QueueSender sender = sess.createSender(qa); > for(int i = 0; i < 10; i++) { > Message msg = sess.createTextMessage("test"); > sender.send(msg); > } > sender.close(); > sess.close(); > conn.close(); > } > > static void jmsTest2() throws JMSException, NamingException { > Properties props = new Properties(); > props.setProperty(Context.INITIAL_CONTEXT_FACTORY, > "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); > props.setProperty(Context.PROVIDER_URL, PROVIDER_URL); > InitialContext ctx = new InitialContext(props); > QueueConnectionFactory cf = > (QueueConnectionFactory)ctx.lookup("ConnectionFactory"); > QueueConnection conn = cf.createQueueConnection(); > conn.start(); //this is required if you want to receive messages > using this connection > QueueSession sess = conn.createQueueSession(false, > Session.AUTO_ACKNOWLEDGE); > Queue qa = sess.createQueue(QUEUE); > QueueReceiver qr = sess.createReceiver(qa); > for(int i = 0; i < 10; i++) { > Message msgin = qr.receive(5000); > System.out.println("msgin" + i + " = " + msgin); > } > //qr.close(); > //sess.close(); > //conn.stop(); > //conn.close(); > } > > public static void main(String[] args) > { > jmsTest(); > jmsTest2(); > jmsTest(); > jmsTest2(); > } > > The first call to jmsTest2 prints 10 messages but the second call fails to > read any messages. The JVM will not stop after the main method completes > because some ActiveMQ threads remain open. > -- View this message in context: http://www.nabble.com/failing-to-close-a-connection-leaves-consumers-behind-that-prevent-new-consumers-receiving-messages-tp18265444p18372602.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.