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

0

6

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.

Tushy answered 24/8, 2013 at 8:23 Comment(1)
I have exactly the same issue. How did you solve it?Institutional

© 2022 - 2024 — McMap. All rights reserved.