mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:集群推送优化
This commit is contained in:
@@ -7,6 +7,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description: 推送给用户的消息对象
|
||||
@@ -24,7 +26,7 @@ public class PushMessageDTO implements Serializable {
|
||||
/**
|
||||
* 推送的uid
|
||||
*/
|
||||
private Long uid;
|
||||
private List<Long> uidList;
|
||||
|
||||
/**
|
||||
* 推送类型 1个人 2全员
|
||||
@@ -34,7 +36,13 @@ public class PushMessageDTO implements Serializable {
|
||||
private Integer pushType;
|
||||
|
||||
public PushMessageDTO(Long uid, WSBaseResp<?> wsBaseMsg) {
|
||||
this.uid = uid;
|
||||
this.uidList = Collections.singletonList(uid);
|
||||
this.wsBaseMsg = wsBaseMsg;
|
||||
this.pushType = WSPushTypeEnum.USER.getType();
|
||||
}
|
||||
|
||||
public PushMessageDTO(List<Long> uidList, WSBaseResp<?> wsBaseMsg) {
|
||||
this.uidList = uidList;
|
||||
this.wsBaseMsg = wsBaseMsg;
|
||||
this.pushType = WSPushTypeEnum.USER.getType();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ public class PushConsumer implements RocketMQListener<PushMessageDTO> {
|
||||
WSPushTypeEnum wsPushTypeEnum = WSPushTypeEnum.of(message.getPushType());
|
||||
switch (wsPushTypeEnum) {
|
||||
case USER:
|
||||
webSocketService.sendToUid(message.getWsBaseMsg(), message.getUid());
|
||||
message.getUidList().forEach(uid -> {
|
||||
webSocketService.sendToUid(message.getWsBaseMsg(), uid);
|
||||
});
|
||||
break;
|
||||
case ALL:
|
||||
webSocketService.sendToAllOnline(message.getWsBaseMsg(), null);
|
||||
|
||||
@@ -20,9 +20,7 @@ public class PushService {
|
||||
private MQProducer mqProducer;
|
||||
|
||||
public void sendPushMsg(WSBaseResp<?> msg, List<Long> uidList) {
|
||||
uidList.parallelStream().forEach(uid -> {
|
||||
mqProducer.sendMsg(MQConstant.PUSH_TOPIC, new PushMessageDTO(uid, msg));
|
||||
});
|
||||
mqProducer.sendMsg(MQConstant.PUSH_TOPIC, new PushMessageDTO(uidList, msg));
|
||||
}
|
||||
|
||||
public void sendPushMsg(WSBaseResp<?> msg, Long uid) {
|
||||
|
||||
@@ -11,7 +11,7 @@ mybatis-plus:
|
||||
spring:
|
||||
profiles:
|
||||
#运行的环境
|
||||
active: my-prod
|
||||
active: my-test
|
||||
application:
|
||||
name: mallchat
|
||||
datasource:
|
||||
|
||||
Reference in New Issue
Block a user