Can I store time in RabbitMQ for call handler in this time? Does RabbitMQ support this?
Asked
Active
Viewed 227 times
1 Answers
1
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.

Alex Kapustin
- 1,869
- 12
- 15
-
Maybe you can recommend me another alternative mechanism in Python? When user can put event(date) in queue for further execution? – Oleg Nov 25 '17 at 23:35
-
How to get date from storage and put this to Countdown EAT? Need I ping database every time none stop? – Oleg Nov 25 '17 at 23:50
-
This way that you suggested does not support delay time in datetime format, just milliseconds – Oleg Nov 25 '17 at 23:54
-
What the problem to convert ? Of course if time for execution is not months ... What is the task you are trying to resolve ? Probably it will be enought for you to use database and cron for every 1 (or 5 minutes) to check whether event happened. – Alex Kapustin Nov 26 '17 at 02:12
-
I must caution that, while RabbitMQ may support it, this is definitely non-standard architecture. The purpose of a queue is to match varying workloads with relatively constant processing capacity. Things like delays, etc. only frustrate the purpose of a message queue. If there is a delay necessary, it is best to implement that in your application logic. – theMayer Nov 27 '17 at 22:45