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