Delayed message in RabbitMQ

后端 未结 8 1246
别跟我提以往
别跟我提以往 2020-12-08 02:31

Is it possible to send message via RabbitMQ with some delay? For example I want to expire client session after 30 minutes, and I send a message which will be processed after

8条回答
  •  -上瘾入骨i
    2020-12-08 02:53

    AMQP protocol does not support delayed messaging, but by using Time-To-Live and Expiration and Dead Letter Exchanges extensions delayed messaging is possible. The solution is described in this link. I copied the following steps from that link:

    Step by step:

    Declare the delayed queue
        Add the x-dead-letter-exchange argument property, and set it to the default exchange "".
        Add the x-dead-letter-routing-key argument property, and set it to the name of the destination queue.
        Add the x-message-ttl argument property, and set it to the number of milliseconds you want to delay the message.
    Subscribe to the destination queue
    

    There is also a plugin for delayed messaging in RabbitMQ repository on GitHub.

    Note that there is a solution called Celery which supports delayed task queuing on RabbitMQ broker by presenting a calling API called apply_async(). Celery supports Python, node and PHP.

提交回复
热议问题