潘志宝
2024-12-12 3374d19db03cce97572c3a294f137d1ea70b307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.iailab.framework.mq.redis.config;
 
import com.iailab.framework.mq.redis.core.RedisMQTemplate;
import com.iailab.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import com.iailab.framework.redis.config.IailabRedisAutoConfiguration;
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 iailab
 */
@Slf4j
@AutoConfiguration(after = IailabRedisAutoConfiguration.class)
public class IailabRedisMQProducerAutoConfiguration {
 
    @Bean
    public RedisMQTemplate redisMQTemplate(StringRedisTemplate redisTemplate,
                                           List<RedisMessageInterceptor> interceptors) {
        RedisMQTemplate redisMQTemplate = new RedisMQTemplate(redisTemplate);
        // 添加拦截器
        interceptors.forEach(redisMQTemplate::addInterceptor);
        return redisMQTemplate;
    }
 
}