Skip to main content

SDK overview

Preparation

Pub/Sub currently supports Go SDK. To use Go SDK, complete the following prerequisites.

Get access key

To obtain user authentication token (API authentication token), first get an access key and then retrieve access key ID and secret access key.

caution

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

  1. Create an access key for user credentials in kakao cloud console > User profile > Access key tab.

  2. After issuing user Access key, refer to Prepare API usage to retrieve Access key ID and secret access key.

SDK requirements

Use Go SDK

Ensure the following requirements are met to use Go SDK.

info

SDK specifications differ between kr-central-1 and kr-central-2 regions. Download the package for the respective region.

  1. Download Go package (1.19 or later).

    Download Go package
    wget 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 results
    module ...

    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}
  2. Refer to Get access key to generate credentials. By default, the SDK attempts to authenticate using Access keys. Authentication uses the CredentialsProvider type, typically configured with DefaultCredentialsProvider as shown below:

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

You can only access resources within the project associated with issued access key.
When calling APIs, set domain and project to match the issued access key's information.

Client

Use client objects to manage topics and subscriptions, send messages, and receive messages.

caution

You must release resources like threads used by the client object by calling the close() method.

Configure custom settings

When creating a client object, you can customize values such as authentication and endpoint settings.

info

The default endpoint is set to the kr-central-2 region's endpoint. Change the endpoint when using kr-central-1.

Client example
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
}
sample. option customizing
opts := []option.ClientOption{
option.WithEndpoint("{endpoint-url}:443"),
}
client, err := pubsub.NewClient(ctx, domainID, projectID, opts...)