
At https://www.rabbitmq.com/community-plugins.html, select rabbitmq-delayed-message-exchange and download the rabbitmq-delayed-message-exchange-<version>.ez file. Place the rabbitmq-delayed-message-exchange-<version>.ez file in the /usr/lib/rabbitmq/plugins directory.
Ensure the file is owned by the rabbitmq users and rabbitmq group.
chown rabbitmq /usr/lib/rabbitmq/plugins/rabbitmq_delayed_message_exchange-*.ez
chgrp rabbitmq /usr/lib/rabbitmq/plugins/rabbitmq_delayed_message_exchange-*.ez
Use the rabbitmq-plugins enable command to enable the plugin. There is no need to restart the RabbitMQ service.
rabbitmq-plugins enable rabbitmq_delayed-message-exchange
The rabbitmq-plugins list command should now show that the rabbitmq-delayed-message-exchange plugin is enabled.
~]# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@DLAMQPS002
|/
[ ] rabbitmq_amqp1_0 3.8.16
[ ] rabbitmq_auth_backend_cache 3.8.16
[ ] rabbitmq_auth_backend_http 3.8.16
[E*] rabbitmq_auth_backend_ldap 3.8.16
[ ] rabbitmq_auth_backend_oauth2 3.8.16
[ ] rabbitmq_auth_mechanism_ssl 3.8.16
[ ] rabbitmq_consistent_hash_exchange 3.8.16
[E*] rabbitmq_delayed_message_exchange 3.8.0
[ ] rabbitmq_event_exchange 3.8.16
[ ] rabbitmq_federation 3.8.16
[ ] rabbitmq_federation_management 3.8.16
[ ] rabbitmq_jms_topic_exchange 3.8.16
[E*] rabbitmq_management 3.8.16
[e*] rabbitmq_management_agent 3.8.16
[E*] rabbitmq_message_timestamp 3.8.0
[ ] rabbitmq_mqtt 3.8.16
[ ] rabbitmq_peer_discovery_aws 3.8.16
[ ] rabbitmq_peer_discovery_common 3.8.16
[ ] rabbitmq_peer_discovery_consul 3.8.16
[ ] rabbitmq_peer_discovery_etcd 3.8.16
[ ] rabbitmq_peer_discovery_k8s 3.8.16
[E*] rabbitmq_prometheus 3.8.16
[ ] rabbitmq_random_exchange 3.8.16
[ ] rabbitmq_recent_history_exchange 3.8.16
[ ] rabbitmq_sharding 3.8.16
[E*] rabbitmq_shovel 3.8.16
[E*] rabbitmq_shovel_management 3.8.16
[ ] rabbitmq_stomp 3.8.16
[ ] rabbitmq_top 3.8.16
[ ] rabbitmq_tracing 3.8.16
[ ] rabbitmq_trust_store 3.8.16
[e*] rabbitmq_web_dispatch 3.8.16
[ ] rabbitmq_web_mqtt 3.8.16
[ ] rabbitmq_web_mqtt_examples 3.8.16
[ ] rabbitmq_web_stomp 3.8.16
[ ] rabbitmq_web_stomp_examples 3.8.16
Now when creating an exchange, you can set the type to x-delayed-message with the x-delayed-type argument which would contain a value such as direct or topic of fanout.
Let's say you have a Java app that is the producer putting messages onto an exchange. The producer can define the x-delay header, such as 10000 milliseconds in this example.
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("x-delay", 10000);
channel.basicPublish(exchange, routingkey, mandatory, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
Did you find this article helpful?
If so, consider buying me a coffee over at