Subscription operations
The DataHub C++ SDK provides operations to create, delete, update, list, and query subscriptions.
Create a subscription
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
Sample code
void CreateSubscription()
{
std::string projectName = "";
std::string topicName = "";
try
{
const std::string subscriptionComment = "test_subscription";
const CreateSubscriptionResult& createSubscriptionResult = client.CreateSubscription(projectName, topicName, subscriptionComment);
}
catch(const DatahubException& e)
{
std::cerr << "Create sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Delete a subscription
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
|
subId |
string |
Sample code
void DeleteSubscription()
{
std::string projectName = "";
std::string topicName = "";
std::string subId = "";
try
{
client.DeleteSubscription(projectName, topicName, subId);
}
catch(const DatahubException& e)
{
std::cerr << "Delete sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Update a subscription
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
|
subId |
string |
|
|
updateSubscriptionComment |
string |
Sample code
void UpdateSubscription()
{
try
{
const std::string updateSubscriptionComment = "test_subscription_1";
const std::string projectName = "";
const std::string topicName = "";
client.UpdateSubscription(projectName, topicName, subId, updateSubscriptionComment);
}
catch(const DatahubException& e)
{
std::cerr << "Upate sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
List subscriptions
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
|
subId |
string |
Sample code
void ListSubscription()
{
const std::string projectName = "";
const std::string topicName = "";
const std::string subId = "";
try
{
const ListSubscriptionResult& subscriptionResult = client.ListSubscription(projectName, topicName, 1, 20, subId));
std::cout << subscriptionResult.GetTotalCount() << std::endl;
}
catch(const DatahubException& e)
{
std::cerr << "list sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Query a subscription
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
|
subId |
string |
Sample code
void UpdateSubscriptionState()
{
try
{
client.UpdateSubscriptionState(projectName, topicName, subId, SubscriptionState::OFFLINE);
std::cout << getSubscriptionResult.GetComment() << std::endl;
}
catch(const DatahubException& e)
{
std::cerr << "Update sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}
Update subscription status
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
topicName |
string |
The name of the topic. |
|
subId |
string |
Sample code
void UpdateSubscriptionState()
{
try
{
client.UpdateSubscriptionState(projectName, topicName, subId, SubscriptionState::OFFLINE);
std::cout << getSubscriptionResult.GetComment() << std::endl;
}
catch(const DatahubException& e)
{
std::cerr << "Update sub fail: " << e.GetRequestId() << ", ErrorCode: " << e.GetErrorCode() << ", ErrorMessage: " << e.GetErrorMessage() << std::endl;
}
}