Overview
The creation and deletion of topics and subscriptions are only available via the KakaoCloud Console.
Prerequisites
To use the SDK provided by Pub/Sub, the following prerequisites must be completed.
Get access key
To obtain a user authentication token (API authentication token), you must first get an access key, then generate an access key ID and a secret access key.
You can only access resources within the project associated with the issued access key.
-
Get an access key using your credentials in the KakaoCloud Console > User profile > Access key tab.
-
After issuing the user Access key, refer to API Preparation to generate the Access key ID and secret access key.
Go SDK requirements
To use the Go SDK, you must meet the following requirements:
-
Download Go Package (1.19 or later).
Download Go Packagewget https://objectstorage.kr-central-2.kakaocloud.com/v1/e9130193fc734337b2b0c1da50e44395/pubsub-sdk/go/v1.0.0/pubsub.tgz
tar -xf pubsub.tgz
cd {your-project}
go mod edit -require github.kakaoenterprise.in/cloud-platform/kc-pub-sub-sdk-go@v1.0.0
go mod edit -replace github.kakaoenterprise.in/cloud-platform/kc-pub-sub-sdk-go@v1.0.0={pubsub-sdk-path}go.mod file resultmodule ...
require (
github.kakaoenterprise.in/cloud-platform/kc-pub-sub-sdk-go v1.0.0
)
replace github.kakaoenterprise.in/cloud-platform/kc-pub-sub-sdk-go v1.0.0 => {pubsub-sdk-path} -
Refer to Get access key to generate credentials keys. By default, the SDK uses Access keys for authentication. Authentication utilizes the
CredentialsProvider
type, and typically,DefaultCredentialsProvider
is configured withcredential-id
andcredential-secret
as follows:Example using credentialsaccessKey := pubsub.AccessKey{CredentialID: "credentialID", CredentialSecret: "credentialSecret"}
opts := []option.ClientOption{
option.WithAccessKey(accessKey),
}
client, err := pubsub.NewClient(ctx, domainID, projectID, opts...)
You can only access resources within the project associated with the issued access key.
Therefore, when making API calls, the domain and project must be set using the information included with the issued access key.
Client
An object used to manage topics and subscriptions, as well as to send and receive messages.
The following information is used to manage topics and subscriptions, and to send and receive messages:
- domainID
- projectID
Since the Client object must release resources such as threads, you must ensure that the close() method is called.
close()
import (
"context"
"fmt"
"github.kakaoenterprise.in/cloud-platform/kc-pub-sub-sdk-go"
)
func test(domainID, projectID, name string) error {
ctx := context.Background()
client, err := pubsub.NewClient(ctx, domainID, projectID)
if err != nil {
return fmt.Errorf("pubsub.NewClient: %v", err)
}
// do something
err = client.Close()
return err
}
Custom configuration values
Values such as authentication and endpoints for the Client are managed through ClientOption
.
When creating a Client object, you can generate a ClientOption
directly to configure custom values.
opts := []option.ClientOption{
option.WithEndpoint("{endpoint-url}:443"),
}
client, err := pubsub.NewClient(ctx, domainID, projectID, opts...)