Skip to main content

Overview

info

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.

caution

You can only access resources within the project associated with the issued access key.

  1. Go to KakaoCloud console > User profile > Credentials > IAM access keys.

  2. 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:

  1. Install Go 1.25 or later, then download the Go SDK using the following commands.

    Download Go Package
    wget 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-go without a /v2 suffix, use v0.0.0 as the local module placeholder and resolve it through replace to the downloaded directory.

    go.mod file result
    module ...

    require (
    pubsub-sdk-go v0.0.0
    )
    replace pubsub-sdk-go => {pubsub-sdk-path}
  2. Refer to Get IAM access key to issue credentials. The SDK authenticates with user access keys. Set the access key ID as CredentialID and the secret access key as CredentialSecret in the AccessKey type, as shown below.

    Example using credentials
    accessKey := pubsub.AccessKey{CredentialID: "credentialID", CredentialSecret: "credentialSecret"}
    opts := []option.ClientOption{
    option.WithAccessKey(accessKey),
    }
    client, err := pubsub.NewClient(ctx, opts...)
caution

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.

caution

Since the Client object must release resources such as threads, you must ensure that the Close() method is called.

Close()​
func (c *Client) Close() error
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.

sample. option customizing
opts := []option.ClientOption{
option.WithEndpoint("{endpoint-url}:443"),
}
client, err := pubsub.NewClient(ctx, opts...)