SDK overview
Overview
DataHub offers two SDK types: Low-Level and High-Level.
-
The Low-Level SDK implements DataHub server-side APIs, primarily for resource management.
-
The High-Level SDK (client library) has two modules: Producer and Consumer. It wraps Low-Level SDK read/write APIs for easier data ingestion and consumption.
Low-Level SDK
Each Low-Level SDK API maps to a DataHub RESTful API. For example, the create-project API:
POST /projects/<ProjectName> HTTP/1.1
x-datahub-client-version: 1.1
Date: Tue, 08 May 2018 09:47:48 GMT
Authorization: AuthorizationString
Content-Type: application/json
Content-Length: xxx
{
"Comment": "test project"
}
The corresponding Java API is:
/**
* Create a datahub project.
*
* @param projectName The name of the project.
* @param comment The comment of the project.
* @throws DatahubClientException Throws DatahubClientException
*/
CreateProjectResult createProject(String projectName, String comment);
High-Level SDK
The Low-Level SDK also handles data ingestion and consumption, but these operations require combining multiple APIs. Misuse can cause failures or excessive load. The High-Level SDK wraps these APIs to simplify read/write operations and improve stability.
Producer
The following compares data ingestion with the Low-Level SDK versus the Producer.
Using the Low-Level SDK:
-
Initialize the client.
-
Call
GetTopicorListSchemato retrieve schema information. -
Call
ListShardto get the list of shards and filter for those in theACTIVEstate. -
Accumulate data and send in batches.
-
Select a shard and call
PutRecordsByShardto write data. -
If the request succeeds, repeat step 4.
-
If the request fails, retry step 5 for retryable errors or handle non-retryable ones accordingly.
-
Periodically call
ListShardto update shard information.
Using the Producer (High-Level SDK for asynchronous sending):
-
Initialize the
Producerand register a callback. -
Call
sendAsyncto send data.
Advantages of the Producer over the Low-Level SDK:
-
Simpler logic and improved usability.
-
Built-in retry mechanism with configurable retries for exceptions such as network jitters.
-
Automatically adapts to scaling in/out.
Consumer
Low-Level SDK consumption is complex:
-
Each shard has a checkpoint that must be periodically committed and retrieved on startup.
-
A single shard cannot be consumed by multiple nodes, making multi-node shard allocation difficult.
-
For strict order requirements, handling shard splits/merges becomes complex. For example, if
shard0splits intoshard1andshard2, both inherit a portion of the hash range. Consumption must completeshard0before starting onshard1andshard2to preserve order.
Low-Level SDK consumption process:
-
Initialize the client.
-
Call
GetTopicorListSchemato retrieve schema information. -
Call
ListShardto get shard information and manually assign shards to tasks. -
Call
OpenOffsetSessionto start consumption and retrieve the stored offset. -
Use the offset to call
GetCursorand obtain the cursor. -
Use the cursor to call
GetRecordsand fetch data. -
If no data is returned, sleep and repeat step 6.
-
If data is returned, process the data and update the cursor, then repeat step 6.
-
Periodically call
ListShardandCommitOffsetto update shard information and checkpoints.
High-Level SDK consumption process using Consumer:
-
Initialize the
Consumer, which automatically assigns shards to nodes and retrieves saved checkpoints. -
Call
Readto read data. -
If no data is returned, the client waits and repeats step 2.
-
If data is returned, process it and repeat step 2.
Advantages of Consumer over the Low-Level SDK:
-
Simpler logic and easier to use.
-
Built-in retry mechanism with configurable retries for exceptions such as network jitters.
-
Automatically adapts to scaling in/out and maintains consumption order.
-
Dynamically allocates shards as nodes join or leave.
-
Automatic checkpoint management without manual handling.
SDK availability
|
Language |
Low-Level SDK |
High-Level SDK |
|
Java |
Supported |
Supported |
|
C++ |
Supported |
Supported |
|
Python |
Supported |
Supported |
|
Go |
Supported |
Not supported |