0

Trying to include the code related to azure redis autoreconnect if any network error occurred in Redis PubSub connection. Any help/advice would be appreciable. Below is my Redis Config code.

 public class RedisConfig 
   {    
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        JedisConnectionFactory jedis = new JedisConnectionFactory();
        jedis.setHostName("redishostname");
        jedis.setPassword("redispassword");
        jedis.setPort(redisport);
        return jedis;
    }

    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
        return template;
    }   

    @Bean
    RedisMessageListenerContainer redisContainer() {
        final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(jedisConnectionFactory());
        container.setTaskExecutor(Executors.newFixedThreadPool(4));     
        return container;
    }
    }
Balaji211
  • 257
  • 1
  • 5
  • 18

1 Answers1

0

Please see the following client library specific guidance (link) for Azure Cache for Redis and the information available for Jedis (Java).

There is a PoolUsage.java example and a ClusterUsage.java example.

As for a specific example for PubSub Reconnect, please see the following Stack Overflow post: jedis pubsub and timeouts: how to listen infinitely as subscriber?

private AkkaStarter2(){
//0 specifying no timeout.. Overlooked this 100 times
sub = new Jedis(REDISHOST, REDISPORT,0);
akkaListener = new AkkaListener();
}
Mike Ubezzi
  • 1,007
  • 6
  • 8