fix:集群推送优化

This commit is contained in:
zhongzb
2023-10-02 15:28:46 +08:00
parent 0a3b503990
commit e891167b6b
4 changed files with 15 additions and 7 deletions

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -11,7 +11,7 @@ mybatis-plus:
spring:
profiles:
#运行的环境
active: my-prod
active: my-test
application:
name: mallchat
datasource: