메서드 목록
사전 작업 및 요구 사항
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
Type | Method | 설명 |
---|---|---|
Topic | getTopic(GetTopicRequest request) | |
Topic | getTopic(ProjectTopic topic) | |
UnaryCallable<GetTopicRequest, Topic> | getTopicCallable() | 토픽을 비동기로 조회 |
Parameters
com.kakaocloud.pubsub.v1.GetTopicRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | topic | O | 토픽 이름 |
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();
}
}
}
토픽 목록 조회
프로젝트 내의 토픽 목록을 조회합니다.
Method
Type | Method | 설명 |
---|---|---|
ListTopicsPagedResponse | listTopics(ListTopicsRequest request) | |
ListTopicsPagedResponse | listTopics(Project project) | |
UnaryCallable<ListTopicsRequest, ListTopicsPagedResponse> | listTopicsPagedCallable() | 토픽 목록을 비동기로 조회 |
Parameters
com.kakaocloud.pubsub.v1.ListTopicsRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
int | pageSize | 한 번에 조회할 목록 개수 | |
String | pageToken | 다음 목록을 불러오기 위한 변수 |
com.kakaocloud.pubsub.v1.Project
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | name | O | Project 명 |
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);
}
);
}
}
토픽의 서브스크립션 목록 조회
특정 토픽의 서브스크립션 목록을 조회합니다.
Method
Type | Method | 설명 |
---|---|---|
ListTopicSubscriptionsPagedResponse | listTopicSubscriptions(ListTopicSubscriptionsRequest request) | |
ListTopicSubscriptionsPagedResponse | listTopicSubscriptions(ProjectTopic projectTopic) | |
UnaryCallable<ListTopicSubscriptionsRequest, ListTopicSubscriptionsPagedResponse> | listTopicSubscriptionsPagedCallable() | 토픽의 서브스크립션 목록을 비동기로 조회 |
Parameters
com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | topic | O | 토픽 이름 |
int | pageSize | 한 번에 조회할 목록 개수 | |
String | pageToken | 다음 목록을 불러오기 위한 변수 |
com.kakaocloud.pubsub.v1.ProjectTopic
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | 토픽 이름 |
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);
}
);
}
}
}
토픽 수정
토픽의 보존 주기 및 설명을 수정할 수 있습니다.
Method
Type | Method | 설명 |
---|---|---|
Topic | updateTopic(UpdateTopicRequest request) | |
Topic | updateTopic(ProjectTopic topic, Duration messageRetentionDuration) | |
UnaryCallable<UpdateTopicRequest, Topic> | updateTopicCallable() | 토픽을 비동기로 수정 |
Parameters
com.kakaocloud.pubsub.v1.UpdateTopicRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
Topic | topic | O | 생성할 토픽에 대한 정보를 담고 있는 객체 |
FieldMask | updateMaskBuilder | O | 업데이트하려는 항목의 필드 |
com.kakaocloud.pubsub.v1.Topic
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | 토픽 이름 |
Duration | messageRetentionDuration | 메시지 보존 주기 | |
String | description | Topic 설명 |
com.google.protobuf.Duration, Timestamp
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
int | nanos | 메시지 보존 주기 Nanos | |
long | seconds | O | 메시지 보존 주기 Seconds |
com.kakaocloud.pubsub.v1.ProjectTopic
Type | Field | 필수 여 부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | 토픽 이름 |
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
서브스크립션을 조작하고, 메시지를 읽을 때 사용하는 객체입니다.
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// Do Something
}
SubscriptionAdminClient 객체는 스레드와 같은 리소스들을 해제시켜줘야 하기 때문에 close() 메서드를 호출해야 합니다. Sample 코드와 같이 try-with-resources를 사용하면 자동으로 이를 해제합니다.
서브스크립션 조회
특정 서브스크립션의 정보를 조회합니다.
Method
Type | Method | 설명 |
---|---|---|
Subscription | getSubscription(GetSubscriptionRequest request) | |
Subscription | getSubscription(ProjectSubscription subscription) | |
UnaryCallable<GetSubscriptionRequest, Subscription> | getSubscriptionCallable() | 서브스크립션을 비동기로 조회 |
Parameters
com.kakaocloud.pubsub.v1.GetSubscriptionRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | 서브스크립션 명 |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | 서브스크립션 명 |
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();
}
}
}
서브스크립션 목록 조회
프로젝트 내 서브스크립션 목록을 조회합니다.
Method
Type | Method | 설명 |
---|---|---|
ListSubscriptionsPagedResponse | listSubscriptions(ListSubscriptionsRequest request) | |
ListSubscriptionsPagedResponse | listSubscriptions(Project project) | |
UnaryCallable<ListSubscriptionsRequest, ListSubscriptionsPagedResponse> | listSubscriptionsPagedCallable() | 서브스크립션 목록을 비동기로 조회 |
Parameters
com.kakaocloud.pubsub.v1.ListTopicSubscriptionsRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
com.kakaocloud.pubsub.v1.Project
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 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);
}
);
}
}
}
서브스크립션 수정
아래 항목을 이용하여 서브스크립션을 수정할 수 있습니다.
Method
Type | Method | 설명 |
---|---|---|
Subscription | updateSubscription(UpdateSubscriptionRequest request) | |
Subscription | updateSubscription( ProjectSubscription subscription, PushConfig pushConfig, int ackDeadlineSeconds) | |
UnaryCallable<UpdateSubscriptionRequest, Subscription> | updateSubscriptionCallable() | 서브스크립션을 비동기로 수정 |
Parameters
com.kakaocloud.pubsub.v1.UpdateSubscriptionRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
Subscription | subscription | O | 생성할 서브스크립션측에 대한 정보를 담고 있는 객체 |
FieldMask | updateMask | O | 업데이트하려는 항목의 필드 |
com.kakaocloud.pubsub.v1.Subscription
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | Subscription 명 |
PushConfig | pushConfig | 메시지 Push 설정 | |
int | ackDeadlineSeconds | 메시지 확인 기한(초) - Default: 10 | |
Duration | messageRetentionDuration | 메시지 보존 주기 | |
int | maxDeliveryAttempt | 최대 전송 시도 횟수 - Default: -1 (무한) |
com.kakaocloud.pubsub.v1.PushConfig
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | pushEndpoint | O | Push 엔드포인트 |
int | pushBatchSize | Push 배치 사이즈 - Default: 0 |
com.google.protobuf.Duration, Timestamp
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
long | seconds | O | 메시지 보존 주기(Seconds) |
int | nanos | 메시지 보존 주기(Nanos) |
com.kakaocloud.pubsub.v1.ProjectSubscription
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | name | O | Subscription 명 |
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();
}
}
}
서브스크립션 시점 되돌리기
서브스크립션 시점을 지정한 시간으로 되돌리고, 지정한 시간 이후의 메시지를 다시 받아볼 수 있습니다.
Method
Type | Method | 설명 |
---|---|---|
Empty | seek(SeekRequest request) | |
UnaryCallable<SeekRequest, Empty> | 확인 기한을 비동기로 수정 |
Parameters
com.kakaocloud.pubsub.v1.SeekRequest
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
String | domain | O | 도메인 ID |
String | project | O | 프로젝트 ID |
String | subscription | O | Subscription 명 |
Timestamp | time | O | 시점을 되돌릴 시간 |
com.google.protobuf.Duration, Timestamp
Type | Field | 필수 여부 | 설명 |
---|---|---|---|
long | seconds | O | 시점 되돌리기할 시간(Seconds) |
int | nanos | 시점 되돌리기할 시간(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();
}
}
}