gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 06:11:15 25 4
gpt4 key购买 nike

我有以下轮询 Redis 的 Camel :

                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] 

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

这是什么Could not get a resource from the pool 我在连接到远程主机时遇到的错误?

我的本​​地 redis 和 elasticache redis 都运行 2.8.24。运行 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

Camel 路线和以前一样。

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

关于spring-redis 无法连接到远程主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37681528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com