🎨 拆分 admin-websocket 模块,方便用户剔除不需要的组件
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.hccake.ballcat.admin.websocket;
|
||||
|
||||
import com.hccake.ballcat.admin.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.admin.websocket.distribute.RedisMessageDistributor;
|
||||
import com.hccake.ballcat.admin.websocket.distribute.RedisWebsocketMessageListener;
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.common.websocket.distribute.RedisMessageDistributor;
|
||||
import com.hccake.ballcat.common.websocket.distribute.RedisWebsocketMessageListener;
|
||||
import com.hccake.ballcat.admin.websocket.user.UserAttributeHandshakeInterceptor;
|
||||
import com.hccake.ballcat.admin.websocket.user.UserSessionKeyGenerator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.listener.PatternTopic;
|
||||
@@ -20,9 +21,10 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
* @author Hccake 2021/1/5
|
||||
* @version 1.0
|
||||
*/
|
||||
@Import({ SystemWebsocketEventListenerConfiguration.class, NotifyWebsocketEventListenerConfiguration.class })
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class AdminWebSocketConfiguration {
|
||||
public class AdminWebSocketAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(UserAttributeHandshakeInterceptor.class)
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hccake.ballcat.admin.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.notify.service.UserAnnouncementService;
|
||||
import com.hccake.ballcat.notify.websocket.NotifyWebsocketEventListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnClass({ NotifyWebsocketEventListener.class, UserAnnouncementService.class })
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class NotifyWebsocketEventListenerConfiguration {
|
||||
|
||||
private final MessageDistributor messageDistributor;
|
||||
|
||||
@Bean
|
||||
public NotifyWebsocketEventListener notifyWebsocketEventListener(UserAnnouncementService userAnnouncementService) {
|
||||
return new NotifyWebsocketEventListener(userAnnouncementService, messageDistributor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.hccake.ballcat.admin.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.system.websoket.SystemWebsocketEventListener;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnClass(SystemWebsocketEventListener.class)
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class SystemWebsocketEventListenerConfiguration {
|
||||
|
||||
private final MessageDistributor messageDistributor;
|
||||
|
||||
@Bean
|
||||
public SystemWebsocketEventListener systemWebsocketEventListener() {
|
||||
return new SystemWebsocketEventListener(messageDistributor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.hccake.ballcat.admin.websocket.constant;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lingting 2021/3/25 17:25
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MessageTypeConstants {
|
||||
|
||||
public static final String LOV_CHANGE = "lov_change";
|
||||
|
||||
}
|
||||
34
ballcat-common/ballcat-common-websocket/pom.xml
Normal file
34
ballcat-common/ballcat-common-websocket/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ballcat-common</artifactId>
|
||||
<groupId>com.hccake</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ballcat-common-websocket</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<!-- slf4j日志 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
/**
|
||||
* 本地消息分发,直接进行发送
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Hccake 2021/1/12
|
||||
* @version 1.0
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
/**
|
||||
* 消息分发器
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.hccake.ballcat.common.websocket.WebSocketMessageSender;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.common.websocket.distribute;
|
||||
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hccake.ballcat.common.websocket.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.json.JsonReadFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -18,6 +18,7 @@
|
||||
<module>ballcat-common-desensitize</module>
|
||||
<module>ballcat-common-util</module>
|
||||
<module>ballcat-common-model</module>
|
||||
<module>ballcat-common-websocket</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
@@ -139,6 +139,11 @@
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-websocket</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- ballcat-stater -->
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package com.hccake.ballcat.admin.websocket.distribute;
|
||||
package com.hccake.ballcat.notify.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDO;
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.notify.event.AnnouncementCloseEvent;
|
||||
import com.hccake.ballcat.notify.event.StationNotifyPushEvent;
|
||||
import com.hccake.ballcat.notify.model.domain.AnnouncementNotifyInfo;
|
||||
import com.hccake.ballcat.notify.model.domain.NotifyInfo;
|
||||
import com.hccake.ballcat.notify.model.dto.AnnouncementCloseMessage;
|
||||
import com.hccake.ballcat.notify.model.dto.AnnouncementPushMessage;
|
||||
import com.hccake.ballcat.notify.model.entity.UserAnnouncement;
|
||||
import com.hccake.ballcat.notify.service.UserAnnouncementService;
|
||||
import com.hccake.ballcat.admin.websocket.message.AnnouncementCloseMessage;
|
||||
import com.hccake.ballcat.admin.websocket.message.AnnouncementPushMessage;
|
||||
import com.hccake.ballcat.admin.websocket.message.DictChangeMessage;
|
||||
import com.hccake.ballcat.admin.websocket.message.LovChangeMessage;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.system.event.DictChangeEvent;
|
||||
import com.hccake.ballcat.system.event.LovChangeEvent;
|
||||
import com.hccake.ballcat.system.model.entity.SysUser;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,38 +25,13 @@ import java.util.List;
|
||||
* @version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PushEventListener {
|
||||
public class NotifyWebsocketEventListener {
|
||||
|
||||
private final UserAnnouncementService userAnnouncementService;
|
||||
|
||||
private final MessageDistributor messageDistributor;
|
||||
|
||||
@Async
|
||||
@EventListener(LovChangeEvent.class)
|
||||
public void onLovChangeEvent(LovChangeEvent event) {
|
||||
LovChangeMessage message = LovChangeMessage.of(event.getKeyword());
|
||||
messageDistributor.distribute(MessageDO.broadcastMessage(message.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典修改事件监听
|
||||
* @param event the `DictChangeEvent`
|
||||
*/
|
||||
@Async
|
||||
@EventListener(DictChangeEvent.class)
|
||||
public void onDictChangeEvent(DictChangeEvent event) {
|
||||
// 构建字典修改的消息体
|
||||
DictChangeMessage dictChangeMessage = new DictChangeMessage();
|
||||
dictChangeMessage.setDictCode(event.getDictCode());
|
||||
String msg = JsonUtils.toJson(dictChangeMessage);
|
||||
|
||||
// 广播修改信息
|
||||
MessageDO messageDO = new MessageDO().setMessageText(msg).setNeedBroadcast(true);
|
||||
messageDistributor.distribute(messageDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公告关闭事件监听
|
||||
* @param event the AnnouncementCloseEvent
|
||||
@@ -24,5 +24,9 @@
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-websocket</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.message;
|
||||
package com.hccake.ballcat.notify.model.dto;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.message.AbstractJsonWebSocketMessage;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.message;
|
||||
package com.hccake.ballcat.notify.model.dto;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.message.AbstractJsonWebSocketMessage;
|
||||
import lombok.Getter;
|
||||
@@ -16,6 +16,10 @@
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-spring-boot-starter-redis</artifactId>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.hccake.ballcat.common.websocket.config;
|
||||
package com.hccake.ballcat.autoconfigure.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.handler.JsonMessageHandler;
|
||||
import com.hccake.ballcat.common.websocket.holder.JsonMessageHandlerHolder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
@@ -18,6 +19,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Yakir
|
||||
*/
|
||||
@Import(WebSocketHandlerConfig.class)
|
||||
@EnableWebSocket
|
||||
@RequiredArgsConstructor
|
||||
public class WebSocketAutoConfiguration {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.websocket.config;
|
||||
package com.hccake.ballcat.autoconfigure.websocket;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.handler.CustomWebSocketHandler;
|
||||
import com.hccake.ballcat.common.websocket.handler.PingJsonMessageHandler;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.common.websocket.config;
|
||||
package com.hccake.ballcat.autoconfigure.websocket;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -1,3 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.hccake.ballcat.common.websocket.config.WebSocketAutoConfiguration,\
|
||||
com.hccake.ballcat.common.websocket.config.WebSocketHandlerConfig
|
||||
com.hccake.ballcat.autoconfigure.websocket.WebSocketAutoConfiguration
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.hccake.ballcat.system.websoket;
|
||||
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDO;
|
||||
import com.hccake.ballcat.common.websocket.distribute.MessageDistributor;
|
||||
import com.hccake.ballcat.system.event.DictChangeEvent;
|
||||
import com.hccake.ballcat.system.event.LovChangeEvent;
|
||||
import com.hccake.ballcat.system.model.dto.DictChangeMessage;
|
||||
import com.hccake.ballcat.system.model.dto.LovChangeMessage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SystemWebsocketEventListener {
|
||||
|
||||
private final MessageDistributor messageDistributor;
|
||||
|
||||
@Async
|
||||
@EventListener(LovChangeEvent.class)
|
||||
public void onLovChangeEvent(LovChangeEvent event) {
|
||||
LovChangeMessage message = LovChangeMessage.of(event.getKeyword());
|
||||
messageDistributor.distribute(MessageDO.broadcastMessage(message.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典修改事件监听
|
||||
* @param event the `DictChangeEvent`
|
||||
*/
|
||||
@Async
|
||||
@EventListener(DictChangeEvent.class)
|
||||
public void onDictChangeEvent(DictChangeEvent event) {
|
||||
// 构建字典修改的消息体
|
||||
DictChangeMessage dictChangeMessage = new DictChangeMessage();
|
||||
dictChangeMessage.setDictCode(event.getDictCode());
|
||||
String msg = JsonUtils.toJson(dictChangeMessage);
|
||||
|
||||
// 广播修改信息
|
||||
MessageDO messageDO = new MessageDO().setMessageText(msg).setNeedBroadcast(true);
|
||||
messageDistributor.distribute(messageDO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,10 @@
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-desensitize</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-common-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hccake</groupId>
|
||||
<artifactId>ballcat-extend-mybatis-plus</artifactId>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hccake.ballcat.admin.websocket.message;
|
||||
package com.hccake.ballcat.system.model.dto;
|
||||
|
||||
import com.hccake.ballcat.common.websocket.message.AbstractJsonWebSocketMessage;
|
||||
import lombok.Getter;
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hccake.ballcat.admin.websocket.message;
|
||||
package com.hccake.ballcat.system.model.dto;
|
||||
|
||||
import com.hccake.ballcat.admin.websocket.constant.MessageTypeConstants;
|
||||
import com.hccake.ballcat.common.util.JsonUtils;
|
||||
import com.hccake.ballcat.common.websocket.message.AbstractJsonWebSocketMessage;
|
||||
import lombok.Getter;
|
||||
@@ -16,7 +15,7 @@ public class LovChangeMessage extends AbstractJsonWebSocketMessage {
|
||||
private String keyword;
|
||||
|
||||
public LovChangeMessage(String keyword) {
|
||||
super(MessageTypeConstants.LOV_CHANGE);
|
||||
super("lov_change");
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user