问题描述
我正在尝试使用gcloud beta模拟器中的bigtable模拟器。
我启动模拟器,获取主机名(localhost)和端口(在本例中为8885)
I am trying to use the bigtable emulator from gcloud beta emulators.I launch the emulator, grab the hostname (localhost) and port (in this instance 8885)
执行:/ usr / local / Caskroom / google-cloud-sdk / latest / google-cloud-sdk / platform / bigtable-emulator / cbtemulator --host = localhost --port = 8885
Executing: /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/bigtable-emulator/cbtemulator --host=localhost --port=8885
我正在尝试从java测试客户端连接到模拟器,
这是我的意思提供:
I am trying to connect to the emulator from a java test client,here is what I provide:
Configuration conf = BigtableConfiguration.configure(projectId, instanceId);
if(!Strings.isNullOrEmpty(host)){
conf.set(BigtableOptionsFactory.BIGTABLE_HOST_KEY, host);
conf.set(BigtableOptionsFactory.BIGTABLE_PORT_KEY, Integer.toString(port));
}
connection = BigtableConfiguration.connect(configuration);
try (Table table = connection.getTable("tName")){
table.put(<Put instance>);
}
当我执行测试代码时,我得到:
When I execute the test code I get:
16:36:37.369 [bigtable-batch-pool-1] INFO com.google.cloud.bigtable.grpc.async.AbstractRetryingRpcListener - Retrying failed call. Failure #1, got: Status{code=UNAVAILABLE, description=null, cause=java.net.ConnectException: Connection refused: localhost/0:0:0:0:0:0:0:1:8885}
java.net.ConnectException: Connection refused: localhost/0:0:0:0:0:0:0:1:8885
我正在使用该库: com.google.cloud.bigtable:bigtable-hbase-1.2:0.9.1
我知道我做错了什么?
谢谢!
推荐答案
您需要设置一个额外的配置属性:
You need one additional config property to be set:
conf.set(BigtableOptionsFactory.BIGTABLE_USE_PLAINTEXT_NEGOTIATION, true);
此外,从日志消息中看起来它正在尝试连接到IPv6地址,我不知道我认为会奏效。仔细检查 host
是否是有效的IPv4地址。
Also, from the log message it looks like it's trying to connect to an IPv6 address, which I don't think will work. Double-check that host
is a valid IPv4 address.
java客户端将使这更容易做到不久的将来。
The java client will make this easier to do in the near future.
这篇关于如何从java连接到正在运行的bigtable模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!