Class SqlDataServiceClient (0.1.0)

GitHub RepositoryProduct Reference

Service Description: Service for streaming data to and from Cloud SQL instances.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SqlDataServiceClient sqlDataServiceClient = SqlDataServiceClient.create()) {
   BidiStream<StreamSqlDataRequest, StreamSqlDataResponse> bidiStream =
       sqlDataServiceClient.streamSqlDataCallable().call();
   StreamSqlDataRequest request =
       StreamSqlDataRequest.newBuilder()
           .setAck(Ack.newBuilder().build())
           .setInstanceId(InstanceName.of("[PROJECT]", "[INSTANCE]").toString())
           .build();
   bidiStream.send(request);
   for (StreamSqlDataResponse response : bidiStream) {
     // Do something when a response is received.
   }
 }
 

Note: close() needs to be called on the SqlDataServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

StreamSqlData

StreamSqlData establishes a bidirectional stream to a Cloud SQL instance, and then streams data to and from the instance.

The first message from the client MUST be a StreamSqlDataRequest request with configuration settings, including required values for the connection_settings field. Subsequent messages from the client may contain the payload field.

Messages from the server may contain the payload field.

The payload fields of the request and response streams contain the raw data of the database's native wire protocol (e.g., PostgreSQL wire protocol). The database client is responsible for generating and parsing this data.

Any errors on initial connection (e.g., connection failure, authorization issues, network problems) will result in the stream being terminated with an appropriate RPC status exception.

After a successful connection is made, if an error occurs, then the server terminates connection and returns the appropriate RPC status exception.

Add the request params headers to the request to ensure that the streaming request is routed to the correct service for your database.

Use this format for the request params header:

x-goog-request-params: location_id={location_path}&instance_id={instance_path}

location_path is locations/{location_name} instance_path is projects/{project_name}/instances/{instance_name}

for example: x-goog-request-params: location_id=locations/us-central1&instance_id=projects/myproject/instances/instancename`

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • streamSqlDataCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of SqlDataServiceSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SqlDataServiceSettings sqlDataServiceSettings =
     SqlDataServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 SqlDataServiceClient sqlDataServiceClient = SqlDataServiceClient.create(sqlDataServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SqlDataServiceSettings sqlDataServiceSettings =
     SqlDataServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 SqlDataServiceClient sqlDataServiceClient = SqlDataServiceClient.create(sqlDataServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > SqlDataServiceClient

Static Methods

create()

public static final SqlDataServiceClient create()

Constructs an instance of SqlDataServiceClient with default settings.

Returns
Type Description
SqlDataServiceClient
Exceptions
Type Description
IOException

create(SqlDataServiceSettings settings)

public static final SqlDataServiceClient create(SqlDataServiceSettings settings)

Constructs an instance of SqlDataServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings SqlDataServiceSettings
Returns
Type Description
SqlDataServiceClient
Exceptions
Type Description
IOException

create(SqlDataServiceStub stub)

public static final SqlDataServiceClient create(SqlDataServiceStub stub)

Constructs an instance of SqlDataServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(SqlDataServiceSettings).

Parameter
Name Description
stub SqlDataServiceStub
Returns
Type Description
SqlDataServiceClient

Constructors

SqlDataServiceClient(SqlDataServiceSettings settings)

protected SqlDataServiceClient(SqlDataServiceSettings settings)

Constructs an instance of SqlDataServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings SqlDataServiceSettings

SqlDataServiceClient(SqlDataServiceStub stub)

protected SqlDataServiceClient(SqlDataServiceStub stub)
Parameter
Name Description
stub SqlDataServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

getSettings()

public final @Nullable SqlDataServiceSettings getSettings()
Returns
Type Description
@org.jspecify.annotations.Nullable com.google.cloud.sql.v1beta4.SqlDataServiceSettings

getStub()

public SqlDataServiceStub getStub()
Returns
Type Description
SqlDataServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

streamSqlDataCallable()

public final BidiStreamingCallable<StreamSqlDataRequest,StreamSqlDataResponse> streamSqlDataCallable()

StreamSqlData establishes a bidirectional stream to a Cloud SQL instance, and then streams data to and from the instance.

The first message from the client MUST be a StreamSqlDataRequest request with configuration settings, including required values for the connection_settings field. Subsequent messages from the client may contain the payload field.

Messages from the server may contain the payload field.

The payload fields of the request and response streams contain the raw data of the database's native wire protocol (e.g., PostgreSQL wire protocol). The database client is responsible for generating and parsing this data.

Any errors on initial connection (e.g., connection failure, authorization issues, network problems) will result in the stream being terminated with an appropriate RPC status exception.

After a successful connection is made, if an error occurs, then the server terminates connection and returns the appropriate RPC status exception.

Add the request params headers to the request to ensure that the streaming request is routed to the correct service for your database.

Use this format for the request params header:

x-goog-request-params: location_id={location_path}&instance_id={instance_path}

location_path is locations/{location_name} instance_path is projects/{project_name}/instances/{instance_name}

for example: x-goog-request-params: location_id=locations/us-central1&instance_id=projects/myproject/instances/instancename`

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SqlDataServiceClient sqlDataServiceClient = SqlDataServiceClient.create()) {
   BidiStream<StreamSqlDataRequest, StreamSqlDataResponse> bidiStream =
       sqlDataServiceClient.streamSqlDataCallable().call();
   StreamSqlDataRequest request =
       StreamSqlDataRequest.newBuilder()
           .setAck(Ack.newBuilder().build())
           .setInstanceId(InstanceName.of("[PROJECT]", "[INSTANCE]").toString())
           .build();
   bidiStream.send(request);
   for (StreamSqlDataResponse response : bidiStream) {
     // Do something when a response is received.
   }
 }
 
Returns
Type Description
BidiStreamingCallable<StreamSqlDataRequest,StreamSqlDataResponse>