RabbitMQ RPC in Tomcat container

452 views
Skip to first unread message

steven....@i-develop.be

unread,
Jul 24, 2013, 11:08:32 AM7/24/13
to rabbitmq...@googlegroups.com
I'm trying to setup RabbitMQ RPC in a web project (like suggested in tutorial 6). It works as intended, but when I try to shutdown Tomcat, the shutdown hangs as soon as I have created a consumer listening to the rpc response. 

jstack and some debugging learned me that for each created consumer, a thread is created. And those threads are preventing Tomcat from shutting down (as they are not managed by Tomcat).

Looking at ConsumerWorkService, there is a method addWork, which creates a new WorkPoolRunnable and if I have understood it correctly, those Runnable's are only stopped when the 'key', being the channel is stopped.

I find that a bit odd.. I would expect that when I call stub.channel.basicCancel(consumer.getConsumerTag()); the runnable for the consumer is removed. 

Or am I completely wrong about my findings and is something else going on?

steven....@i-develop.be

unread,
Jul 25, 2013, 7:30:51 PM7/25/13
to rabbitmq...@googlegroups.com, Discussions about RabbitMQ
Managed to get it working:

* passed in my own ExecutorService when creating the connection and stored it in the ServletContextListener
* Used Executors.newCachedThreadPool(); -> not necessary, but is good as many short executions, and unused threads die after 60s idle time
* Shutdown threads in ServletContextListener.destroyed(). First thought this didn't work as my breakpoint was not reached, but somehow, breakpoint just seem not to work there (could make sense when I think about it, I'm stopping the process so debugger might already be detached). But logging assures me now my code is executed.
ServletContextListener.destroyed() {
            executorService.shutdown();
            executorService.awaitTermination(20, TimeUnit.SECONDS);
}

And that's it :)

Op woensdag 24 juli 2013 17:08:32 UTC+2 schreef steven....@i-develop.be het volgende:
Reply all
Reply to author
Forward
0 new messages