0
votes

I'm writing a service on NodeJS that processes CPU-bound tasks. The main idea is pretty simple:

  1. Client (browser) sends request
  2. Webserver (NodeJS + ExpressJS) handles request: generates ID, adds a task to RabbitMQ with that ID and replies to client with that ID.
  3. Also webserver adds the task to Redis server with ID as a key and {status: active} as a value
  4. Consumer processes a task in about a minute and updates redis entry with the derived result.
  5. Client uses this ID to check the status of the corresponding task.

The question: I wish consumer to stop processing the task in the step 4 if client has stopped asking server that the task is still running. How can I do that with RabbitMQ?

P.S.: I've tried to purge the queue but faced with some problems: the queue is not purged if the message was not acknowledged by consumer. As sad here, this will happen only after my CPU-bound task is finished.

1

1 Answers

0
votes

I've figured out my problem of purging consumer, but without using RabbitMQ, because didn't found any API for that.

As mentioned in this answer on SO, I can check in another DB if the consumer should proceed or not. So I've decided to use redis also for this purpose: inside working thread I check an according entry in redis if the key has not expired yet.

Hope this would be helpful for somebody else.