yutool-mq-core
消息组件核心类库,制定了消息发送和接收的标准接口。
消息发送接口
java
public interface Sender<M extends Serializable> {
/**
* 立刻发送消息
* @param message 消息体
*/
void sendMessage(M message);
/**
* 发送消息
* @param message 消息体
* @param sendAt 发送时间
*/
default void sendMessage(M message, LocalDateTime sendAt) {
sendMessage(message, ChronoUnit.MILLIS.between(LocalDateTime.now(), sendAt));
}
/**
* 延迟发送消息
* @param message 消息体
* @param delayMillis 延迟毫秒数
*/
default void sendMessage(M message, long delayMillis) {
sendMessage(message, Duration.ofMillis(delayMillis));
}
/**
* 延迟发送消息
* @param message 消息体
* @param delayDuration 延迟时长
*/
void sendMessage(M message, Duration delayDuration);
/**
* 设置上下文配置
* @param key 配置Key
* @param value 配置Value
*/
default void setMqProp(String key, Object value) {
MqContext.putMqProp(key, value);
}
/**
* 获取上下文配置
* @param key 配置Key
* @return 配置Value
*/
default Object getMqProp(String key) {
return MqContext.getMqProp(key);
}
}
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
使用MqContext消息上下文对象,可在发送消息时获取上下文信息,适配不同的场景。
消息接收接口
java
public interface Receiver<M> {
/**
* 接收并处理消息
* @param message 消息体
*/
default void handle(M message) {
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
评论区留言准则:
1. 本评论区禁止传播封建迷信、吸烟酗酒、低俗色情、赌博诈骗等任何违法违规内容。
2. 当他人以不正当方式诱导打赏、私下交易,请谨慎判断,以防人身财产损失。
3. 请勿轻信各类招聘征婚、代练代抽、私下交易、购买礼包码、游戏币等广告信息,谨防网络诈骗。