Rahul Malu
Rahul Malu

Reputation: 566

RabbitMQ scheduled message and revoke feature

Is it possible to schedule a message using RabbitMQ and also remove the message (which is scheduled to be processed) when certain conditions are met? We have a requirement where we need to call a external service to get some data. The call is asynchronous. The client calls the API endpoint of the server mentioning the data that it needs. The server just responds back with a acknowledgement that it has received the request from client. Internally the server also starts processing the client request and it will call the client API endpoint with the actual response to the query it received sometime back from the client.

There is a time limit (30sec) till the client needs to wait to get the response from the server. If the client receives response within 30sec then it will proceed with the execution. Even if the client does not receives response from the server in 30sec, it will proceed with other steps.

There are thousands of independent transactions (request and response) happening each second between the client and server. How can the client keep a track of the requests and and response received in the most effective way using RabbitMQ. Can the RabbitMQ plugin rabbitmq_delayed_message_exchange used for this scenario in which the client will push new messages in a queue along with x-delay header (30sec)? How can the scheduled message be removed from the queue in case the client receives the response from server before 30sec?

Upvotes: 0

Views: 184

Answers (1)

José M
José M

Reputation: 3509

I'd do the following:

  1. Make the response go through RabbitMQ too (using RPC)
  2. Make sure that the name of the response queue is also sent as a parameter that is used to route it by some exchange policy (routing key or use header exchange)
  3. Set up a DLX exchange with the correct policy for 2.
  4. Set a 30s TTL in the client->server queue

How'd this work in the usual case?

  1. Client creates the reply-to queue
  2. Client sends the request to the server
  3. Client consumes from the reply-to queue
  4. Server consumes the message and posts the response to the reply-to queue

What'd happen with a timeout?

  1. Client creates the reply-to queue
  2. Client sends the request to the server
  3. Client consumes from the reply-to queue
  4. Request message TTL triggers
  5. RMQ deadletters the request message to the reply-to queue
  6. Client receives its own request instead of the response

Upvotes: 1

Related Questions