spring-redis无法连接到远程主机

我有以下骆驼对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);

而且效果很好。但是,当我将redisUri从

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]

我检查了通过telnet到并使用redis-cli可以访问elasticache。

Could not get a resource from the pool连接到远程主机时出现此错误是什么?

我的本地redis和elasticache redis都运行2.8.24。运行骆驼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中使用。

以上是 spring-redis无法连接到远程主机 的全部内容, 来源链接: utcz.com/qa/407126.html

回到顶部