gpt4 book ai didi

java - SolrJ 连接到 Zookeeper 时挂起

转载 作者:行者123 更新时间:2023-12-02 03:27:53 24 4
gpt4 key购买 nike

我有一个本地两个实例 Solr Cloud 设置和一个 Zookeeper 实例。我试图通过 SolrJ 连接来执行查询,但是在执行查询时我的代码挂起 2 分钟左右,然后失败。我遵循了 Solr wiki 上的基本示例。日志/代码如下

2016-07-24 13:29:01.932  INFO 83666 --- [qtp699221219-28] org.apache.zookeeper.ZooKeeper           : Initiating client connection, connectString=localhost:2181 sessionTimeout=10000 watcher=org.apache.solr.common.cloud.SolrZkClient$3@496eab9
2016-07-24 13:29:01.948 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ConnectionManager : Waiting for client to connect to ZooKeeper

2016-07-24 13:29:01.953 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

2016-07-24 13:29:01.955 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Socket connection established to localhost/127.0.0.1:2181, initiating session

2016-07-24 13:29:01.967 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1561cdd875e0004, negotiated timeout = 10000

2016-07-24 13:29:01.972 INFO 83666 --- [back-3-thread-1] o.a.solr.common.cloud.ConnectionManager : Watcher org.apache.solr.common.cloud.ConnectionManager@4bb95d56 name:ZooKeeperConnection Watcher:localhost:2181 got event WatchedEvent state:SyncConnected type:None path:null path:null type:None

2016-07-24 13:29:01.972 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ConnectionManager : Client is connected to ZooKeeper

2016-07-24 13:29:01.973 INFO 83666 --- [qtp699221219-28] o.apache.solr.common.cloud.SolrZkClient : Using default ZkACLProvider

2016-07-24 13:29:01.974 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader : Updating cluster state from ZooKeeper...



2016-07-24 13:29:01.990 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader : Loaded empty cluster properties

2016-07-24 13:29:01.995 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader : Updated live nodes from ZooKeeper... (0) -> (2)

2016-07-24 13:31:24.653 ERROR 83666 --- [qtp699221219-28] o.a.s.client.solrj.impl.CloudSolrClient : Request to collection foo failed due to (0) java.net.ConnectException: Operation timed out, retry? 0

我的代码是:

    String zkHostString = "localhost:2181";
CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHostString).build();
solr.setDefaultCollection("foo");
SolrQuery query = new SolrQuery();
query.set("q", "*:*");
QueryResponse response = null;
try {
response = solr.query(query);
} catch (SolrServerException e) {
return null;
}
//Do Something with the results...

最佳答案

呃,我是个白痴,zookeeper 实例和 solr 实例都在 docker 内部,上面发布的代码不是。因此,Zookeeper 使用 docker 容器 ip 报告 solr url...主机需要通过 localhost 连接,而不是 docker 容器 ip。

例如:Zookeeper 响应 [ http://172.17.0.5:8983/solr/foo_shard1_replica2 , http://172.17.0.6:8984/solr/foo_shard1_replica1]但我的代码需要调用 [ http://localhost:8983/solr/foo_shard1_replica2 , http://localhost:8984/solr/foo_shard1_replica1]

关于java - SolrJ 连接到 Zookeeper 时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38552103/

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