How to retract a message in RabbitMQ?

后端 未结 4 1332
旧巷少年郎
旧巷少年郎 2021-02-04 05:26

I\'ve got something like a job queue over RabbitMQ and, upon a request to cancel a job, I\'d like to retract the tasks that have not yet started processing (their messages have

4条回答
  •  猫巷女王i
    2021-02-04 06:08

    I would solve this scenario by having the worker check some sort of authoritative data source to determine if the the job should proceed or not. For example, the worker would check the job's status in a database to see if the job was canceled already.

    For scenarios where the speed of processing jobs may be faster than the speed with which the authoritative store can be updated and read, a less guaranteed data store that trades speed for other characteristics may be useful.

    An example of this would be to use Redis as the store for canceling processing of a message instead of a relational DB like MySQL. Redis is very fast, but makes fewer guarantees regarding the data it holds, whereas MySQL is much slower, but offers more guarantees about the data it holds.

    In the end, the concept of checking with another source for whether or not to process a message is the same, but the way you implement that depends on your particular scenario.

提交回复
热议问题