/// <inheritdoc /> public async Task Add(string tableName, IEnumerable <HBaseRow> rows) { if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } if (rows == null) { throw new ArgumentNullException(nameof(rows)); } var wrapper = new HBaseRowWrapper { Rows = rows.ToList() }; var json = HBaseSerializationHelper.SerializeObject(wrapper); var url = $"{tableName}/row_key"; var content = HttpRequestContentFactory.CreateJsonContent(json); HttpResponseMessage response; using (var httpClient = CreateHttpClient()) { response = await httpClient.PutAsync(url, content); } if (!response.IsSuccessStatusCode) { throw new HBaseException("HBase REST API 返回了表示错误的 HTTP 状态码:" + response.StatusCode); } }
/// <inheritdoc /> public async Task <IHBaseScanner> OpenScanner(string tableName, HBaseScannerCreationOptions options = null) { if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } // 构造请求负载 var contentJson = string.Empty; if (options != null) { contentJson = HBaseSerializationHelper.SerializeObject(options); } // 发送 HTTP 请求 var url = $"{tableName}/scanner"; var content = HttpRequestContentFactory.CreateJsonContent(contentJson); HttpResponseMessage response; using (var httpClient = CreateHttpClient()) { response = await httpClient.PutAsync(url, content); } if (!response.IsSuccessStatusCode) { throw new HBaseException("HBase REST API 返回了表示错误的 HTTP 状态码:" + response.StatusCode); } // 从响应的 Location 头部拿到 Scanner 的接入点 if (!response.Headers.TryGetValues("Location", out var scannerEndpoints)) { throw new HBaseException("HBase REST API 没有返回任何有效的 Scanner 终结点。"); } var scannerEpt = scannerEndpoints.FirstOrDefault(); if (scannerEpt == null) { throw new HBaseException("HBase REST API 没有返回任何有效的 Scanner 终结点。"); } return(new DefaultHBaseScanner(scannerEpt, _httpClientFactory)); }