-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
websocket:重新封装 websocket 组件,支持 token 认证,并增加 WebSocketMessageListener …
…方便处理消息
- Loading branch information
Showing
57 changed files
with
1,929 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ava/cn/iocoder/yudao/framework/mq/redis/config/YudaoRedisMQProducerAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cn.iocoder.yudao.framework.mq.redis.config; | ||
|
||
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate; | ||
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor; | ||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Redis 消息队列 Producer 配置类 | ||
* | ||
* @author 芋道源码 | ||
*/ | ||
@Slf4j | ||
@AutoConfiguration(after = YudaoRedisAutoConfiguration.class) | ||
public class YudaoRedisMQProducerAutoConfiguration { | ||
|
||
@Bean | ||
public RedisMQTemplate redisMQTemplate(StringRedisTemplate redisTemplate, | ||
List<RedisMessageInterceptor> interceptors) { | ||
RedisMQTemplate redisMQTemplate = new RedisMQTemplate(redisTemplate); | ||
// 添加拦截器 | ||
interceptors.forEach(redisMQTemplate::addInterceptor); | ||
return redisMQTemplate; | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cn.iocoder.yudao.framework.mq.redis.config.YudaoRedisMQAutoConfiguration | ||
cn.iocoder.yudao.framework.mq.redis.config.YudaoRedisMQProducerAutoConfiguration | ||
cn.iocoder.yudao.framework.mq.redis.config.YudaoRedisMQConsumerAutoConfiguration | ||
cn.iocoder.yudao.framework.mq.rabbitmq.config.YudaoRabbitMQAutoConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
yudao-framework/yudao-spring-boot-starter-websocket/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?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> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-framework</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>yudao-spring-boot-starter-websocket</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>${project.artifactId}</name> | ||
<description>WebSocket 框架,支持多节点的广播</description> | ||
<url>https://github.com/YunaiV/ruoyi-vue-pro</url> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-common</artifactId> | ||
</dependency> | ||
|
||
<!-- Web 相关 --> | ||
<dependency> | ||
<!-- 为什么是 websocket 依赖 security 呢?而不是 security 拓展 websocket 呢? | ||
因为 websocket 和 LoginUser 当前登录的用户有一定的相关性,具体可见 WebSocketSessionManagerImpl 逻辑。 | ||
如果让 security 拓展 websocket 的话,会导致 websocket 组件的封装很散,进而增大理解成本。 | ||
--> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-spring-boot-starter-security</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-websocket</artifactId> | ||
</dependency> | ||
|
||
<!-- Web 相关 --> | ||
<dependency> | ||
<!-- 为什么是 websocket 依赖 security 呢?而不是 security 拓展 websocket 呢? | ||
因为 websocket 和 LoginUser 当前登录的用户有一定的相关性,具体可见 WebSocketSessionManagerImpl 逻辑。 | ||
如果让 security 拓展 websocket 的话,会导致 websocket 组件的封装很散,进而增大理解成本。 | ||
--> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-spring-boot-starter-security</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- 消息队列相关 --> | ||
<dependency> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-spring-boot-starter-mq</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.kafka</groupId> | ||
<artifactId>spring-kafka</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.amqp</groupId> | ||
<artifactId>spring-rabbit</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.rocketmq</groupId> | ||
<artifactId>rocketmq-spring-boot-starter</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<!-- 业务组件 --> | ||
<dependency> | ||
<!-- 为什么要依赖 tenant 组件? | ||
因为广播某个类型的用户时候,需要根据租户过滤下,避免广播到别的租户! | ||
--> | ||
<groupId>cn.iocoder.cloud</groupId> | ||
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
34 changes: 34 additions & 0 deletions
34
...socket/src/main/java/cn/iocoder/yudao/framework/websocket/config/WebSocketProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.iocoder.yudao.framework.websocket.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* WebSocket 配置项 | ||
* | ||
* @author xingyu4j | ||
*/ | ||
@ConfigurationProperties("yudao.websocket") | ||
@Data | ||
@Validated | ||
public class WebSocketProperties { | ||
|
||
/** | ||
* WebSocket 的连接路径 | ||
*/ | ||
@NotEmpty(message = "WebSocket 的连接路径不能为空") | ||
private String path = "/ws"; | ||
|
||
/** | ||
* 消息发送器的类型 | ||
* | ||
* 可选值:local、redis、rocketmq、kafka、rabbitmq | ||
*/ | ||
@NotNull(message = "WebSocket 的消息发送者不能为空") | ||
private String senderType = "local"; | ||
|
||
} |
Oops, something went wrong.