如何解决在 CDP 上使用 HBase Java 客户端通过 Knox 连接 HBase
我需要使用 HBase Java 客户端通过 Knox 连接到 HBase。我有以下诺克斯详细信息
Knox_Url: https://knox-host:port/gateway/cdp-proxy-api/hbase
Username: knox_user_name
Password: knox_password
使用以下代码,我可以添加 URL,但无法添加凭据。
URL url = new URL(Knox_Url);
Configuration conf = HBaseConfiguration.create();
conf.addResource(URL);
Connection con = ConnectionFactory.createConnection(conf);
我看过其他 StackOverflow 问题,但他们都提到了要在配置中设置的以下属性。
public void setUp() throws IOException {
config = HBaseConfiguration.create();
config.set("zookeeper.znode.parent","/hbase-unsecure");
config.set("hbase.zookeeper.quorum",ZOOKEEPER_QUORUM);
config.set("hbase.zookeeper.property.clientPort","2181");
config.set("hbase.cluster.distributed","true");
connection = ConnectionFactory.createConnection(config);
}
我的问题是有没有办法使用 Knox 网关详细信息连接到 HBase 并检索数据?
解决方法
我们可以使用 RestTemplate 连接到 HBase。
配置
public RestTemplate create(){
return new RestTemplateBuilder()
.basicAuthentication(user,password)
.setConnectTimeout(Duration.ofSeconds(60))
.setReadTimeout(Duration.ofSeconds(60))
.build();
}
使用
String url = "https://host:port/gateway/cdp-proxy-api/hbase";
String response = config.create().getForEntity(url,String.class).getBody();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。