Obtaining a Data Cursor

Use the DIS SDK to obtain the information about the data cursor.

char *streamName = "myStream";
char *projectId = "c159a24641da49b2a729ea6f57647888";
char *region = "******";
char *host = "dis.cn-north-1.myhuaweicloud.com:20004";
int ret = 0;
DISResponseInfo RspInfo = { 0 };
DISGetCursor     tempCursor = { 0 };
tempCursor.streamName = streamName;
tempCursor.partitionId = "0";
tempCursor.cursorType = DISCursorTypeAtSeqNumber;
tempCursor.startingSequenceNumber = "0";
//tempCursor.cursorType = DISCursorTypeAtSeqNumber;
//tempCursor.timestamp = "1536026725191";
printf("===================%s Begin=======================\n", __FUNCTION__);
ret = DisGetCursor(host, projectId, region, &tempCursor, &RspInfo);
if (ret != 0)
{
printf("GetCursor Error: %d\r\n", ret);
}
printf("the rsp code is %d\r\n", RspInfo.HttpResponseCode);
if (RspInfo.HttpResponseCode >= 300 || RspInfo.HttpResponseCode < 200)
{
printf("HttpResponseCode: %ld\r\n", RspInfo.HttpResponseCode);
printf("the errorCode is %s, message is %s\r\n", RspInfo.ErrorCode, RspInfo.ErrorDetail);
printf("===================%s End=======================\n", __FUNCTION__);
}
else
{
printf("HttpResponseCode: %ld\r\n", RspInfo.HttpResponseCode);
printf("the partition cursor is %s\r\n", tempCursor.cursorResult.partitionCursor);
printf("===================%s End=======================\n", __FUNCTION__);
}
Table 1 DISGetCursor parameter description

Parameter

Mandatory

Type

Description

streamName

Yes

char *

Name of the stream created on the management console.

The name can contain letters, digits, hyphens (-), and underscores (_).

The value must be 1 to 64 characters long.

partitionId

Yes

char *

ID of the partition to get the cursor for.

Value range: 0 to 2147483647

cursorType

No

DISCursorType

Cursor type.

  • DISCursorTypeAtSeqNumber: Data is read from the position denoted by a specific sequence number (that is defined by starting-sequence-number). This is the default cursor type.
  • DISCursorTypeAfterSeqNumber: Data is read right after the position denoted by a specific sequence number (that is defined by starting-sequence-number).
  • DISCursorTypeTrimHorizon: Data is read at the last untrimmed record in the partition in the system, which is the oldest data record in the partition.
  • DISCursorTypeLatest: Data is read just after the most recent record in the partition. This setting ensures that you always read the most recent data in the partition.
  • DISCursorTypeAtTimestamp: Data is read from the position denoted by a specific timestamp (that is defined by timestamp).

startingSequenceNumber

No

char *

Sequence number. A sequence number is the unique identifier of each record. DIS automatically allocates a sequence number when the data producer calls the PutRecords operation to add data to the DIS stream. The sequence number of the same partition key usually changes with time. A longer interval between PutRecords requests results in a larger sequence number.

The sequence number is closely related to cursor types AT_SEQUENCE_NUMBER and AFTER_SEQUENCE_NUMBER. The two parameters determine the location of the data to be accessed.

Value range: 0 to 9223372036854775807

timestamp

No

char *

Timestamp when the data record starts to be read, which is closely related to the DISCursorTypeAtTimestamp cursor type. The two parameters determine the position of the data to be read.

NOTE:

This timestamp is accurate to milliseconds.

pucReserved

No

void *

Empty pointer, used to extend the request body.

Execution Result

Information similar to the following is displayed on the console:

the rsp code is 200
HttpResponseCode: 200
the partition cursor is eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXNoYXduIiwicGFydGl0aW9uLWlkIjoiMCIsImN1cnNvci10eXBlIjoiQVRfU0VRVUVOQ0VfTlVNQkVSIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiMCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUzNTk3MjU4NzIxOX0
Table 2 DISGetCursor parameter description

Parameter

Type

Description

cursorResult

DISCursor

Cursor that is obtained in response.

Table 3 DISCursor parameter description

Parameter

Type

Description

partitionCursor

Char [520]

Data cursor.

Value: 1 to 512 characters.

NOTE:

The validity period of a cursor is 5 minutes.