Skip to main content

Method list

Preparation and requirements

For pre-work and requirements for using Pub/Sub Java SDK, please refer to the Overview.

Method types

  • Flatten Method

    • This method takes the values ​​required to create a Default Request as parameters. Not all fields corresponding to the request can be used. To use all fields, you must use the Default Request method.
  • Default Request Method

    • This method takes the request object required when calling the API as a parameter.
  • Callable Method

    • A method that can call the gRPC API asynchronously. It takes the Default Request as a parameter.

Topic

Retrieve topic

You can retrieve topics using the items below.

Method
TypeMethodDescription
TopicgetTopic(GetTopicRequest request)
TopicgetTopic(ProjectTopic topic)
UnaryCallable<GetTopicRequest, Topic>getTopicCallable()Retrieve topics asynchronously
Parameters

com.kakaocloud.pubsub.v1.GetTopicRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringtopicOTopic 명
Example
public Topic getTopic(GetTopicRequest request)
import com.kakaocloud.pubsub.v1.GetTopicRequest;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class GetTopicExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

getTopic(domainId, projectId, topicName);
}

private static void getTopic(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setTopic(topicName)
.build();

Topic topic = topicAdminClient.getTopic(request);
}
}
}
public Topic getTopic(ProjectTopic topic)
import com.kakaocloud.pubsub.v1.ProjectTopic;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class GetTopicExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

getTopic(domainId, projectId, topicName);
}

private static void getTopic(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopic projectTopic = ProjectTopic.of(domainId, projectId, topicName);

Topic topic = topicAdminClient.getTopic(projectTopic);
}
}
}
public UnaryCallable<GetTopicRequest, Topic> getTopicCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.GetTopicRequest;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class GetTopicExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

getTopic(domainId, projectId, topicName);
}

private static void getTopic(String domainId, String projectId, String topicName)
throws IOException, ExecutionException, InterruptedException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setTopic(topicName)
.build();

ApiFuture<Topic> futureCall = topicAdminClient.getTopicCallable().futureCall(request);

Topic response = futureCall.get();
}
}
}

Retrieve topic list

Retrieves the topic list within the project.

Method
TypeMethodDescription
ListTopicsPagedResponselistTopics(ListTopicsRequest request)
ListTopicsPagedResponselistTopics(Project project)
UnaryCallable<ListTopicsRequest, ListTopicsPagedResponse>listTopicsPagedCallable()Retrieves a list of topics asynchronously
Parameters

com.kakaocloud.pubsub.v1.ListTopicsRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
intpageSizeNumber of lists to view at once
StringpageTokenVariable to load the next list

com.kakaocloud.pubsub.v1.Project

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringnameOProject name

Example

public ListTopicsPagedResponse listTopics(ListTopicsRequest request)
import com.kakaocloud.pubsub.v1.ListTopicsRequest;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class ListTopicsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listTopics(domainId, projectId);
}

private static void listTopics(String domainId, String projectId) throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest request =
ListTopicsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setPageSize(1)
.setPageToken("page-token")
.build();

topicAdminClient.listTopics(request).iterateAll()
.forEach(
topic -> {
System.out.println(topic);
}
);
}
}
}
public ListTopicsPagedResponse listTopics(Project project)
import com.kakaocloud.pubsub.v1.Project;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class ListTopicsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listTopics(domainId, projectId);
}

private static void listTopics(String domainId, String projectId) throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Project project = Project.of(domainId, projectId);

topicAdminClient.listTopics(project).iterateAll()
.forEach(
topic -> {
System.out.println(topic);
}
);
}
}
}
public UnaryCallable<ListTopicsRequest, ListTopicsPagedResponse> listTopicsPagedCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.ListTopicsPagedResponse;
import com.kakaocloud.pubsub.v1.ListTopicsRequest;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class ListTopicsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listTopics(domainId, projectId);
}

private static void listTopics(String domainId, String projectId)
throws IOException, ExecutionException, InterruptedException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest request =
ListTopicsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setPageSize(1)
.setPageToken("page-token")
.build();

ApiFuture<ListTopicsPagedResponse> futureCall =
topicAdminClient.listTopicsPagedCallable().futureCall(request);

futureCall.get().iterateAll()
.forEach(
topic -> {
System.out.println(topic);
}
);
}
}

Retrieve subscription list of topic

Retrieve the subscription list for a specific topic.

Method
TypeMethodDescription
ListTopicSubscriptionsPagedResponselistTopicSubscriptions(ListTopicSubscriptionsRequest request)
ListTopicSubscriptionsPagedResponselistTopicSubscriptions(ProjectTopic projectTopic)
UnaryCallable<ListTopicSubscriptionsRequest,
ListTopicSubscriptionsPagedResponse>
listTopicSubscriptionsPagedCallable()Retrieves the list of subscriptions for a topic asynchronously.
Parameters

