All Products
Search
Document Center

Tablestore:Create a tunnel

Last Updated:Oct 11, 2024

If you want to consume data in a data table in real time, you can call the CreateTunnel operation to create a tunnel for the table. You can create multiple tunnels for a data table. When you create a tunnel, you must specify the data table name, tunnel name, and tunnel type.

Prerequisites

  • A TunnelClient instance is initialized.

  • A data table is created. For more information, see Create a data table.

Parameters

Request parameters

Parameter

Description

TableName

The name of the data table for which you want to create a tunnel.

TunnelName

The name of the tunnel.

Type

The type of the tunnel. Valid values: BaseData, Stream, and BaseAndStream. The BaseData type specifies that the tunnel is used to consume full data of the data table. The Stream type specifies that the tunnel is used to consume incremental data of the data table. The BaseAndStream type specifies that the tunnel is used to consume differential data of the data table.

If you set this parameter to Stream or BaseAndStream, the system considers the data that is written to the data table after the tunnel is created incremental. If you want to consume incremental data generated after a specific point of time, you must configure the startTime parameter for the incremental data.

  • Valid values of the startTime parameter: [Current system time - Stream validity period + 5 minutes, Current system time]. Unit: nanoseconds.

    Note

    Stream validity period is the validity period of incremental logs in milliseconds. The maximum validity period of incremental logs is seven days. You can specify the Stream validity period when you enable Stream for the data table. You cannot modify the Stream validity period after you specify it.

  • You can also configure the endTime parameter for the incremental data that you want to consume. The value of the endTime parameter must be greater than the value of the startTime parameter.

Response parameters

Parameter

Description

TunnelId

The ID of the tunnel.

ResponseInfo

Other fields returned in the response, including the RequestId field in the request. RequestId uniquely identifies the request.

Examples

The following sample code provides an example on how to create a tunnel of the BaseAndStream type:

req := &tunnel.CreateTunnelRequest{
   TableName:  "<TABLE_NAME>",
   TunnelName: "<TUNNEL_NAME>",
   Type:       tunnel.TunnelTypeBaseStream, // Create a tunnel of the BaseAndStream type. 
}
resp, err := tunnelClient.CreateTunnel(req)
if err != nil {
   log.Fatal("create tunnel failed ", err)
}
log.Println("tunnel id is", resp.TunnelId)

FAQ

What do I do if the "OTSTrimmedDataAccess Requested stream data is already trimmed or does not exist" error message is returned when I use Tunnel Service to consume data?

References