1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.bigtable.data.v2.samples; 18 19 // [START bigtable_v2_generated_Bigtable_ReadRows_async] 20 import com.google.api.gax.rpc.ServerStream; 21 import com.google.bigtable.v2.ReadRowsRequest; 22 import com.google.bigtable.v2.ReadRowsResponse; 23 import com.google.bigtable.v2.RowFilter; 24 import com.google.bigtable.v2.RowSet; 25 import com.google.bigtable.v2.TableName; 26 import com.google.cloud.bigtable.data.v2.BaseBigtableDataClient; 27 28 public class AsyncReadRows { 29 main(String[] args)30 public static void main(String[] args) throws Exception { 31 asyncReadRows(); 32 } 33 asyncReadRows()34 public static void asyncReadRows() throws Exception { 35 // This snippet has been automatically generated and should be regarded as a code template only. 36 // It will require modifications to work: 37 // - It may require correct/in-range values for request initialization. 38 // - It may require specifying regional endpoints when creating the service client as shown in 39 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 40 try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) { 41 ReadRowsRequest request = 42 ReadRowsRequest.newBuilder() 43 .setTableName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()) 44 .setAppProfileId("appProfileId704923523") 45 .setRows(RowSet.newBuilder().build()) 46 .setFilter(RowFilter.newBuilder().build()) 47 .setRowsLimit(-944199211) 48 .build(); 49 ServerStream<ReadRowsResponse> stream = 50 baseBigtableDataClient.readRowsCallable().call(request); 51 for (ReadRowsResponse response : stream) { 52 // Do something when a response is received. 53 } 54 } 55 } 56 } 57 // [END bigtable_v2_generated_Bigtable_ReadRows_async] 58