简体   繁体   English

Redis PubSub 与 Jedis 重新连接

[英]Redis PubSub Reconnect with Jedis

Trying to include the code related to azure redis autoreconnect if any.network error occurred in Redis PubSub connection.尝试包含与 azure redis autoreconnect if any.network error occurred in Redis PubSub connection 相关的代码。 Any help/advice would be appreciable.任何帮助/建议都将不胜感激。 Below is my Redis Config code.下面是我的 Redis 配置代码。

 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;
    }
    }

Please see the following client library specific guidance ( link ) for Azure Cache for Redis and the information available for Jedis (Java) .请参阅以下针对 Azure 的客户端库特定指南( 链接) Redis 的缓存以及Jedis (Java)的可用信息。

There is a PoolUsage.java example and a ClusterUsage.java example.有一个PoolUsage.java示例和一个ClusterUsage.java示例。

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?至于 PubSub Reconnect 的具体例子,请看下面的 Stack Overflow 帖子: 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM