Subscription operations
You can create, delete, query, list, and update subscriptions using the DataHub Go SDK.
Create a subscription
Parameters
|
Name |
Type |
Description |
|
projectName |
string |
The project name. |
|
topicName |
string |
The topic name. |
|
comment |
string |
The subscription comment. |
Error descriptions
|
Class name |
Error code |
Description |
|
ResourceNotFoundError |
|
The requested resource does not exist. This error may occur if you send another request immediately after a Split/Merge operation. |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Code example
func createSubscription() {
csr, err := dh.CreateSubscription(projectName, topicName, "sub comment")
if err != nil {
fmt.Println("create subscription failed")
fmt.Println(err)
return
}
fmt.Println("create subscription successful")
fmt.Println(*csr)
}
Delete a subscription
Parameters
|
Name |
Type |
Description |
|
projectName |
string |
The project name. |
|
topicName |
string |
The topic name. |
|
subId |
string |
The ID of the subscription. |
Error descriptions
|
Class name |
Error code |
Description |
|
ResourceNotFoundError |
|
The requested resource does not exist. This error may occur if you send another request immediately after a Split/Merge operation. |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Code example
func delSubscription(dh datahub.DataHub, projectName, topicName string) {
subId := "1565577384801DCN0O"
if err := dh.DeleteSubscription(projectName, topicName, subId); err != nil {
fmt.Println("delete subscription failed")
return
}
fmt.Println("delete subscription successful")
}
Query a subscription
Parameters
|
Name |
Type |
Description |
|
projectName |
string |
The project name. |
|
topicName |
string |
The topic name. |
|
subId |
string |
The ID of the subscription. |
Response example
type GetSubscriptionResult struct {
SubscriptionEntry
}
Error descriptions
|
Class name |
Error code |
Description |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Code example
func getSubscription(dh datahub.DataHub, projectName, topicName string) {
subId := "1565577384801DCN0O"
gs, err := dh.GetSubscription(projectName, topicName, subId)
if err != nil {
fmt.Println("get subscription failed")
fmt.Println(err)
return
}
fmt.Println("get subscription successful")
fmt.Println(gs)
}
List subscriptions
Retrieve a list of subscriptions by specifying pageIndex and pageSize.
-
pageIndex = 1, pageSize = 10returns subscriptions 1–10. -
pageIndex = 2, pageSize = 5returns subscriptions 6–10.
Parameters
|
Class name |
Error code |
Description |
|
projectName |
string |
The project name. |
|
topicName |
string |
The topic name. |
|
pageIndex |
int |
The page index to start the listing from. |
|
pageSize |
int |
The number of subscriptions per page. |
Response example
type ListSubscriptionResult struct {
TotalCount int64 `json:"TotalCount"`
Subscriptions []SubscriptionEntry `json:"Subscriptions"`
}
Error descriptions
|
Class name |
Error code |
Description |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Code example
func listSubscription(dh datahub.DataHub, projectName, topicName string) {
pageIndex := 1
pageSize := 5
ls, err := dh.ListSubscription(projectName, topicName, pageIndex, pageSize)
if err != nil {
fmt.Println("get subscription list failed")
fmt.Println(err)
return
}
fmt.Println("get subscription list successful")
for _, sub := range ls.Subscriptions {
fmt.Println(sub)
}
}
Update a subscription
Parameters
|
Name |
Type |
Description |
|
projectName |
string |
The project name. |
|
topicName |
string |
The topic name. |
|
subId |
string |
The ID of the subscription. |
|
comment |
string |
The subscription comment. |
Error descriptions
|
Class name |
Error code |
Description |
|
ResourceNotFoundError |
|
The requested resource does not exist. This error may occur if you send another request immediately after a Split/Merge operation. |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Sample code
func updateSubscription(dh datahub.DataHub, projectName, topicName string) {
subId := "1565580329258VXSY8"
if err := dh.UpdateSubscription(projectName, topicName, subId, "new sub comment"); err != nil {
fmt.Println("update subscription comment failed")
fmt.Println(err)
return
}
fmt.Println("update subscription comment successful")
}
Update subscription status
Parameters
|
Parameter |
Type |
Description |
|
projectName |
String |
The project name. |
|
topicName |
string |
The topic name. |
|
subId |
string |
The ID of the subscription. |
|
state |
SubscriptionState |
The desired state to apply to the subscription. |
Error descriptions
|
Class name |
Error code |
Description |
|
ResourceNotFoundError |
|
The requested resource does not exist. This error may occur if you send another request immediately after a Split/Merge operation. |
|
AuthorizationFailedError |
|
Failed to parse the authorization signature. Check whether the AccessKey is valid. |
|
InvalidParameterError |
|
Invalid parameters. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Code example
func updateSubState(dh datahub.DataHub, projectName, topicName string) {
subId := "1565580329258VXSY8"
if err := dh.UpdateSubscriptionState(projectName, topicName, subId, datahub.SUB_OFFLINE); err != nil {
fmt.Println("update subscription state failed")
fmt.Println(err)
return
}
fmt.Println("update subscription state successful")
}