0

I am using spring-MVC and spring-data-redis to control Redis-cluster pool. When I using jedisCluster.subscribe(new JedisPubSubListener(), "bb");

my application will stock in this code(I try to use thread but the other one can't get the instance in @autowerid). I google a lot of way point me to using spring-boot . but I can change the structure in our project. So I think when spring init I can register a listener to use. But I can run sauce in my original code.

Can someone make an example for me if I using this following code :

@Configuration
public class RedisClusterConfig {
    private List<String> redisNodes(){
        return Arrays.asList(redisNode.split(","));
    }

    @Bean
    JedisPoolConfig jedisPoolConfig(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(maxTotal);
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMinIdle(minIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
        jedisPoolConfig.setTestOnBorrow(testOnBorrow);
        jedisPoolConfig.setTestOnReturn(testOnReturn);
        jedisPoolConfig.setTestWhileIdle(testWhileIdle);        
        return jedisPoolConfig;
    }

@Bean
    RedisConnectionFactory redisClusterConnectionFactory(JedisPoolConfig 
jedisPoolConfig){
        JedisConnectionFactory redisConnectionFactory = new 
JedisConnectionFactory(new RedisClusterConfiguration(redisNodes()));
        redisConnectionFactory.setPoolConfig(jedisPoolConfig);
        return redisConnectionFactory;
    }
}
石荒人
  • 753
  • 1
  • 6
  • 11

1 Answers1

0

this is how I setting in my configuration.

@Bean
public RedisMessageListenerContainer redisMessageListenerContainer() {

    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(redisConnectionFactory);

    container.addMessageListener(consumerRedis(),topic());
    return container;

}

@Bean
public ConsumerRedisListener consumerRedis() {
    return new ConsumerRedisListener();//this class implements MessageListener 
}

@Bean
public ChannelTopic topic() {
    return new ChannelTopic("channel");
}
石荒人
  • 753
  • 1
  • 6
  • 11