All Products
Search
Document Center

Tablestore:Create a tunnel

Last Updated:Jul 05, 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.

Response parameters

Parameter

Description

TunnelId

The ID of the tunnel.

ResponseInfo

Other fields returned in the request, 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