Skip to main content

SDK Overview

Preparation

To use the SDK provided by Pub/Sub, you must perform the following pre-work.

Issue access key

To obtain a user authentication token (API authentication token), first obtain an access key, then issue an access key ID and a security access key.

caution

You can only access resources belonging to the project for which you have been issued an access key.

  1. Issue an access key using your credentials in the KakaoCloud Console > User Profile (Top right) > Access Key tab.

  2. After issuing the user access key, refer to the API Preparations to issue an access key ID and a security access key.

SDK requirements

To use SDK Java, you must meet the following prerequisites:

  1. Check JDK, Java version.

    • JDK 1.8 or higher
    • Java 8 or higher
  2. Add SDK Dependency.

    Download jar file
    $ wget https://objectstorage.kr-central-1.kakaocloud.com/v1/e9130193fc734337b2b0c1da50e44395/pub-sub-java-sdk/v0.1.5/kc-pub-sub-0.1.5.jar

    # Then move to the libs folder of the project you want to use.
    $ mkdir {your-project}/libs
    $ mv kc-pub-sub-0.1.5.jar {your-project}/libs
    Maven(pom.xml)
    <repositories>
    <repository>
    <id>java-pubsub</id>
    <url>file://${project.basedir}/libs/kc-pub-sub-0.1.5.jar</url>
    </repository>
    </repositories>

    <dependencies>
    <dependency>
    <groupId>com.kakaocloud.pubsub</groupId>
    <artifactId>kc-pub-sub</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/kc-pub-sub-0.1.5.jar</systemPath>
    </dependency>
    </dependencies>
    Gradle(build.gradle)
    dependencies {
    implementation files("$rootProject.projectDir/libs/kc-pub-sub-0.1.5.jar")
    }
    info

    For versions prior to kc-pub-sub-0.1.5.jar, the token server needs to be changed as follows.

    DefaultCredentialsProvider.newBuilder()
    .setTokenServerUri("https://iam.kakaocloud.com")
    .build();

    PublisherStubSettings settings = PublisherStubSettings.newBuilder()
    .setCredentialsProvider(provider)
    .build();

    SubscriberStubSettings settings = SubscriberStubSettings.newBuilder()
    .setCredentialsProvider(provider)
    .build();
  3. Refer to [Issue Access Key](#Issue Access Key) to obtain a Credentials key. By default, the SDK attempts authentication using the access key. Authentication uses the CredentialsProvider type, and by default, credential-id and credential-secret are set in DefaultCredentialsProvider as follows.

    Example using Credentials key
    DefaultCredentialsProvider provider = DefaultCredentialsProvider.newBuilder()
    .setCredentialId("credentialId")
    .setCredentialSecret("credentialSecret")
    .build()

    PublisherStubSettings settings = PublisherStubSettings.newBuilder()
    .setCredentialsProvider(provider)
    .build();

    TopicAdminClient topicAdminClient = TopicAdminClient.create(settings);

Client

This is an object used to manipulate topics and subscriptions and to send and receive messages.

caution

The Client object must release resources such as threads, so the close() method must be called.

Custom settings

When creating a Client object, the user can arbitrarily set values ​​such as authentication and call endpoint.

Sample. endpoint customizing
PublisherStubSettings settings =
PublisherStubSettings.newBuilder()
.setEndpoint("{endpoint-url}:10443")
.build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(settings);

SubscriberStubSettings settings =
SubscriberStubSettings.newBuilder()
.setEndpoint("{endpoint-url}:10443")
.build();
SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create(settings);