提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.websocket.core.sender.rocketmq; |
H |
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.apache.rocketmq.spring.annotation.MessageModel; |
|
5 |
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
|
6 |
import org.apache.rocketmq.spring.core.RocketMQListener; |
|
7 |
|
|
8 |
/** |
|
9 |
* {@link RocketMQWebSocketMessage} 广播消息的消费者,真正把消息发送出去 |
|
10 |
* |
|
11 |
* @author iailab |
|
12 |
*/ |
|
13 |
@RocketMQMessageListener( // 重点:添加 @RocketMQMessageListener 注解,声明消费的 topic |
|
14 |
topic = "${iailab.websocket.sender-rocketmq.topic}", |
|
15 |
consumerGroup = "${iailab.websocket.sender-rocketmq.consumer-group}", |
|
16 |
messageModel = MessageModel.BROADCASTING // 设置为广播模式,保证每个实例都能收到消息 |
|
17 |
) |
|
18 |
@RequiredArgsConstructor |
|
19 |
public class RocketMQWebSocketMessageConsumer implements RocketMQListener<RocketMQWebSocketMessage> { |
|
20 |
|
|
21 |
private final RocketMQWebSocketMessageSender rocketMQWebSocketMessageSender; |
|
22 |
|
|
23 |
@Override |
|
24 |
public void onMessage(RocketMQWebSocketMessage message) { |
|
25 |
rocketMQWebSocketMessageSender.send(message.getSessionId(), |
|
26 |
message.getUserType(), message.getUserId(), |
|
27 |
message.getMessageType(), message.getMessageContent()); |
|
28 |
} |
|
29 |
|
|
30 |
} |