본문으로 건너뛰기

메서드 목록

사전 작업 및 요구 사항

Pub/Sub Java SDK를 사용하기 위한 사전 작업 및 요구 사항은 개요 문서를 참고하시기 바랍니다.

API별 제공 메서드 유형

  • Flatten Method

    • Default Request를 생성하기 위해 필요한 값들을 Parameter로 가지는 메서드입니다. Request에 해당하는 모든 필드를 사용할 수 있는 것은 아닙니다. 모든 필드를 사용하려면 Default Request Method를 사용해야 합니다.
  • Default Request Method

    • API 호출 시에 필요한 Request 객체를 파라미터로 가지는 메서드입니다.
  • Callable Method

    • 비동기로 gRPC API를 호출할 수 있는 메서드입니다. Default Request를 파라미터로 가집니다.

토픽

토픽 조회

특정 토픽의 정보를 조회합니다.

Method
TypeMethod설명
TopicgetTopic(GetTopicRequest request)
TopicgetTopic(ProjectTopic topic)
UnaryCallable<GetTopicRequest, Topic>getTopicCallable()토픽을 비동기로 조회
Parameters

com.kakaocloud.pubsub.v1.GetTopicRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringtopicO토픽 이름
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();
}
}
}

토픽 목록 조회

프로젝트 내의 토픽 목록을 조회합니다. 

Method
TypeMethod설명
ListTopicsPagedResponselistTopics(ListTopicsRequest request)
ListTopicsPagedResponselistTopics(Project project)
UnaryCallable<ListTopicsRequest, ListTopicsPagedResponse>listTopicsPagedCallable()토픽 목록을 비동기로 조회
Parameters

com.kakaocloud.pubsub.v1.ListTopicsRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
intpageSize한 번에 조회할 목록 개수
StringpageToken다음 목록을 불러오기 위한 변수

com.kakaocloud.pubsub.v1.Project

TypeField필수 여부설명
StringdomainO   도메인 ID
StringnameOProject 명

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);
}
);
}
}

토픽의 서브스크립션 목록 조회

특정 토픽의 서브스크립션 목록을 조회합니다. 

Method
TypeMethod설명
ListTopicSubscriptionsPagedResponselistTopicSubscriptions(ListTopicSubscriptionsRequest request)
ListTopicSubscriptionsPagedResponselistTopicSubscriptions(ProjectTopic projectTopic)
UnaryCallable<ListTopicSubscriptionsRequest,
ListTopicSubscriptionsPagedResponse>
listTopicSubscriptionsPagedCallable()토픽의 서브스크립션 목록을 비동기로 조회
Parameters

com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringtopicO토픽 이름
intpageSize한 번에 조회할 목록 개수
StringpageToken다음 목록을 불러오기 위한 변수

com.kakaocloud.pubsub.v1.ProjectTopic

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO토픽 이름

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);
}
);
}
}
}

토픽 수정

토픽의 보존 주기 및 설명을 수정할 수 있습니다.

Method
TypeMethod설명
TopicupdateTopic(UpdateTopicRequest request)
TopicupdateTopic(ProjectTopic topic, Duration messageRetentionDuration)
UnaryCallable<UpdateTopicRequest, Topic>updateTopicCallable()토픽을 비동기로 수정
Parameters

com.kakaocloud.pubsub.v1.UpdateTopicRequest

TypeField필수 여부설명
TopictopicO   생성할 토픽에 대한 정보를 담고 있는 객체
FieldMaskupdateMaskBuilderO업데이트하려는 항목의 필드

com.kakaocloud.pubsub.v1.Topic

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO토픽 이름
DurationmessageRetentionDuration메시지 보존 주기
StringdescriptionTopic 설명

com.google.protobuf.Duration, Timestamp

TypeField필수 여부설명
intnanos메시지 보존 주기 Nanos
longsecondsO   메시지 보존 주기 Seconds

com.kakaocloud.pubsub.v1.ProjectTopic

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO토픽 이름
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

서브스크립션을 조작하고, 메시지를 읽을 때 사용하는 객체입니다.

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

SubscriptionAdminClient 객체는 스레드와 같은 리소스들을 해제시켜줘야 하기 때문에 close() 메서드를 호출해야 합니다. Sample 코드와 같이 try-with-resources를 사용하면 자동으로 이를 해제합니다.


서브스크립션 조회

특정 서브스크립션의 정보를 조회합니다.

Method
TypeMethod설명
SubscriptiongetSubscription(GetSubscriptionRequest request)
SubscriptiongetSubscription(ProjectSubscription subscription)
UnaryCallable<GetSubscriptionRequest, Subscription>getSubscriptionCallable()서브스크립션을 비동기로 조회
Parameters

com.kakaocloud.pubsub.v1.GetSubscriptionRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명
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();
}
}
}

서브스크립션 목록 조회

프로젝트 내 서브스크립션 목록을 조회합니다.

Method
TypeMethod설명
ListSubscriptionsPagedResponselistSubscriptions(ListSubscriptionsRequest request)
ListSubscriptionsPagedResponselistSubscriptions(Project project)
UnaryCallable<ListSubscriptionsRequest,
ListSubscriptionsPagedResponse>
listSubscriptionsPagedCallable()서브스크립션 목록을 비동기로 조회
Parameters

com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID

com.kakaocloud.pubsub.v1.Project

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 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);
}
);
}
}
}

서브스크립션 수정

아래 항목을 이용하여 서브스크립션을 수정할 수 있습니다.

Method
TypeMethod설명
SubscriptionupdateSubscription(UpdateSubscriptionRequest request)
SubscriptionupdateSubscription( ProjectSubscription subscription,
PushConfig pushConfig, int ackDeadlineSeconds)
UnaryCallable<UpdateSubscriptionRequest, Subscription>updateSubscriptionCallable()서브스크립션을 비동기로 수정
Parameters

com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest

TypeField필수 여부설명
SubscriptionsubscriptionO   생성할 서브스크립션측에 대한 정보를 담고 있는 객체
FieldMaskupdateMaskO업데이트하려는 항목의 필드

com.kakaocloud.pubsub.v1.Subscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameOSubscription 명
PushConfigpushConfig    메시지 Push 설정
intackDeadlineSeconds메시지 확인 기한(초)
- Default: 10
DurationmessageRetentionDuration메시지 보존 주기
intmaxDeliveryAttempt최대 전송 시도 횟수
- Default: -1(무한)

com.kakaocloud.pubsub.v1.PushConfig

TypeField필수 여부설명
StringpushEndpointO    Push 엔드포인트
intpushBatchSizePush 배치 사이즈
- Default: 0

com.google.protobuf.Duration, Timestamp

TypeField필수 여부설명
longsecondsO   메시지 보존 주기(Seconds)
intnanos메시지 보존 주기(Nanos)

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameOSubscription 명
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();
}
}
}

서브스크립션 시점 되돌리기

서브스크립션 시점을 지정한 시간으로 되돌리고, 지정한 시간 이후의 메시지를 다시 받아볼 수 있습니다.

Method
TypeMethod설명
Emptyseek(SeekRequest request)
UnaryCallable<SeekRequest, Empty>확인 기한을 비동기로 수정
Parameters

com.kakaocloud.pubsub.v1.SeekRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringsubscriptionOSubscription 명
TimestamptimeO시점을 되돌릴 시간

com.google.protobuf.Duration, Timestamp

TypeField필수 여부설명
longsecondsO   시점 되돌리기할 시간(Seconds)
intnanos시점 되돌리기할 시간(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();
}
}
}

Message 게시

Object - Publisher

com.kakaocloud.pubsub.v1.Publisher

토픽에 메시지를 발행할 때 사용하는 객체입니다.

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);
}
}
사용자 지정 설정값

Publisher 객체 생성 시, 사용자가 임의로 설정값을 설정할 수 있습니다.

sample. endpoint customizing
publisher = Publisher.newBuilder(topic)
.setEndpoint("your-endpoint")
.build();
Method
TypeMethod설명
ApiFuture<String>publish(PublishMessage message)메시지 발행을 비동기로 처리
Parameters

com.kakaocloud.pubsub.v1.PublishMessage

TypeField설명
Stringdata메시지 내용
⚠️ 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);
}
}
}
}

메시지 수신

Object - Subscriber

com.kakaocloud.pubsub.v1.Subscriber

메시지를 구독(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();
}
사용자 지정 설정값

Publisher 객체 생성 시, 사용자가 임의로 설정값을 설정할 수 있습니다.

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

com.kakaocloud.pubsub.v1.MessageReceiver

TypeMethod설명
voidreceive(final ReceivedMessage message,
final AckReplyConsumer consumer)
받은 메시지에 대해 ack(or nack) 처리를 한 후, 그에 대한 결과를 받지 않아도 되는 경우에 사용

com.kakaocloud.pubsub.v1.MessageReceiverWithAckResponse

TypeMethod설명
voidreceive(final ReceivedMessage message,
final AckReplyConsumerWithResponse consumer)
받은 메시지에 대해 ack(or nack) 처리를 한 후, 그에 대한 결과를 받아야 하는 경우에 사용

com.kakaocloud.pubsub.v1.ReceivedMessage

TypeField설명
Stringdata메시지 내용

com.kakaocloud.pubsub.v1.AckReplyConsumer

TypeMethod설명
voidack()acknowledge 처리를 함
voidnack()negative acknowledge 처리를 함

com.kakaocloud.pubsub.v1.AckReplyConsumerWithResponse

TypeMethod설명
Future<AckResponseData>ack()acknowledge 처리를 한 후, 이에 대한 결과를 받음
Future<AckResponseData>nack()negative acknowledge 처리를 한 후, 이에 대한 결과를 받음
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();
}
}
}

메시지 수신

서브스크립션의 메시지를 동기로 수신합니다.

Method
TypeMethod설명
PullResponsepull(PullRequest request)
UnaryCallable<PullRequest, PullResponse>pullCallable()메시지 수신 확인을 비동기로 처리
Parameters

com.kakaocloud.pubsub.v1.PullRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringsubscriptionO서브스크립션 명
intmaxMessagesO배치 사이즈

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명
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();
}
}
}

메시지 수신 확인

가져온 메시지를 확인 처리합니다.

Method
TypeMethod설명
AcknowledgeResponseacknowledge(AcknowledgeRequest request)
AcknowledgeResponseacknowledge(ProjectSubscription subscription, List<String> ackIds)
UnaryCallable<AcknowledgeRequest,
AcknowledgeResponse>
acknowledgeCallable()메시지 수신 확인을 비동기로 처리
Parameters

com.kakaocloud.pubsub.v1.AcknowledgeRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringsubscriptionO서브스크립션 명
ListackIdsO메시지 AckID 리스트

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명
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();
}
}
}

메시지 수신 미확인 처리

아래 항목을 이용하여 가져온 메시지를 미확인으로 처리합니다.

Method
TypeMethod설명
ModifyAckDeadlineResponsenack(ModifyAckDeadlineRequest request)
ModifyAckDeadlineResponsenack(ProjectSubscription subscription, List<String> acIds)
UnaryCallable<ModifyAckDeadlineRequest,
ModifyAckDeadlineResponse>
nackCallable()메시지를 비동기로 미확인 처리
Parameters

com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringsubscriptionOSubscription 명
StringackActionO확인 유형
- skip
- extend
intackDeadlineSeconds메시지 확인 기한(초)
- Default: 10
ListackIdsO메시지 AckId 리스트

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명
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();
}
}
}

메시지 확인 기한 수정

메시지 확인 기한(Ack Deadline)을 수정합니다.

Method
TypeMethod설명
ModifyAckDeadlineResponsemodifyAckDeadline(ModifyAckDeadlineRequest request)
ModifyAckDeadlineResponsemodifyAckDeadline( ProjectSubscription subscription, AckAction ackAction, List<String> acIds)
UnaryCallable<ModifyAckDeadlineRequest,
ModifyAckDeadlineResponse>
modifyAckDeadlineCallable()확인 기한을 비동기로 수정
Parameters

com.kakaocloud.pubsub.v1.ModifyAckDeadlineRequest

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringsubscriptionO서브스크립션 명
StringackActionO확인 유형
- skip
- extend
intackDeadlineSeconds메시지 확인 기한(초)
- Default: 10
ListackIdsO메시지 AckId 리스트

com.kakaocloud.pubsub.v1.ProjectSubscription

TypeField필수 여부설명
StringdomainO   도메인 ID
StringprojectO프로젝트 ID
StringnameO서브스크립션 명

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();
}
}
}