This document describes the feature, use cases, and usage of delayed message in TDMQ for RabbitMQ.
Delayed message: After a message is sent to the server, the business may want the consumer to receive it after a period of time rather than immediately. This type of message is called "delayed message".
The delayed message feature in TDMQ for RabbitMQ can be used in the same way as the delayed message plugin of RabbitMQ, so you don't need to modify your business when migrating it.
Map<String, Object> args = new HashMap<String, Object>(); args.put("x-delayed-type", "direct"); channel.exchangeDeclare("ExchangeName", "x-delayed-message", true, false, args);
The parameters are described as follows:
|x-delayed-type||Exchange type, which specifies the routing rule. Valid values:
|ExchangeName||Exchange name, which can be obtained from the exchange list in the console.|
|x-delayed-message||Specified exchange type for delayed message delivery.|
Headerattribute of the message and specify the target exchange as the one declared in the previous step.
byte messageBodyBytes = "delayed payload".getBytes("UTF-8"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("x-delay", 4000); AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder().headers(headers); channel.basicPublish("ExchangeName", "", props.build(), messageBodyBytes);
After the message arrives at the exchange, it will be delivered to the corresponding queue in 4,000 milliseconds.