forked from chengxy-nds/Springboot-Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeadLetterSendMessage.java
More file actions
29 lines (23 loc) · 889 Bytes
/
DeadLetterSendMessage.java
File metadata and controls
29 lines (23 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.chengxy.delayqueue.deadLetterQueue;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Author: xiaofu
* @Description:
*/
@Component
public class DeadLetterSendMessage {
@Resource
private AmqpTemplate amqpTemplate;
public void send(String delayTimes) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
amqpTemplate.convertAndSend(RabbitConstant.IOT_VIRTUAL_DEVICE_DELAY_EXCHANGE,RabbitConstant.IOT_VIRTUAL_DEVICE_DELAY_QUEUE, "大家好我是延迟数据" + delayTimes, message -> {
message.getMessageProperties().setExpiration(delayTimes);
System.out.println(sdf.format(new Date()) + " Delay sent.");
return message;
});
}
}