【问题标题】:Connect HBase via Knox using HBase Java Client on CDP使用 CDP 上的 HBase Java 客户端通过 Knox 连接 HBase
【发布时间】:2021-06-18 13:46:58
【问题描述】:

我需要使用 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 并检索数据?

【问题讨论】:

    标签: java hbase knox-gateway apache-knox cloudera-cdp


    【解决方案1】:

    我们可以使用 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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 2016-06-20
      • 2016-01-06
      相关资源
      最近更新 更多