github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dis/v2/data/GetCursor.go (about)

     1  package data
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  )
     7  
     8  type GetCursorOpts struct {
     9  	// Name of the stream.
    10  	StreamName string `q:"stream-name"`
    11  	// Partition ID of the stream. The value can be in either of the following formats:
    12  	// shardId-00000000000
    13  	// For example, if a stream has three partitions, the partition identifiers are 0, 1, and 2,
    14  	// or shardId-0000000000, shardId-0000000001, and shardId-0000000002, respectively.
    15  	PartitionId string `q:"partition-id"`
    16  	// Cursor type.
    17  	// AT_SEQUENCE_NUMBER: Data is read from the position denoted by a specific sequence number
    18  	// (that is defined by starting-sequence-number). This is the default cursor type.
    19  	// AFTER_SEQUENCE_NUMBER: Data is read right after the position denoted by a specific sequence number
    20  	// (that is defined by starting-sequence-number).
    21  	// TRIM_HORIZON: Data is read from the earliest data record in the partition.
    22  	// For example, a tenant uses a DIS stream to upload three pieces of data A1, A2, and A3. N days later,
    23  	// A1 has expired and A2 and A3 are still in the validity period.
    24  	// In this case, if the tenant uses TRIM_HORIZON to download the data, the system downloads data from A2.
    25  	// LATEST: Data is read from the latest record in the partition.
    26  	// This setting ensures that you always read the latest record in the partition.
    27  	// AT_TIMESTAMP: Data is read from the position denoted by a specific timestamp.
    28  	// Enumeration values:
    29  	// AT_SEQUENCE_NUMBER
    30  	// AFTER_SEQUENCE_NUMBER
    31  	// TRIM_HORIZON
    32  	// LATEST
    33  	// AT_TIMESTAMP
    34  	CursorType string `q:"cursor-type,omitempty"`
    35  	// Serial number. A sequence number is a unique identifier for each record.
    36  	// DIS automatically allocates a sequence number when the data producer calls the PutRecords operation to add data to the DIS stream.
    37  	// SN of the same partition key usually changes with time.
    38  	// A longer interval between PutRecords requests results in a larger sequence number.
    39  	// The sequence number is closely related to cursor types AT_SEQUENCE_NUMBER and AFTER_SEQUENCE_NUMBER.
    40  	// The two parameters determine the position of the data to be read.
    41  	// Value range: 0 to 9,223,372,036,854,775,807
    42  	StartingSequenceNumber string `q:"starting-sequence-number,omitempty"`
    43  	// Timestamp when the data record starts to be read, which is closely related to cursor type AT_TIMESTAMP.
    44  	// The two parameters determine the position of the data to be read.
    45  	// Note:
    46  	// The timestamp is accurate to milliseconds.
    47  	Timestamp *int64 `q:"timestamp,omitempty"`
    48  	// Unique ID of the stream. This parameter is mandatory for obtaining the iterator of an authorized stream.
    49  	StreamId string `q:"stream-id,omitempty"`
    50  }
    51  
    52  func GetCursor(client *golangsdk.ServiceClient, opts GetCursorOpts) (*GetCursorResponse, error) {
    53  	url, err := golangsdk.NewURLBuilder().WithEndpoints("cursors").WithQueryParams(&opts).Build()
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  
    58  	// GET /v2/{project_id}/cursors
    59  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  
    64  	var res GetCursorResponse
    65  	err = extract.Into(raw.Body, &res)
    66  	return &res, err
    67  }
    68  
    69  type GetCursorResponse struct {
    70  	// Data cursor. Value range: a string of 1 to 512 characters
    71  	// Note:
    72  	// The validity period of a data cursor is 5 minutes.
    73  	// Minimum: 1
    74  	// Maximum: 512
    75  	PartitionCursor string `json:"partition_cursor,omitempty"`
    76  }