Commit a82898ca135491b815a9e5c7cda9e95b65b12708

Authored by puhui999
2 parents 92b10e2e 68049b85

Merge remote-tracking branch 'yudao/master' into feature/mall_product

yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/config/YudaoMQAutoConfiguration.java
@@ -14,6 +14,8 @@ import lombok.extern.slf4j.Slf4j; @@ -14,6 +14,8 @@ import lombok.extern.slf4j.Slf4j;
14 import org.redisson.api.RedissonClient; 14 import org.redisson.api.RedissonClient;
15 import org.springframework.beans.factory.annotation.Value; 15 import org.springframework.beans.factory.annotation.Value;
16 import org.springframework.boot.autoconfigure.AutoConfiguration; 16 import org.springframework.boot.autoconfigure.AutoConfiguration;
  17 +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
17 import org.springframework.context.annotation.Bean; 19 import org.springframework.context.annotation.Bean;
18 import org.springframework.data.redis.connection.RedisServerCommands; 20 import org.springframework.data.redis.connection.RedisServerCommands;
19 import org.springframework.data.redis.connection.stream.Consumer; 21 import org.springframework.data.redis.connection.stream.Consumer;
@@ -57,6 +59,8 @@ public class YudaoMQAutoConfiguration { @@ -57,6 +59,8 @@ public class YudaoMQAutoConfiguration {
57 * 创建 Redis Pub/Sub 广播消费的容器 59 * 创建 Redis Pub/Sub 广播消费的容器
58 */ 60 */
59 @Bean(initMethod = "start", destroyMethod = "stop") 61 @Bean(initMethod = "start", destroyMethod = "stop")
  62 + @ConditionalOnBean(AbstractChannelMessageListener.class) // 只有 AbstractChannelMessageListener 存在的时候,才需要注册 Redis pubsub 监听
  63 + @ConditionalOnProperty(prefix = "yudao.mq.redis.pubsub", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.pubsub.enable=false 禁用多租户
60 public RedisMessageListenerContainer redisMessageListenerContainer( 64 public RedisMessageListenerContainer redisMessageListenerContainer(
61 RedisMQTemplate redisMQTemplate, List<AbstractChannelMessageListener<?>> listeners) { 65 RedisMQTemplate redisMQTemplate, List<AbstractChannelMessageListener<?>> listeners) {
62 // 创建 RedisMessageListenerContainer 对象 66 // 创建 RedisMessageListenerContainer 对象
@@ -77,6 +81,8 @@ public class YudaoMQAutoConfiguration { @@ -77,6 +81,8 @@ public class YudaoMQAutoConfiguration {
77 * 创建 Redis Stream 重新消费的任务 81 * 创建 Redis Stream 重新消费的任务
78 */ 82 */
79 @Bean 83 @Bean
  84 + @ConditionalOnBean(AbstractStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候,才需要注册 Redis pubsub 监听
  85 + @ConditionalOnProperty(prefix = "yudao.mq.redis.stream", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.stream.enable=false 禁用多租户
80 public RedisPendingMessageResendJob redisPendingMessageResendJob(List<AbstractStreamMessageListener<?>> listeners, 86 public RedisPendingMessageResendJob redisPendingMessageResendJob(List<AbstractStreamMessageListener<?>> listeners,
81 RedisMQTemplate redisTemplate, 87 RedisMQTemplate redisTemplate,
82 @Value("${spring.application.name}") String groupName, 88 @Value("${spring.application.name}") String groupName,
@@ -90,6 +96,8 @@ public class YudaoMQAutoConfiguration { @@ -90,6 +96,8 @@ public class YudaoMQAutoConfiguration {
90 * Redis Stream 的 xreadgroup 命令:https://www.geek-book.com/src/docs/redis/redis/redis.io/commands/xreadgroup.html 96 * Redis Stream 的 xreadgroup 命令:https://www.geek-book.com/src/docs/redis/redis/redis.io/commands/xreadgroup.html
91 */ 97 */
92 @Bean(initMethod = "start", destroyMethod = "stop") 98 @Bean(initMethod = "start", destroyMethod = "stop")
  99 + @ConditionalOnBean(AbstractStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候,才需要注册 Redis pubsub 监听
  100 + @ConditionalOnProperty(prefix = "yudao.mq.redis.stream", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.stream.enable=false 禁用多租户
93 public StreamMessageListenerContainer<String, ObjectRecord<String, String>> redisStreamMessageListenerContainer( 101 public StreamMessageListenerContainer<String, ObjectRecord<String, String>> redisStreamMessageListenerContainer(
94 RedisMQTemplate redisMQTemplate, List<AbstractStreamMessageListener<?>> listeners) { 102 RedisMQTemplate redisMQTemplate, List<AbstractStreamMessageListener<?>> listeners) {
95 RedisTemplate<String, ?> redisTemplate = redisMQTemplate.getRedisTemplate(); 103 RedisTemplate<String, ?> redisTemplate = redisMQTemplate.getRedisTemplate();
yudao-server/src/main/resources/application.yaml
@@ -134,6 +134,12 @@ yudao: @@ -134,6 +134,12 @@ yudao:
134 - cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants 134 - cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants
135 - cn.iocoder.yudao.module.system.enums.ErrorCodeConstants 135 - cn.iocoder.yudao.module.system.enums.ErrorCodeConstants
136 - cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants 136 - cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants
  137 + mq:
  138 + redis:
  139 + pubsub:
  140 + enable: false # 是否开启 Redis pubsub 广播消费,默认为 true。这里设置成 false,可以按需开启
  141 + stream:
  142 + enable: false # 是否开启 Redis stream 集群消费,默认为 true。这里设置成 false,可以按需开启
137 tenant: # 多租户相关配置项 143 tenant: # 多租户相关配置项
138 enable: true 144 enable: true
139 ignore-urls: 145 ignore-urls: