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 14 import org.redisson.api.RedissonClient;
15 15 import org.springframework.beans.factory.annotation.Value;
16 16 import org.springframework.boot.autoconfigure.AutoConfiguration;
  17 +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
17 19 import org.springframework.context.annotation.Bean;
18 20 import org.springframework.data.redis.connection.RedisServerCommands;
19 21 import org.springframework.data.redis.connection.stream.Consumer;
... ... @@ -57,6 +59,8 @@ public class YudaoMQAutoConfiguration {
57 59 * 创建 Redis Pub/Sub 广播消费的容器
58 60 */
59 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 64 public RedisMessageListenerContainer redisMessageListenerContainer(
61 65 RedisMQTemplate redisMQTemplate, List<AbstractChannelMessageListener<?>> listeners) {
62 66 // 创建 RedisMessageListenerContainer 对象
... ... @@ -77,6 +81,8 @@ public class YudaoMQAutoConfiguration {
77 81 * 创建 Redis Stream 重新消费的任务
78 82 */
79 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 86 public RedisPendingMessageResendJob redisPendingMessageResendJob(List<AbstractStreamMessageListener<?>> listeners,
81 87 RedisMQTemplate redisTemplate,
82 88 @Value("${spring.application.name}") String groupName,
... ... @@ -90,6 +96,8 @@ public class YudaoMQAutoConfiguration {
90 96 * Redis Stream 的 xreadgroup 命令:https://www.geek-book.com/src/docs/redis/redis/redis.io/commands/xreadgroup.html
91 97 */
92 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 101 public StreamMessageListenerContainer<String, ObjectRecord<String, String>> redisStreamMessageListenerContainer(
94 102 RedisMQTemplate redisMQTemplate, List<AbstractStreamMessageListener<?>> listeners) {
95 103 RedisTemplate<String, ?> redisTemplate = redisMQTemplate.getRedisTemplate();
... ...
yudao-server/src/main/resources/application.yaml
... ... @@ -134,6 +134,12 @@ yudao:
134 134 - cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants
135 135 - cn.iocoder.yudao.module.system.enums.ErrorCodeConstants
136 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 143 tenant: # 多租户相关配置项
138 144 enable: true
139 145 ignore-urls:
... ...