com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringtopicOTopic name
intpageSizeNumber of lists to view at once
StringpageTokenVariable to load the next list

com.kakaocloud.pubsub.v1.ProjectTopic

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOTopic name

Example

ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ListTopicSubscriptionsRequest request)
import com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class ListTopicSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

listTopicSubscriptions(domainId, projectId, topicName);
}

private static void listTopicSubscriptions(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setTopic(topicName)
.build();

topicAdminClient.listTopicSubscriptions(request).iterateAll()
.forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}
public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ProjectTopic projectTopic)
import com.kakaocloud.pubsub.v1.ProjectTopic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;

public class ListTopicSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

listTopicSubscriptions(domainId, projectId, topicName);
}

private static void listTopicSubscriptions(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopic projectTopic = ProjectTopic.of(domainId, projectId, topicName);

topicAdminClient.listTopicSubscriptions(projectTopic).iterateAll()
.forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}
UnaryCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsPagedResponse>listTopicSubscriptionsPagedCallable()
public class ListTopicSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

listTopicSubscriptions(domainId, projectId, topicName);
}

private static void listTopicSubscriptions(String domainId, String projectId, String topicName)
throws IOException, ExecutionException, InterruptedException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setTopic(topicName)
.build();

ApiFuture<ListTopicSubscriptionsPagedResponse> futureCall =
topicAdminClient.listTopicSubscriptionsPagedCallable().futureCall(request);

futureCall.get().iterateAll()
.forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}

Modify topic

You can modify the retention period and description of a specific topic.

Method
TypeMethodDescription
TopicupdateTopic(UpdateTopicRequest request)
TopicupdateTopic(ProjectTopic topic, Duration messageRetentionDuration)
UnaryCallable<UpdateTopicRequest, Topic>updateTopicCallable()Modify topic asynchronously
Parameters

com.kakaocloud.pubsub.v1.UpdateTopicRequest

TypeFieldRequiredDescription
TopictopicO   Object containing information about the topic to be created
FieldMaskupdateMaskBuilderOFields of the item to be updated

com.kakaocloud.pubsub.v1.Topic

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOTopic name
DurationmessageRetentionDurationMessage retention period
StringdescriptionTopic description

com.google.protobuf.Duration, Timestamp

TypeFieldRequiredDescription
intnanosMessage retention cycle Nanos
longsecondsO   Message retention cycle Seconds

com.kakaocloud.pubsub.v1.ProjectTopic

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOTopic name
Example
public Topic updateTopic(UpdateTopicRequest request)
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import com.kakaocloud.pubsub.v1.UpdateTopicRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class UpdateTopicExample {
public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

updateTopic(domainId, projectId, topicName);
}

private static void updateTopic(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder()
.setTopic(
Topic.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setName(topicName)
.setMessageRetentionDuration(
Duration.newBuilder()
.setSeconds(864000)
.build())
.setDescription("new description")
.build())
.setUpdateMask(
FieldMask.newBuilder()
.addPaths(
Topic.getDescriptor()
.findFieldByNumber(Topic.MESSAGE_RETENTION_DURATION_FIELD_NUMBER)
.getName())
.addPaths(
Topic.getDescriptor()
.findFieldByNumber(Topic.DESCRIPTION_FIELD_NUMBER)
.getName())
.build())
.build();

Topic topic = topicAdminClient.updateTopic(request);
}
}
}
public Topic updateTopic( ProjectTopic topic, Duration messageRetentionDuration)
import com.google.protobuf.Duration;
import com.kakaocloud.pubsub.v1.ProjectTopic;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class UpdateTopicExample {
public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

updateTopic(domainId, projectId, topicName);
}

private static void updateTopic(String domainId, String projectId, String topicName)
throws IOException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopic projectTopic = ProjectTopic.of(domainId, projectId, topicName);

Duration newDuration = Duration.newBuilder()
.setSeconds(864000)
.build();

Topic topic = topicAdminClient.updateTopic(projectTopic, newDuration);
}
}
}
public UnaryCallable<UpdateTopicRequest, Topic> updateTopicCallable()
import com.google.api.core.ApiFuture;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.kakaocloud.pubsub.v1.Topic;
import com.kakaocloud.pubsub.v1.TopicAdminClient;
import com.kakaocloud.pubsub.v1.UpdateTopicRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class UpdateTopicExample {
public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

updateTopic(domainId, projectId, topicName);
}

