How to properly implement RabbitMQ RPC from Java servlet web container?

随声附和 提交于 2019-12-21 16:52:38

问题


I'd like for incoming Java servlet web requests to invoke RabbitMQ using the RPC approach as described here.

However, I'm not sure how to properly reuse callback queues between requests, as per the RabbitMQ tutorial linked above creating a new callback queue per every request is inefficient (RabbitMQ may not cope even if using the Queue TTL feature).

There would generally be only 1-2 RPC calls per every servlet request, but obviously a lot of servlet requests per second.

I don't think I can share the callback queues between threads, so I'd want at least one per each web worker thread.

My first idea was to store the callback queue in a ThreadLocal, but that can lead to memory leaks.

My second idea was to store them in a session, but I am not sure they will serialize properly and my sessions are currently not replicated/shared between web servers, so it is IMHO not a good solution.

My infrastructure is Tomcat / Guice / Stripes Framework.

Any ideas what the most robust/simple solution is?

Am I missing something in this whole approach, and thus over-complicating things?

Note 1- This question relates to the overall business case described here - see option 1.

Note 2 - There is a seemingly related question How to setup RabbitMQ RPC in a web context, but it is mostly concerned with proper shutdown of threads created by the RabbitMQ client.

来源:https://stackoverflow.com/questions/18416525/how-to-properly-implement-rabbitmq-rpc-from-java-servlet-web-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!