我正在研究Lettuce集群Java客户端。它是在bolt
拓扑(Apache Strom)中设置的。 spout
正在从kafka
读取数据并将其传递给bolt
。但是,当我启动拓扑时,出现以下错误消息,程序终止。我想念什么吗?是什么原因造成的?
29502 [Thread-17-RecommendationLettuceBolt-executor [2 2]]错误o.a.s.util-异步循环死了! io.lettuce.core.RedisException:无法从初始URI检索初始集群分区[RedisURI [host ='127.0.0.1',port = 7001]] 在io.lettuce.core.cluster.RedisClusterClient.loadPartitions(RedisClusterClient.java:865)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在io.lettuce.core.cluster.RedisClusterClient.initializePartitions(RedisClusterClient.java:819)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在io.lettuce.core.cluster.RedisClusterClient.connect(RedisClusterClient.java:345)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在com.projectName.indexer.lettuce.LettuceClusterClientProvider.getConnection(LettuceClusterClientProvider.java:72)〜[classes / :?] 在com.projectName.indexer.lettuce.LettuceCacheRepopulationHandler.openLettuceConnection(LettuceCacheRepopulationHandler.java:42)〜[classes / :?] 在com.projectName.indexer.bolts.RecommendationLettuceBolt.prepare(RecommendationLettuceBolt.java:35)〜[classes / :?] 在org.apache.storm.daemon.executor $ fn__8058 $ fn__8071.invoke(executor.clj:795)〜[storm-core-1.0.2.jar:1.0.2] 在org.apache.storm.util $ async_loop $ fn__624.invoke(util.clj:482)[storm-core-1.0.2.jar:1.0.2] 在clojure.lang.AFn.run(AFn.java:22)[clojure-1.7.0.jar :?] 在java.base / java.lang.Thread.run(Thread.java:844)[?:?] 引起原因:io.lettuce.core.RedisConnectionException:无法在[RedisURI [host ='127.0.0.1',port = 7001]]建立与Redis群集的连接 在io.lettuce.core.cluster.topology.AsyncConnections.get(AsyncConnections.java:89)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在io.lettuce.core.cluster.topology.ClusterTopologyRefresh.loadViews(ClusterTopologyRefresh.java:73)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在io.lettuce.core.cluster.RedisClusterClient.doLoadPartitions(RedisClusterClient.java:871)〜[lettuce-core-5.1.7.RELEASE.jar :?] 在io.lettuce.core.cluster.RedisClusterClient.loadPartitions(RedisClusterClient.java:844)〜[lettuce-core-5.1.7.RELEASE.jar :?] ...还有9个
private void init() {
redisUri = RedisURI.Builder
.redis(lettuceConfig.getLettuceClusterHost())
.withPort(lettuceConfig.getLettuceClusterPort())
.withTimeout(Duration.ofMillis(lettuceConfig.getLettuceClusterTimeout()))
.build();
}
public StatefulRedisClusterConnection getConnection() {
if (connection == null || !connection.isOpen()) {
redisClusterClient = RedisClusterClient.create(redisUri);
final ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
.enablePeriodicRefresh(Duration.ofMinutes(BoltConstants.Lettuce.PERIODIC_REFRESH_TIME_IN_MIN))
.enableAdaptiveRefreshTrigger()
.build();
final ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder()
.autoReconnect(true)
.topologyRefreshOptions(topologyRefreshOptions)
.build();
redisClusterClient.setOptions(clusterClientOptions);
connection = redisClusterClient.connect(SnappyCompressor.wrap(new StringCodec()));
log.info("Connected to Redis client lettuce. lettuce connection is up and running.");
}
return connection;
}
compile 'io.lettuce:lettuce-core:5.1.7.RELEASE'
答案 0 :(得分:1)
该错误即将到来,因为我尚未在您的计算机上本地安装 redis群集。
我通过以下步骤解决了
https://redis.io/download并在命令Installation下运行
$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzf redis-5.0.5.tar.gz
$ cd redis-5.0.5
$ make //The binaries that are now compiled are available in the src directory
$ src/redis-server
Creating a Redis Cluster using the create-cluster script
现在检查Redis发行版中的redis-5.0.5/utils/create-cluster
目录。内部有一个名为create-cluster
的脚本,它是一个简单的bash脚本。为了启动具有3个主节点和3个从节点的6节点集群,只需键入以下命令:
$ create-cluster start // start
$ create-cluster create // create cluster
$ create-cluster stop // for stoping
您将在终端中看到以下输出
$ ps aux |grep redis
300067846 28222 0.6 0.0 4379932 2612 ?? Ss 7:41PM 0:00.73 ../../src/redis-server *:30004 [cluster]
300067846 28227 0.5 0.0 4380956 2604 ?? Ss 7:41PM 0:00.71 ../../src/redis-server *:30006 [cluster]
300067846 28218 0.4 0.0 4381980 2676 ?? Ss 7:41PM 0:00.73 ../../src/redis-server *:30002 [cluster]
300067846 28216 0.4 0.0 4374812 2576 ?? Ss 7:41PM 0:00.50 ../../src/redis-server *:30001 [cluster]
300067846 28225 0.4 0.0 4380956 2632 ?? Ss 7:41PM 0:00.68 ../../src/redis-server *:30005 [cluster]
300067846 28220 0.3 0.0 4379932 2596 ?? Ss 7:41PM 0:00.52 ../../src/redis-server *:30003 [cluster]
300067846 85550 0.0 0.0 4309420 1128 ?? S 3:08PM 0:07.76 redis-server *:6379
查看所有主从节点
../redis-5.0.5/utils/create-cluster$ cat nodes-3000*.conf