| | |
| | | package com.ruoyi.web.core.config; |
| | | |
| | | import com.ruoyi.web.component.RedisMqReceiver; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | |
| | | |
| | | @Configuration |
| | | public class RedisConfiguration { |
| | | @Autowired |
| | | private RedisConnectionFactory redisConnectionFactory; |
| | | |
| | | // 第一个@Bean是创建一个新的Redis消息监听容器,然后指定Redis连接。第二个@Bean是给我们写的监听类指定一个Redis消息监听容器,即第一个@Bean的内容 |
| | | |
| | | // 创建一个新的Redis消息监听容器 |
| | | @Bean |
| | | public RedisMessageListenerContainer redisMessageListenerContainer() { |
| | | RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer(); |
| | | redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory); |
| | | return redisMessageListenerContainer; |
| | | RedisMessageListenerContainer redisContainer(RedisConnectionFactory connectionFactory) { |
| | | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| | | container.setConnectionFactory(connectionFactory); |
| | | return container; |
| | | } |
| | | |
| | | @Bean |
| | | public RedisMqReceiver keyExpiredListener() { |
| | | return new RedisMqReceiver(this.redisMessageListenerContainer()); |
| | | } |
| | | |
| | | } |