Uploading Data

Sample Code

Initialize a DIS client as instructed in Initializing a DIS SDK Client Instance. Use the initialized client instance to upload your streaming data to DIS through a DIS stream.

//Initialize a DIS client.
var dic = new DISIngestionClient();  
//Specify the stream name.
 String streamName = "streamName"; 
PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
putRecordsRequest.StreamName = streamName;
//Configure the data to be uploaded.
 var putRecordsRequestEntries = new List<PutRecordsRequestEntry>();
string shardId = "shardId-0000000000";
for (int i = 0; i < 3; i++)
{
string a = shardId + i;
var putRecordsRequestEntry = new PutRecordsRequestEntry
{
//Data to be uploaded. The uploaded data is the serialized binary data in the Base64 format.
Data = Encoding.UTF8.GetBytes(a),
//Specify the hash value of the data to be written into the partition.
ExplicitHashKey = "123",
//Partition to which data is written to.
PartitionKey = 1
};
putRecordsRequestEntries.Add(putRecordsRequestEntry);
}
putRecordsRequest.Records = putRecordsRequestEntries;
PutRecordsResult response = dic.PutRecords(putRecordsRequest);

foreach (var item in response.Records)
{
Console.WriteLine(item);
}

Viewing Execution Results

Run Ctrl+F5. Information similar to the following is displayed on the console:

PutRecordsResultEntry [shardId=shardId-0000000000, sequenceNumber=0, errorCode=,
 errorMessage=]
PutRecordsResultEntry [shardId=shardId-0000000000, sequenceNumber=1, errorCode=,
 errorMessage=]
PutRecordsResultEntry [shardId=shardId-0000000000, sequenceNumber=2, errorCode=,
 errorMessage=]
Table 1 Description of response parameter PutRecordsResult

Parameter

Type

Description

failed_record_count

Int

Number of data records that fail to be uploaded.

records

List<PutRecordsResultEntry>

Information of data records.

Description of parameter PutRecordsResultEntry

errorCode

String

Error code.

errorMessage

String

Error message.

shardId

String

Partition ID.

sequenceNumber

String

Unique sequence number. Each data record has a sequence number that is unique within its partition.

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