Search code examples
rabbitmqrabbitmqctl

Does RabbitMQ support execution of process from queue by time?


Can I store time in RabbitMQ for call handler in this time? Does RabbitMQ support this?


Solution

  • Yes, it's supported, but only via extra plugin.

    There is more dateiled about that

    Simply saying you need to install rabbitmq-plugins enable rabbitmq_delayed_message_exchange plugin, and add new header to your message:

    byte[] messageBodyBytes = "delayed payload".getBytes();
    AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder();
    headers = new HashMap<String, Object>();
    headers.put("x-delay", 5000);
    props.headers(headers);
    channel.basicPublish("my-exchange", "", props.build(), messageBodyBytes);
    

    So you need to put x-delay value with milliseconds after this message should be processed.