diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java index 06eeb90..cacf23a 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java @@ -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 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 uidList, WSBaseResp wsBaseMsg) { + this.uidList = uidList; this.wsBaseMsg = wsBaseMsg; this.pushType = WSPushTypeEnum.USER.getType(); } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java index cff6fb5..e99ff20 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java @@ -26,7 +26,9 @@ public class PushConsumer implements RocketMQListener { 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); diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java index 0eed34e..896b4e0 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java @@ -20,9 +20,7 @@ public class PushService { private MQProducer mqProducer; public void sendPushMsg(WSBaseResp msg, List 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) { diff --git a/mallchat-chat-server/src/main/resources/application.yml b/mallchat-chat-server/src/main/resources/application.yml index ee78bd5..88a3e29 100644 --- a/mallchat-chat-server/src/main/resources/application.yml +++ b/mallchat-chat-server/src/main/resources/application.yml @@ -11,7 +11,7 @@ mybatis-plus: spring: profiles: #运行的环境 - active: my-prod + active: my-test application: name: mallchat datasource: