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 theDefault Request
method.
- This method takes the values required to create a
-
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.
- A method that can call the gRPC API asynchronously. It takes the
Topic
Retrieve topic
You can retrieve topics using the items below.
Method
Type | Method | Description |
---|---|---|
Topic | getTopic(GetTopicRequest request) | |
Topic | getTopic(ProjectTopic topic) | |
UnaryCallable<GetTopicRequest, Topic> | getTopicCallable() | Retrieve topics asynchronously |
Parameters
com.kakaocloud.pubsub.v1.GetTopicRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | topic | O | Topic 명 |
Example
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);
}
}
}
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);
}
}
}
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
Type | Method | Description |
---|---|---|
ListTopicsPagedResponse | listTopics(ListTopicsRequest request) | |
ListTopicsPagedResponse | listTopics(Project project) | |
UnaryCallable<ListTopicsRequest, ListTopicsPagedResponse> | listTopicsPagedCallable() | Retrieves a list of topics asynchronously |
Parameters
com.kakaocloud.pubsub.v1.ListTopicsRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
int | pageSize | Number of lists to view at once | |
String | pageToken | Variable to load the next list |
com.kakaocloud.pubsub.v1.Project
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | name | O | Project name |
Example
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);
}
);
}
}
}
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);
}
);
}
}
}
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
Type | Method | Description |
---|---|---|
ListTopicSubscriptionsPagedResponse | listTopicSubscriptions(ListTopicSubscriptionsRequest request) | |
ListTopicSubscriptionsPagedResponse | listTopicSubscriptions(ProjectTopic projectTopic) | |
UnaryCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsPagedResponse> | listTopicSubscriptionsPagedCallable() | Retrieves the list of subscriptions for a topic asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | topic | O | Topic name |
int | pageSize | Number of lists to view at once | |
String | pageToken | Variable to load the next list |
com.kakaocloud.pubsub.v1.ProjectTopic
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Topic name |
Example
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);
}
);
}
}
}
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);
}
);
}
}
}
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
Type | Method | Description |
---|---|---|
Topic | updateTopic(UpdateTopicRequest request) | |
Topic | updateTopic(ProjectTopic topic, Duration messageRetentionDuration) | |
UnaryCallable<UpdateTopicRequest, Topic> | updateTopicCallable() | Modify topic asynchronously |
Parameters
com.kakaocloud.pubsub.v1.UpdateTopicRequest
Type | Field | Required | Description |
---|---|---|---|
Topic | topic | O | Object containing information about the topic to be created |
FieldMask | updateMaskBuilder | O | Fields of the item to be updated |
com.kakaocloud.pubsub.v1.Topic
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Topic name |
Duration | messageRetentionDuration | Message retention period | |
String | description | Topic description |
com.google.protobuf.Duration, Timestamp
Type | Field | Required | Description |
---|---|---|---|
int | nanos | Message retention cycle Nanos | |
long | seconds | O | Message retention cycle Seconds |
com.kakaocloud.pubsub.v1.ProjectTopic
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Topic name |
Example
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);
}
}
}
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);
}
}
}
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.
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// Do Something
}
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
Type | Method | Description |
---|---|---|
Subscription | getSubscription(GetSubscriptionRequest request) | |
Subscription | getSubscription(ProjectSubscription subscription) | |
UnaryCallable<GetSubscriptionRequest, Subscription> | getSubscriptionCallable() | Retrieve a subscription asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.GetSubscriptionRequest
Type | Field | Required or not | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | Yes | Domain ID |
String | project | Yes | Project ID |
String | name | Yes | Subscription name |
Example
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);
}
}
}
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 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
Type | Method | Description |
---|---|---|
ListSubscriptionsPagedResponse | listSubscriptions(ListSubscriptionsRequest request) | |
ListSubscriptionsPagedResponse | listSubscriptions(Project project) | |
UnaryCallable<ListSubscriptionsRequest, ListSubscriptionsPagedResponse> | listSubscriptionsPagedCallable() | Retrieve the list of subscriptions asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
com.kakaocloud.pubsub.v1.Project
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
Example
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);
}
);
}
}
}
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);
}
);
}
}
}
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
Type | Method | Description |
---|---|---|
Subscription | updateSubscription(UpdateSubscriptionRequest request) | |
Subscription | updateSubscription( ProjectSubscription subscription, PushConfig pushConfig, int ackDeadlineSeconds) | |
UnaryCallable<UpdateSubscriptionRequest, Subscription> | updateSubscriptionCallable() | Modify subscription to asynchronous |
Parameters
com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest
Type | Field | Required | Description |
---|---|---|---|
Subscription | subscription | O | Object containing information about the subscription side to be created |
FieldMask | updateMask | O | Fields of the item to be updated |
com.kakaocloud.pubsub.v1.Subscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
PushConfig | pushConfig | Message push settings | |
int | ackDeadlineSeconds | Message acknowledgement deadline (seconds) - Default: 10 | |
Duration | messageRetentionDuration | Message retention period | |
int | maxDeliveryAttempt | Maximum number of delivery attempts - Default: -1 (infinite) |
com.kakaocloud.pubsub.v1.PushConfig
Type | Field | Required | Description |
---|---|---|---|
String | pushEndpoint | O | Push endpoint |
int | pushBatchSize | Push batch size - Default: 0 |
com.google.protobuf.Duration, Timestamp
Type | Field | Required | Description |
---|---|---|---|
long | seconds | O | Message retention period (Seconds) |
int | nanos | Message retention period (Nanos) |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required or not | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription people |
Example
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);
}
}
}
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
);
}
}
}
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
Type | Method | Description |
---|---|---|
Empty | seek(SeekRequest request) | |
UnaryCallable<SeekRequest, Empty> | Modify the acknowledgement deadline to asynchronous |
Parameters
com.kakaocloud.pubsub.v1.SeekRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | subscription | O | Subscription name |
Timestamp | time | O | Time to roll back |
com.google.protobuf.Duration, Timestamp
Type | Field | Required | Description |
---|---|---|---|
long | seconds | O | Time to roll back (Seconds) |
int | nanos | Time to roll back (Nanos) |
Example
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);
}
}
}
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.
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.
publisher = Publisher.newBuilder(topic)
.setEndpoint("your-endpoint")
.build();
Method
Type | Method | Description |
---|---|---|
ApiFuture<String> | publish(PublishMessage message) | Process message publishing asynchronously |
Parameters
com.kakaocloud.pubsub.v1.PublishMessage
Type | Field | Description |
---|---|---|
String | data | Message content ⚠️ Must be encoded in Base64. |
Example
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).
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.
subscriber = Subscriber
.newBuilder(subscription, receiver)
.setEndpoint("your-endpoint")
.build();
Parameters
com.kakaocloud.pubsub.v1.MessageReceiver
Type | Method | Description |
---|---|---|
void | receive(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
Type | Method | Description |
---|---|---|
void | receive(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
Type | Field | Description |
---|---|---|
String | data | Message content |
com.kakaocloud.pubsub.v1.AckReplyConsumer
Type | Method | Description |
---|---|---|
void | ack() | Processes acknowledge |
void | nack() | Processes negative acknowledge |
com.kakaocloud.pubsub.v1.AckReplyConsumerWithResponse
Type | Method | Description |
---|---|---|
Future<AckResponseData> | ack() | After processing an acknowledgement, receive the result |
Future<AckResponseData> | nack() | After processing a negative acknowledgement, receive the result |
Example
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();
}
}
}
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
Type | Method | Description |
---|---|---|
PullResponse | pull(PullRequest request) | |
UnaryCallable<PullRequest, PullResponse> | pullCallable() | Process message acknowledgments asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.PullRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | subscription | O | Subscription name |
int | maxMessages | O | Batch Size |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
Example
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);
}
);
}
}
}
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
Type | Method | Description |
---|---|---|
AcknowledgeResponse | acknowledge(AcknowledgeRequest request) | |
AcknowledgeResponse | acknowledge(ProjectSubscription subscription, List<String> ackIds) | |
UnaryCallable<AcknowledgeRequest, AcknowledgeResponse> | acknowledgeCallable() | Process message acknowledgments asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.AcknowledgeRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | subscription | O | Subscription name |
List | ackIds | O | Message AckID list |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
Example
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);
}
}
}
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);
}
}
}
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
Type | Method | Description |
---|---|---|
ModifyAckDeadlineResponse | nack(ModifyAckDeadlineRequest request) | |
ModifyAckDeadlineResponse | nack(ProjectSubscription subscription, List<String> acIds) | |
UnaryCallable<ModifyAckDeadlineRequest, ModifyAckDeadlineResponse> | nackCallable() | Acknowledge messages as unread asynchronously. |
Parameters
com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | subscription | O | Subscription name |
String | ackAction | O | Acknowledgement type - skip - extend |
int | ackDeadlineSeconds | Message acknowledgement deadline (seconds) - Default: 10 | |
List | ackIds | O | Message AckId list |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
Example
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);
}
}
}
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);
}
}
}
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
Type | Method | Description |
---|---|---|
ModifyAckDeadlineResponse | modifyAckDeadline(ModifyAckDeadlineRequest request) | |
ModifyAckDeadlineResponse | modifyAckDeadline( ProjectSubscription subscription, AckAction ackAction, List<String> acIds) | |
UnaryCallable<ModifyAckDeadlineRequest, ModifyAckDeadlineResponse> | modifyAckDeadlineCallable() | Modify the acknowledgement deadline to asynchronous |
Parameters
com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | subscription | O | Subscription name |
String | ackAction | O | Acknowledgement type - skip - extend |
int | ackDeadlineSeconds | Message acknowledgement deadline (seconds) - Default: 10 | |
List | ackIds | O | Message AckId list |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | Required | Description |
---|---|---|---|
String | domain | O | Domain ID |
String | project | O | Project ID |
String | name | O | Subscription name |
Example
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);
}
}
}
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);
}
}
}
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();
}
}
}