Message queue architecture (client to web server to worker and back)

Viewed 10531

I have a web server written in Node JS running on Heroku. The server has a web server process and a worker process. The web server successfully sends messages to the worker via a RabbitMQ queue; the worker successfully returns the processed data to the web server. I use a randomly generated Uuid to track the messages and ensure the right message is paired up with the right original message.

In a separate project, I have the client (website) successfully communicating with the web server. Now, I need to put the two together.

How can I make it so:

  1. Client sends a HTTP POST.
  2. Web server receives the request and passes the request into the message queue.
  3. Worker processes the request and returns to the web server.
  4. Web server returns the correct data to the client so the client can associate the response with the original request.

Step 4 is where I'm stuck. I think I read somewhere that the client should continuously poll (HTTP POSTs?) the web server until it's data is ready. I think I need to respond to the client after step 1 so the request doesn't time out. Any ideas/advice appreciated!

Block diagram: enter image description here

2 Answers

Look at this article though it uses activeMQ and not rabbitMQ but it says here that you set each reach request with a correlation id that you can use to map the response to it a corresponding id, that way you can easily reply to your web client with the correct response for the correct request.

Related