我正在尝试运行jetcd客户端以访问在端口2379的docker容器中运行的etcd
我正在使用docker映像Name: tensorflow
Version: 1.11.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /home/pi/.local/lib/python3.5/site-packages
Requires: termcolor, keras-preprocessing, six, grpcio, tensorboard, absl-py, numpy, gast, setuptools, protobuf, astor, keras-applications, wheel
Required-by:
并执行以下命令来启动容器:
elcolio/etcd:latest
,我只运行一个实例。容器已成功启动,并且我能够在容器上运行docker run \
-d \
-p 2379:2379 \
-p 2380:2380 \
-p 4001:4001 \
-p 7001:7001 \
-v /data/backup/dir:/data \
--name some-etcd \
elcolio/etcd:latest \
-name some-etcd \
-discovery=https://discovery.etcd.io/blahblahblahblah \
-advertise-client-urls http://10.x.x.x:4001 \
-initial-advertise-peer-urls http://10.x.x.x:7001
。但是,通过Java,我无法运行它。
代码如下:
etcdctl
我遇到以下错误:
import com.coreos.jetcd.Client;
import com.coreos.jetcd.KV;
import com.coreos.jetcd.data.ByteSequence;
import com.coreos.jetcd.kv.GetResponse;
import com.coreos.jetcd.data.ByteSequence;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Demo {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Client client = Client.builder().endpoints("https://10.x.x.x:2379").build();
KV kvClient = client.getKVClient();
ByteSequence key = ByteSequence.fromString("/message");
ByteSequence value = ByteSequence.fromString("test_value");
// put the key-value
// kvClient.put(key,value).get();
// get the CompletableFuture
CompletableFuture<GetResponse> getFuture = kvClient.get(key);
// get the value from CompletableFuture
GetResponse response = getFuture.get();
System.out.println(response);
// delete the key
kvClient.delete(key).get();
}
}
P.S:我尝试在该端口上进行telnet,并且工作正常。卷曲也很好。我没有为etcd输入凭据。
答案 0 :(得分:0)
如果您将convert 485454502f转换为字符串,则显示:HTTP/
似乎您的程序正在尝试连接到HTTP1服务器,而不是HTTP2(如跟踪中所述)。
答案 1 :(得分:0)
Asier强调的问题是正确的。我在这里得到的解决方法是下载支持http 2.0的etcd3。 为此,我下载了图像:
https://hub.docker.com/r/xieyanze/etcd3
然后与之连接。
答案 2 :(得分:0)
当我使用Java客户端0.3.0并且我的docker映像是v2时,我遇到了同样的问题,因此我将映像更新为v3,然后解决了这个问题。