package com.ld.igds.mq;
|
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.listener.PatternTopic;
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
/**
|
* REDIS 消息队列,监听配置
|
*/
|
@Configuration
|
public class RedisMqSubConfig {
|
|
public static final String TOPIC_TAG = "TOPIC_";
|
|
/**
|
* redis消息监听器容器
|
* <p>
|
* 订阅话题以TOPIC_TAG 为标记
|
*/
|
@Bean
|
public RedisMessageListenerContainer container(RedisConnectionFactory redisConnectionFactory) {
|
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
container.setConnectionFactory(redisConnectionFactory);
|
|
//订阅频道,通配符*表示任意多个占位符
|
container.addMessageListener(new MySubscribe(), new PatternTopic(TOPIC_TAG + "*"));
|
|
return container;
|
}
|
|
}
|