提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.websocket.core.sender.redis; |
H |
2 |
|
|
3 |
import com.iailab.framework.mq.redis.core.RedisMQTemplate; |
|
4 |
import com.iailab.framework.websocket.core.sender.AbstractWebSocketMessageSender; |
|
5 |
import com.iailab.framework.websocket.core.sender.WebSocketMessageSender; |
|
6 |
import com.iailab.framework.websocket.core.session.WebSocketSessionManager; |
|
7 |
import lombok.extern.slf4j.Slf4j; |
|
8 |
|
|
9 |
/** |
|
10 |
* 基于 Redis 的 {@link WebSocketMessageSender} 实现类 |
|
11 |
* |
|
12 |
* @author iailab |
|
13 |
*/ |
|
14 |
@Slf4j |
|
15 |
public class RedisWebSocketMessageSender extends AbstractWebSocketMessageSender { |
|
16 |
|
|
17 |
private final RedisMQTemplate redisMQTemplate; |
|
18 |
|
|
19 |
public RedisWebSocketMessageSender(WebSocketSessionManager sessionManager, |
|
20 |
RedisMQTemplate redisMQTemplate) { |
|
21 |
super(sessionManager); |
|
22 |
this.redisMQTemplate = redisMQTemplate; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void send(Integer userType, Long userId, String messageType, String messageContent) { |
|
27 |
sendRedisMessage(null, userId, userType, messageType, messageContent); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public void send(Integer userType, String messageType, String messageContent) { |
|
32 |
sendRedisMessage(null, null, userType, messageType, messageContent); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void send(String sessionId, String messageType, String messageContent) { |
|
37 |
sendRedisMessage(sessionId, null, null, messageType, messageContent); |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* 通过 Redis 广播消息 |
|
42 |
* |
|
43 |
* @param sessionId Session 编号 |
|
44 |
* @param userId 用户编号 |
|
45 |
* @param userType 用户类型 |
|
46 |
* @param messageType 消息类型 |
|
47 |
* @param messageContent 消息内容 |
|
48 |
*/ |
|
49 |
private void sendRedisMessage(String sessionId, Long userId, Integer userType, |
|
50 |
String messageType, String messageContent) { |
|
51 |
RedisWebSocketMessage mqMessage = new RedisWebSocketMessage() |
|
52 |
.setSessionId(sessionId).setUserId(userId).setUserType(userType) |
|
53 |
.setMessageType(messageType).setMessageContent(messageContent); |
|
54 |
redisMQTemplate.send(mqMessage); |
|
55 |
} |
|
56 |
|
|
57 |
} |