Overview
You can create and delete topics and subscriptions through the KakaoCloud console, API, or SDK.
Prerequisites
To use the SDK provided by Pub/Sub, the following prerequisites must be completed.
Get IAM access key
To obtain a user authentication token (API authentication token), you must first get an access key, then retrieve the access key ID and secret access key.
You can only access resources within the project associated with the issued access key.
-
Go to KakaoCloud console > User profile > Credentials > IAM access keys.
-
After issuing the user Access key, refer to API Preparation to retrieve the access key ID and secret access key.
Go SDK requirements
To use the Go SDK, you must meet the following requirements:
-
Install Go 1.25 or later, then download the Go SDK using the following commands.
Download Go Packagewget https://objectstorage.kr-central-2.kakaocloud.com/v1/e9130193fc734337b2b0c1da50e44395/pubsub-sdk/go/v2.0.0/pubsub.tgz
tar -xf pubsub.tgz
cd {your-project}
go mod edit -require pubsub-sdk-go@v0.0.0
go mod edit -replace pubsub-sdk-go={pubsub-sdk-path}The downloaded SDK is release 2.0.0. Because its module path is
pubsub-sdk-gowithout a/v2suffix, usev0.0.0as the local module placeholder and resolve it throughreplaceto the downloaded directory.go.mod file resultmodule ...
require (
pubsub-sdk-go v0.0.0
)
replace pubsub-sdk-go => {pubsub-sdk-path} -
Refer to Get IAM access key to issue credentials. The SDK authenticates with user access keys. Set the access key ID as
CredentialIDand the secret access key asCredentialSecretin theAccessKeytype, as shown below.Example using credentialsaccessKey := pubsub.AccessKey{CredentialID: "credentialID", CredentialSecret: "credentialSecret"}
opts := []option.ClientOption{
option.WithAccessKey(accessKey),
}
client, err := pubsub.NewClient(ctx, opts...)
You can only access resources within the project associated with the issued access key.
Client
An object used to manage topics and subscriptions, as well as to send and receive messages.
Since the Client object must release resources such as threads, you must ensure that the Close() method is called.
Close()
import (
"context"
"fmt"
"pubsub-sdk-go"
)
func test() error {
ctx := context.Background()
client, err := pubsub.NewClient(ctx)
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, opts...)