private static void updateTopic(String domainId, String projectId, String topicName)
throws IOException, ExecutionException, InterruptedException {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder()
.setTopic(
Topic.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setName(topicName)
.setMessageRetentionDuration(
Duration.newBuilder()
.setSeconds(864000)
.build())
.setDescription("new description")
.build())
.setUpdateMask(
FieldMask.newBuilder()
.addPaths(
Topic.getDescriptor()
.findFieldByNumber(Topic.MESSAGE_RETENTION_DURATION_FIELD_NUMBER)
.getName())
.addPaths(
Topic.getDescriptor()
.findFieldByNumber(Topic.DESCRIPTION_FIELD_NUMBER)
.getName())
.build())
.build();

ApiFuture<Topic> futureCall = topicAdminClient.updateTopicCallable().futureCall(request);

Topic topic = futureCall.get();
}
}
}

Subscription

Object - SubscriptionAdminClient

com.google.cloud.pubsub.v1.SubscriptionAdminClient

An object used to manipulate subscriptions and read messages.

Sample
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// Do Something
}
caution

The SubscriptionAdminClient object must release resources such as threads, so the close() method must be called.
If you use try-with-resources, as in the sample code, it will automatically release them.


Retrieve subscription

Retrieve information for a specific subscription.

Method
TypeMethodDescription
SubscriptiongetSubscription(GetSubscriptionRequest request)
SubscriptiongetSubscription(ProjectSubscription subscription)
UnaryCallable<GetSubscriptionRequest, Subscription>getSubscriptionCallable()Retrieve a subscription asynchronously.
Parameters

com.kakaocloud.pubsub.v1.GetSubscriptionRequest

TypeFieldRequired or notDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequiredDescription
StringdomainYesDomain ID
StringprojectYesProject ID
StringnameYesSubscription name
Example
public Subscription getSubscription(GetSubscriptionRequest request)
GetSubscriptionRequest request)
import com.kakaocloud.pubsub.v1.GetSubscriptionRequest;
import com.kakaocloud.pubsub.v1.Subscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class GetSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

getSubscription(domainId, projectId, subscriptionName);
}

private static void getSubscription(
String domainId, String projectId, String subscriptionName) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
GetSubscriptionRequest request =
GetSubscriptionRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.build();

Subscription subscription = subscriptionAdminClient.getSubscription(request);
}
}
}
public Subscription getSubscription(ProjectSubscription subscription)
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.Subscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class GetSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

getSubscription(domainId, projectId, subscriptionName);
}

private static void getSubscription(
String domainId, String projectId, String subscriptionName) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscription projectSubscription =
ProjectSubscription.of(domainId, projectId, subscriptionName);

Subscription subscription = subscriptionAdminClient.getSubscription(projectSubscription);
}
}
}
public UnaryCallable<GetSubscriptionRequest, Subscription>getSubscriptionCallable()
public class GetSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

getSubscription(domainId, projectId, subscriptionName);
}

private static void getSubscription(
String domainId, String projectId, String subscriptionName)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
GetSubscriptionRequest request =
GetSubscriptionRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.build();

ApiFuture<Subscription> futureCall =
subscriptionAdminClient.getSubscriptionCallable().futureCall(request);

Subscription subscription = futureCall.get();
}
}
}

Retrieve subscription list

Retrieve the subscription list within the project.

Method
TypeMethodDescription
ListSubscriptionsPagedResponselistSubscriptions(ListSubscriptionsRequest request)
ListSubscriptionsPagedResponselistSubscriptions(Project project)
UnaryCallable<ListSubscriptionsRequest,
ListSubscriptionsPagedResponse>
listSubscriptionsPagedCallable()Retrieve the list of subscriptions asynchronously.
Parameters

com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID

com.kakaocloud.pubsub.v1.Project

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
Example
public ListSubscriptionsPagedResponse listSubscriptions(ListSubscriptionsRequest request)
import com.kakaocloud.pubsub.v1.ListSubscriptionsRequest;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class ListSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listSubscriptions(domainId, projectId);
}

private static void listSubscriptions(String domainId, String projectId)
throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ListSubscriptionsRequest request =
ListSubscriptionsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.build();

subscriptionAdminClient.listSubscriptions(request).iterateAll()
.forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}
public ListSubscriptionsPagedResponse listSubscriptions(Project project)
import com.kakaocloud.pubsub.v1.Project;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class ListSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listSubscriptions(domainId, projectId);
}

private static void listSubscriptions(String domainId, String projectId)
throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
Project project = Project.of(domainId, projectId);

subscriptionAdminClient.listSubscriptions(project).iterateAll()
.forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}
public UnaryCallable<ListSubscriptionsRequest, ListSubscriptionsPagedResponse> listSubscriptionsPagedCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.ListSubscriptionsPagedResponse;
import com.kakaocloud.pubsub.v1.ListSubscriptionsRequest;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class ListSubscriptionsExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";

listSubscriptions(domainId, projectId);
}

private static void listSubscriptions(String domainId, String projectId)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ListSubscriptionsRequest request =
ListSubscriptionsRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.build();

ApiFuture<ListSubscriptionsPagedResponse> futureCall =
subscriptionAdminClient.listSubscriptionsPagedCallable().futureCall(request);

ListSubscriptionsPagedResponse response = futureCall.get();
response.iterateAll().forEach(
subscription -> {
System.out.println(subscription);
}
);
}
}
}

Modify subscription

Modify a subscription.

Method
TypeMethodDescription
SubscriptionupdateSubscription(UpdateSubscriptionRequest request)
SubscriptionupdateSubscription( ProjectSubscription subscription,
PushConfig pushConfig, int ackDeadlineSeconds)
UnaryCallable<UpdateSubscriptionRequest, Subscription>updateSubscriptionCallable()Modify subscription to asynchronous
Parameters

com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest

TypeFieldRequiredDescription
SubscriptionsubscriptionO   Object containing information about the subscription side to be created
FieldMaskupdateMaskOFields of the item to be updated

com.kakaocloud.pubsub.v1.Subscription

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name
PushConfigpushConfig   Message push settings
intackDeadlineSecondsMessage acknowledgement deadline (seconds)
- Default: 10
DurationmessageRetentionDurationMessage retention period
intmaxDeliveryAttemptMaximum number of delivery attempts
- Default: -1(infinite)

com.kakaocloud.pubsub.v1.PushConfig

TypeFieldRequiredDescription
StringpushEndpointO    Push endpoint
intpushBatchSizePush batch size
- Default: 0

com.google.protobuf.Duration, Timestamp

TypeFieldRequiredDescription
longsecondsO   Message retention period (Seconds)
intnanosMessage retention period (Nanos)

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequired or notDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription people
Example
public Subscription updateSubscription(UpdateSubscriptionRequest request)
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.kakaocloud.pubsub.v1.DescriptorUtils;
import com.kakaocloud.pubsub.v1.Subscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest;
import java.io.IOException;

public class UpdateSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

updateSubscription(domainId, projectId, subscriptionName);
}

private static void updateSubscription(
String domainId, String projectId, String subscriptionName) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
UpdateSubscriptionRequest request =
UpdateSubscriptionRequest.newBuilder()
.setSubscription(
Subscription.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setName(subscriptionName)
.setMessageRetentionDuration(
Duration.newBuilder()
.setSeconds(10)
.build())
.build())
.setUpdateMask(
FieldMask.newBuilder()
.addPaths(
DescriptorUtils.findSubscriptionFieldNameByNumber(
Subscription.MESSAGE_RETENTION_DURATION_FIELD_NUMBER))
.build())
.build();

Subscription subscription = subscriptionAdminClient.updateSubscription(request);
}
}
}
public Subscription updateSubscription( ProjectSubscription subscription, PushConfig pushConfig, int ackDeadlineSeconds)
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.Subscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class UpdateSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

updateSubscription(domainId, projectId, subscriptionName);
}

private static void updateSubscription(
String domainId, String projectId, String subscriptionName) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscription projectSubscription =
ProjectSubscription.of(domainId, projectId, subscriptionName);

int ackDeadlineSeconds = 100;

Subscription subscription = subscriptionAdminClient.updateSubscription(
projectSubscription,
null,
ackDeadlineSeconds
);
}
}
}
public UnaryCallable<UpdateSubscriptionRequest, Subscription>updateSubscriptionCallable()
import com.google.api.core.ApiFuture;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.kakaocloud.pubsub.v1.DescriptorUtils;
import com.kakaocloud.pubsub.v1.Subscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class UpdateSubscriptionExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

updateSubscription(domainId, projectId, subscriptionName);
}

private static void updateSubscription(
String domainId, String projectId, String subscriptionName)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
UpdateSubscriptionRequest request =
UpdateSubscriptionRequest.newBuilder()
.setSubscription(
Subscription.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setName(subscriptionName)
.setMessageRetentionDuration(
Duration.newBuilder()
.setSeconds(10)
.build())
.build())
.setUpdateMask(
FieldMask.newBuilder()
.addPaths(
DescriptorUtils.findSubscriptionFieldNameByNumber(
Subscription.MESSAGE_RETENTION_DURATION_FIELD_NUMBER))
.build())
.build();

ApiFuture<Subscription> futureCall =
subscriptionAdminClient.updateSubscriptionCallable().futureCall(request);

Subscription subscription = futureCall.get();
}
}
}

Rewind subscription time

You can rewind the subscription point to a specified time and receive messages again after the specified time.

Method
TypeMethodDescription
Emptyseek(SeekRequest request)
UnaryCallable<SeekRequest, Empty>Modify the acknowledgement deadline to asynchronous
Parameters

com.kakaocloud.pubsub.v1.SeekRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringsubscriptionOSubscription name
TimestamptimeOTime to roll back

com.google.protobuf.Duration, Timestamp

TypeFieldRequiredDescription
longsecondsO   Time to roll back (Seconds)
intnanosTime to roll back (Nanos)
Example
public Empty seek(SeekRequest request)
import com.google.protobuf.Timestamp;
import com.kakaocloud.pubsub.v1.SeekRequest;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class SeekExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";
Timestamp seekTime = Timestamp.newBuilder()
.setSeconds(1691650590)
.build()

seek(domainId, projectId, subscriptionName, seekTime);
}

private static void seek(
String domainId, String projectId, String subscriptionName, Timestamp seekTime) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SeekRequest request =
SeekRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setTime()
.build();

subscriptionAdminClient.seek(request);
}
}
}
public UnaryCallable<SeekRequest, Empty> seekCallable()
import com.google.api.core.ApiFuture;
import com.google.protobuf.Timestamp;
import com.kakaocloud.pubsub.v1.SeekRequest;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class SeekExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";
Timestamp seekTime = Timestamp.newBuilder()
.setSeconds(1691650590)
.build()

seek(domainId, projectId, subscriptionName, seekTime);
}

private static void seek(
String domainId, String projectId, String subscriptionName, Timestamp seekTime)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SeekRequest request =
SeekRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setTime()
.build();

ApiFuture<Empty> futureCall =
subscriptionAdminClient.seekCallable().futureCall(request);

futureCall.get();
}
}
}

Publish message

Object - Publisher

com.kakaocloud.pubsub.v1.Publisher

An object used when publishing messages to a topic.

Sample
ProjectTopic topic = ProjectTopic.of(domainId, projectId, topicName);
Publisher publisher = null;

try {
publisher = Publisher.newBuilder(topic).build();

// Do Something

} finally {
if (publisher != null) {
publisher.runShutdown();
publisher.awaitTermination(1, TimeUnit.MINUTES);
}
}
Custom settings

When creating a Publisher object, users can set their own settings.

sample. endpoint customizing
publisher = Publisher.newBuilder(topic)
.setEndpoint("your-endpoint")
.build();
Method
TypeMethodDescription
ApiFuture<String>publish(PublishMessage message)Process message publishing asynchronously
Parameters

com.kakaocloud.pubsub.v1.PublishMessage

TypeFieldDescription
StringdataMessage content
⚠️ Must be encoded in Base64.
Example
public ApiFuture <String> publish(PublishMessage message)
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.rpc.ApiException;
import com.google.common.util.concurrent.MoreExecutors;
import com.kakaocloud.pubsub.v1.ProjectTopic;
import com.kakaocloud.pubsub.v1.PublishMessage;
import com.kakaocloud.pubsub.v1.Publisher;
import java.io.IOException;
import java.util.Base64;
import java.util.concurrent.TimeUnit;

public class PublishExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String topicName = "your-topic-name";

publish(domainId, projectId, topicName);
}

private static void publish(String domainId, String projectId, String topicName)
throws IOException, InterruptedException {
ProjectTopic topic = ProjectTopic.of(domainId, projectId, topicName);
Publisher publisher = null;

try {
publisher = Publisher.newBuilder(topic).build();

String message = "message";
String data = Base64.getEncoder().encodeToString(message.getBytes());
PublishMessage publishMessage = PublishMessage.newBuilder().setData(data).build();
ApiFuture`<String>` futureCall = publisher.publish(publishMessage);
ApiFutures.addCallback(
futureCall,
new ApiFutureCallback`<String>`() {
@Override
public void onSuccess(String messageId) {
System.out.println("Published message ID: " + messageId);
}

@Override
public void onFailure(Throwable t) {
if (t instanceof ApiException) {
ApiException apiException = ((ApiException) t);
System.out.println(apiException.getStatusCode().getCode());
System.out.println(apiException.isRetryable());
}
System.out.println("Error publishing message : " + message);
}
},
MoreExecutors.directExecutor());
} finally {
if (publisher != null) {
publisher.runShutdown();
publisher.awaitTermination(1, TimeUnit.MINUTES);
}
}
}
}

Receive message

Object - Subscriber

com.kakaocloud.pubsub.v1.Subscriber

This is the object used when subscribing to messages (streaming pull).

Sample
ProjectSubscription subscription = ProjectSubscription.of(domainId, projectId, subscriptionName);
Subscriber subscriber = null;
MessageReceiver receiver = (ReceivedMessage message, AckReplyConsumer consumer) -> {
// Do Something
};

