Help Center> RES> User Guide> Managing a Data Source> Uploading Real-time Data

Uploading Real-time Data

RES uses DIS SDKs to upload real-time user data and perform nearline processing. This section uses Java as an example. For more language examples, see the Data Ingestion Service SDK Reference.

Prerequisites

  • If you need to use the nearline upload mode, you can use the DIS SDKs to upload data. Download the DIS SDKs as required.

Uploading Real-time Data to RES

  1. Initialize the DIS client and use code to initialize the DIS SDK client instance. The following is a code example: For details, see Initializing the DIS Client.
    1
    2
    3
    4
    5
    6
    7
    8
    // Create a DIS client instance.
    DIS dic = DISClientBuilder.standard()
    	.withEndpoint("YOUR_ENDPOINT")
    	.withAk("YOUR_AK")
    	.withSk("YOUR_SK")
    	.withProjectId("YOUR_PROJECT_ID")
    	.withRegion("YOUR_REGION")
    	.build();
    

    Parameter descriptions:

  2. Obtain the ID of the stream (streamId) to which data is uploaded.
    • Click Details of a nearline data source.
      Figure 1 Obtaining the stream ID
  3. Upload real-time data. The sample code is as follows. The value of streamId must be the same as the stream ID in step 2.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    // Configure stream ID.
    String streamId = "xxxx";
    // Configure the data to be uploaded.
    String message = "hello world.";
    PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
    putRecordsRequest.setStreamId(streamId);
    List < PutRecordsRequestEntry > putRecordsRequestEntryList = new ArrayList < PutRecordsRequestEntry > ();
    ByteBuffer buffer = ByteBuffer.wrap(message.getBytes());
    for (int i = 0; i < 3; i++) {
    	PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry();
    	putRecordsRequestEntry.setData(buffer);
    	putRecordsRequestEntry.setPartitionKey(String.valueOf(ThreadLocalRandom.current().nextInt(1000000)));
    	putRecordsRequestEntryList.add(putRecordsRequestEntry);
    }
    putRecordsRequest.setRecords(putRecordsRequestEntryList);
    
    LOGGER.info("========== BEGIN PUT ============");
    
    PutRecordsResult putRecordsResult = null;
    try {
    	putRecordsResult = dic.putRecords(putRecordsRequest);
    } catch (DISClientException e) {
    	LOGGER.error("Failed to get a normal response, please check params and retry. Error message [{}]",
    		e.getMessage(),
    		e);
    } catch (Exception e) {
    	LOGGER.error(e.getMessage(), e);
    }