activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmadden <madden....@gmail.com>
Subject Consumer pool shutdown with acknowledgments
Date Tue, 12 Jul 2011 17:08:30 GMT
Hello, I am having a problem successfully shutting down a consumer pool where
there is one outstanding job in the pool.  The shutdown sequence will wait
for the job to finish, but the acknowledgement never makes it back to the
queue and thus the queue count is out of whack, here is my code (I am suing
CLIENT_ACKNOWLEDGE btw):

Code to stop the pool:

	public void stop() {
		logger.info("Shutting down TwitterConsumerPool.");
		try {
			for (MessageConsumer consumer : consumers) {
				logger.info("Closing consumer: " + consumer.toString());
				consumer.close();
				logger.info("Closed consumer: " + consumer.toString());
			}
			for (Session session : sessions) {
				if (session.getTransacted()) { session.commit(); }
				session.close();
				logger.info("Closed session: " + session.toString());
			}

			conn.stop();
			logger.info("Stopped connection: " + conn.toString());
			conn.close();
			logger.info("Closed connection: " + conn.toString());
		} catch (JMSException e) {
			logger.error("Failed to stop Twitter Consumer Pool {}", e);
		}
	}

Listener code to sent acknowledgement:

        logger.info("Received message from activemq server: " + text);
	pojo = gson.fromJson(text, TwitterPojo.class);
        logger.info("Sleeping for 20 seconds.");
	Thread.sleep(10000);
	service.submit(pojo); 
	logger.info("Executed " + service.getName() + " successfully with input: "
+ pojo.asJson()); 
		
	try {
		synchronized (msg) {
		    // Must call acknowledge on Message object specifically.
	            msg.acknowledge();
		    logger.info("Sent acknowledgement to ActiveMQ: " + msg.toString());
	        } 
        }catch (Exception e) {
		logger.error(e.toString());
	}

--
View this message in context: http://activemq.2283324.n4.nabble.com/Consumer-pool-shutdown-with-acknowledgments-tp3662897p3662897.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message