try {
subscriber = Subscriber.newBuilder(subscription, receiver).build();
subscriber.startAsync().awaitRunning();
subscriber.awaitTerminated(15, TimeUnit.MINUTES);
} catch (TimeoutException timeoutException) {
subscriber.stopAsync().awaitTerminated();
}
Custom settings

When creating a Publisher object, users can set their own settings.

Sample. endpoint customizing
subscriber = Subscriber
.newBuilder(subscription, receiver)
.setEndpoint("your-endpoint")
.build();
Parameters

com.kakaocloud.pubsub.v1.MessageReceiver

TypeMethodDescription
voidreceive(final ReceivedMessage message,
final AckReplyConsumer consumer)
Used when you do not need to receive the result after ack(or nack) processing a received message.

com.kakaocloud.pubsub.v1.MessageReceiverWithAckResponse

TypeMethodDescription
voidreceive(final ReceivedMessage message,
final AckReplyConsumerWithResponse consumer)
Used when you need to receive the result after ack(or nack) processing a received message.

com.kakaocloud.pubsub.v1.ReceivedMessage

TypeFieldDescription
StringdataMessage content

com.kakaocloud.pubsub.v1.AckReplyConsumer

TypeMethodDescription
voidack()Processes acknowledge
voidnack()Processes negative acknowledge

com.kakaocloud.pubsub.v1.AckReplyConsumerWithResponse

TypeMethodDescription
Future<AckResponseData>ack()After processing an acknowledgement, receive the result
Future<AckResponseData>nack()After processing a negative acknowledgement, receive the result
Example
void receive(final ReceivedMessage message, final AckConsumer consumer)
import com.kakaocloud.pubsub.v1.AckConsumer;
import com.kakaocloud.pubsub.v1.MessageReceiver;
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.PubsubMessage;
import com.kakaocloud.pubsub.v1.ReceivedMessage;
import com.kakaocloud.pubsub.v1.Subscriber;
import java.io.IOException;
import java.util.Base64;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class StreamingPullExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

streamingPull(domainId, projectId, subscriptionName);
}

private static void streamingPull(
String domainId, String projectId, String subscriptionName) throws IOException {
ProjectSubscription subscription = ProjectSubscription.of(domainId, projectId, subscriptionName);
Subscriber subscriber = null;
MessageReceiver receiver = (ReceivedMessage receivedMessage, AckConsumer consumer) -> {
PubsubMessage message = receivedMessage.getMessage();
System.out.println("Message Id: " + message.getMessageId());
System.out.println("Message Decoded Data: " + new String(Base64.getDecoder().decode(receivedMessage.getMessage().getData())));

consumer.ack();
};

try {
subscriber = Subscriber.newBuilder(subscription, receiver).build();
subscriber.startAsync().awaitRunning();
subscriber.awaitTerminated(15, TimeUnit.MINUTES);
} catch (TimeoutException timeoutException) {
subscriber.stopAsync().awaitTerminated();
}
}
}
void receive( final ReceivedMessage message, final AckConsumerWithResponse consumer)
import com.kakaocloud.pubsub.v1.AckConsumerWithResponse;
import com.kakaocloud.pubsub.v1.AckResponseData;
import com.kakaocloud.pubsub.v1.MessageReceiverWithAckResponse;
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.PubsubMessage;
import com.kakaocloud.pubsub.v1.ReceivedMessage;
import com.kakaocloud.pubsub.v1.Subscriber;
import java.io.IOException;
import java.util.Base64;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class StreamingPullExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

streamingPull(domainId, projectId, subscriptionName);
}

private static void streamingPull(
String domainId, String projectId, String subscriptionName) throws IOException {
ProjectSubscription subscription = ProjectSubscription.of(domainId, projectId, subscriptionName);
Subscriber subscriber = null;
MessageReceiverWithAckResponse receiver =
(ReceivedMessage receivedMessage, AckConsumerWithResponse consumer) -> {
PubsubMessage message = receivedMessage.getMessage();
System.out.println("Message Id: " + message.getMessageId());
System.out.println("Message Decoded Data: " + new String(Base64.getDecoder().decode(receivedMessage.getMessage().toStringUtf8getData())));

try {
AckResponseData ackResponse = consumer.ack().get();

System.out.println("Response Type: " + ackResponse.getResponseType());
System.out.println("Re-issued ack id: " + ackResponse.getReIssuedAckIdIfExists());
System.out.println("Error: " + ackResponse.getErrorIfExists());
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
};

try {
subscriber = Subscriber.newBuilder(subscription, receiver).build();
subscriber.startAsync().awaitRunning();
subscriber.awaitTerminated(15, TimeUnit.MINUTES);
} catch (TimeoutException timeoutException) {
subscriber.stopAsync().awaitTerminated();
}
}
}

Receive message

Receives messages from subscriptions synchronously.

Method
TypeMethodDescription
PullResponsepull(PullRequest request)
UnaryCallable<PullRequest, PullResponse>pullCallable()Process message acknowledgments asynchronously.
Parameters

com.kakaocloud.pubsub.v1.PullRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringsubscriptionOSubscription name
intmaxMessagesOBatch Size

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name
Example
public PullResponse pull(PullRequest request)
import com.kakaocloud.pubsub.v1.PullRequest;
import com.kakaocloud.pubsub.v1.PullResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;

public class PullExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

pull(domainId, projectId, subscriptionName);
}

private static void pull(
String domainId, String projectId, String subscriptionName) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
PullRequest request =
PullRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setMaxMessages(10)
.build();

PullResponse response = subscriptionAdminClient.pull(request);
response.getReceivedMessagesList().forEach(
receivedMessage -> {
System.out.println(receivedMessage);
}
);
}
}
}
public UnaryCallable<PullRequest, PullResponse> pullCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.PullRequest;
import com.kakaocloud.pubsub.v1.PullResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class PullExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

pull(domainId, projectId, subscriptionName);
}

private static void pull(
String domainId, String projectId, String subscriptionName)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
PullRequest request =
PullRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setMaxMessages(10)
.build();

ApiFuture<PullResponse> futureCall =
subscriptionAdminClient.pullCallable().futureCall(request);

PullResponse response = futureCall.get();
}
}
}

Acknowledge message reception

Acknowledge the received message.

Method
TypeMethodDescription
AcknowledgeResponseacknowledge(AcknowledgeRequest request)
AcknowledgeResponseacknowledge(ProjectSubscription subscription, List<String> ackIds)
UnaryCallable<AcknowledgeRequest,
AcknowledgeResponse>
acknowledgeCallable()Process message acknowledgments asynchronously.
Parameters

com.kakaocloud.pubsub.v1.AcknowledgeRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringsubscriptionOSubscription name
ListackIdsOMessage AckID list

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name
Example
public AcknowledgeResponse acknowledge(AcknowledgeRequest request)
import com.kakaocloud.pubsub.v1.AcknowledgeRequest;
import com.kakaocloud.pubsub.v1.AcknowledgeResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

acknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void acknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
AcknowledgeRequest request =
AcknowledgeRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.addAllAckIds(ackIds)
.build();

AcknowledgeResponse response = subscriptionAdminClient.acknowledge(request);
}
}
}
public AcknowledgeResponse acknowledge( ProjectSubscription subscription, List<String> ackIds)
import com.kakaocloud.pubsub.v1.AcknowledgeResponse;
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

acknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void acknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscription subscription =
ProjectSubscription.of(domainId, projectId, subscriptionName);

AcknowledgeResponse response =
subscriptionAdminClient.acknowledge(subscription, ackIds);
}
}
}
public UnaryCallable<AcknowledgeRequest, AcknowledgeResponse> acknowledgeCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.AcknowledgeRequest;
import com.kakaocloud.pubsub.v1.AcknowledgeResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class AcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

acknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void acknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
AcknowledgeRequest request =
AcknowledgeRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.addAllAckIds(ackIds)
.build();

ApiFuture<AcknowledgeResponse> futureCall =
subscriptionAdminClient.acknowledgeCallable().futureCall(request);

AcknowledgeResponse response = futureCall.get();
}
}
}

Process messages as unread

Use the items below to process the received message as unread.

Method
TypeMethodDescription
ModifyAckDeadlineResponsenack(ModifyAckDeadlineRequest request)
ModifyAckDeadlineResponsenack(ProjectSubscription subscription, List<String> acIds)
UnaryCallable<ModifyAckDeadlineRequest,
ModifyAckDeadlineResponse>
nackCallable()Acknowledge messages as unread asynchronously.
Parameters

com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringsubscriptionOSubscription name
StringackActionOAcknowledgement type
- skip
- extend
intackDeadlineSecondsMessage acknowledgement deadline (seconds)
- Default: 10
ListackIdsOMessage AckId list

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name
Example
public ModifyAckDeadlineResponse negativeAcknowledge(ModifyAckDeadlineRequest request
import com.kakaocloud.pubsub.v1.AckAction;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class NegativeAcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

negativeAcknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void negativeAcknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ModifyAckDeadlineRequest request =
ModifyAckDeadlineRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setAckAction(AckAction.SKIP.toRequest())
.addAllAckIds(ackIds)
.build();

ModifyAckDeadlineResponse response = subscriptionAdminClient.nack(request);
}
}
}
public ModifyAckDeadlineResponse negativeAcknowledge( ProjectSubscription subscription, List<String> acIds)
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class NegativeAcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

negativeAcknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void negativeAcknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscription subscription =
ProjectSubscription.of(domainId, projectId, subscriptionName);

ModifyAckDeadlineResponse response =
subscriptionAdminClient.nack(subscription, ackIds);
}
}
}
public UnaryCallable<ModifyAckDeadlineRequest, ModifyAckDeadlineResponse> negativeAcknowledgeCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.AckAction;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class NegativeAcknowledgeExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

negativeAcknowledge(domainId, projectId, subscriptionName, ackIds);
}

private static void negativeAcknowledge(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {

ModifyAckDeadlineRequest request =
ModifyAckDeadlineRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setAckAction(AckAction.SKIP.toRequest())
.addAllAckIds(ackIds)
.build();

ApiFuture<ModifyAckDeadlineResponse> futureCall =
subscriptionAdminClient.nackCallable().futureCall(request);

ModifyAckDeadlineResponse response = futureCall.get();
}
}
}

Modify message Ack deadline

Modify the message ack deadline.

Method
TypeMethodDescription
ModifyAckDeadlineResponsemodifyAckDeadline(ModifyAckDeadlineRequest request)
ModifyAckDeadlineResponsemodifyAckDeadline( ProjectSubscription subscription, AckAction ackAction, List<String> acIds)
UnaryCallable<ModifyAckDeadlineRequest,
ModifyAckDeadlineResponse>
modifyAckDeadlineCallable()Modify the acknowledgement deadline to asynchronous
Parameters

com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringsubscriptionOSubscription name
StringackActionOAcknowledgement type
- skip
- extend
intackDeadlineSecondsMessage acknowledgement deadline (seconds)
- Default: 10
ListackIdsOMessage AckId list

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeFieldRequiredDescription
StringdomainO   Domain ID
StringprojectOProject ID
StringnameOSubscription name

Example

public ModifyAckDeadlineResponse modifyAckDeadline(ModifyAckDeadlineRequest request)
import com.kakaocloud.pubsub.v1.AckAction;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ModifyAckDeadlineExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

modifyAckDeadline(domainId, projectId, subscriptionName, ackIds);
}

private static void modifyAckDeadline(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ModifyAckDeadlineRequest request =
ModifyAckDeadlineRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setAckAction(AckAction.EXTEND.toRequest())
.addAllAckIds(ackIds)
.build();

ModifyAckDeadlineResponse response = subscriptionAdminClient.modifyAckDeadline(request);
}
}
}
public ModifyAckDeadlineResponse modifyAckDeadline(ProjectSubscription subscription, AckAction ackAction, List<String> acIds)
import com.kakaocloud.pubsub.v1.AckAction;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.ProjectSubscription;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ModifyAckDeadlineExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

modifyAckDeadline(domainId, projectId, subscriptionName, ackIds);
}

private static void modifyAckDeadline(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscription projectSubscription =
ProjectSubscription.of(domainId, projectId, subscriptionName);

ModifyAckDeadlineResponse response =
subscriptionAdminClient.modifyAckDeadline(
projectSubscription, AckAction.EXTEND, ackIds);
}
}
}
public UnaryCallable<ModifyAckDeadlineRequest, ModifyAckDeadlineResponse> modifyAckDeadlineCallable()
import com.google.api.core.ApiFuture;
import com.kakaocloud.pubsub.v1.AckAction;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest;
import com.kakaocloud.pubsub.v1.ModifyAckDeadlineResponse;
import com.kakaocloud.pubsub.v1.SubscriptionAdminClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class ModifyAckDeadlineExample {
public static void main(String[] args) throws Exception {
String domainId = "your-domain-id";
String projectId = "your-project-id";
String subscriptionName = "your-subscription-name";

String ackId = "message-ack-id";
List`<String>` ackIds = new ArrayList<>();
ackIds.add(ackId);

modifyAckDeadline(domainId, projectId, subscriptionName, ackIds);
}

private static void modifyAckDeadline(
String domainId, String projectId, String subscriptionName, List`<String>` ackIds)
throws IOException, ExecutionException, InterruptedException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ModifyAckDeadlineRequest request =
ModifyAckDeadlineRequest.newBuilder()
.setDomain(domainId)
.setProject(projectId)
.setSubscription(subscriptionName)
.setAckAction(AckAction.EXTEND.toRequest())
.addAllAckIds(ackIds)
.build();

ApiFuture<ModifyAckDeadlineResponse> futureCall =
subscriptionAdminClient.modifyAckDeadlineCallable().futureCall(request);

ModifyAckDeadlineResponse response = futureCall.get();
}
}
}