无法连接到远程主机

无法连接到远程主机

本文介绍了spring-redis 无法连接到远程主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下骆驼轮询Redis:

I have the following camel which polls Redis:

                from("timer://pollredis?fixedRate=true&period=5")
                    // poll redis
                    .setHeader("CamelRedis.Command", constant("LPOP"))
                    .setHeader("CamelRedis.Key", constant("shipments"))
                    // from redis, it is a producer, fetch with .to() !
                    .to(redisUri)
                    //
                    .choice().when(simple("${in.body} == null")).stop().otherwise()
                    //
                    .to("direct:internal").end();


    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.afterPropertiesSet();

    RedisTemplate<?, ?> redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();

    SimpleRegistry registry = new SimpleRegistry();
    registry.put("redisTemplate", redisTemplate);

而且效果很好.但是,当我从

And it works great. However, when I change the redisUri from

redisUri = spring-redis://localhost:6379?redisTemplate=#redisTemplate

redisUri = spring-redis://[stuff].xavwv8.ng.0001.euw1.cache.amazonaws.com:6379?redisTemplate=#redisTemplate

我收到以下错误:

11:42:49.754 INFO  Failed delivery for (MessageId: ID-ip-10-12-22-168-43293-1465299763162-0-1 on ExchangeId: ID-ip-10-12-22-168-43293-1465299763162-0-2). On delivery attempt: 0 caught: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool | org.apache.camel.util.CamelLogger.log(CamelLogger.java:159) [Camel (camel-1) thread #0 - timer://pollredis]

我已经通过远程登录和使用 redis-cli 来检查我是否可以访问 elasticache.

I have checked that I have access to the elasticache by telneting to it and by using redis-cli.

连接到远程主机时出现的无法从池中获取资源错误是什么?

What is this Could not get a resource from the pool error that I'm getting when connecting to a remote host?

我的本​​地 redis 和 elasticache redis 都在运行 2.8.24.跑骆驼2.17.1.

Both my local redis and the elasticache redis is running 2.8.24. Running camel 2.17.1.

推荐答案

这是我的工作方式:

    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(redisHost);
    jedisConnectionFactory.setPort(Integer.parseInt(redisPort));
    jedisConnectionFactory.afterPropertiesSet();

    RedisTemplate<String, Object> redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();

    SimpleRegistry registry = new SimpleRegistry();
    registry.put("redisTemplate", redisTemplate);

属性文件:

redisUri = spring-redis://notused?redisTemplate=#redisTemplate
redisHost = [stuff].xavwv8.ng.0001.euw1.cache.amazonaws.com
redisPort = 6379

骆驼路线和以前一样.

很明显,当您使用连接工厂时,您无法将主机设置为稍后在 URI 中使用.

So apparently when you use a connection factory you can't set the host to use in the URI later.

这篇关于spring-redis 无法连接到远程主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:08