diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java index 36d576767efb..7d8eb0f15e79 100644 --- a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java +++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java @@ -67,8 +67,8 @@ *
*
* try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
- * String name = "";
- * Topic callResult = publisherApi.createTopic(name);
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.createTopic(formattedName);
* }
*
*
@@ -277,6 +277,14 @@ public void close() throws IOException {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.createTopic(formattedName);
+ * }
+ *
+ *
*
*
*
@@ -289,8 +297,8 @@ public void close() throws IOException {
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Topic createTopic(String name) {
+ TOPIC_PATH_TEMPLATE.validate(name);
Topic request = Topic.newBuilder().setName(name).build();
-
return createTopic(request);
}
@@ -298,6 +306,17 @@ public final Topic createTopic(String name) {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic request = Topic.newBuilder()
+ * .setName(formattedName)
+ * .build();
+ * Topic response = publisherApi.createTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -312,6 +331,19 @@ private Topic createTopic(Topic request) {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic request = Topic.newBuilder()
+ * .setName(formattedName)
+ * .build();
+ * ListenableFuture<Topic> future = publisherApi.createTopicCallable().futureCall(request);
+ * // Do something
+ * Topic response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -327,6 +359,15 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishResponse response = publisherApi.publish(formattedTopic, messages);
+ * }
+ *
+ *
*
*
*
@@ -335,9 +376,10 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishRequest request = PublishRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .addAllMessages(messages)
+ * .build();
+ * PublishResponse response = publisherApi.publish(request);
+ * }
+ *
+ *
*
*
*
@@ -363,6 +418,21 @@ public PublishResponse publish(PublishRequest request) {
* does not exist. The message payload must not be empty; it must contain
* either a non-empty data field, or at least one attribute.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishRequest request = PublishRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .addAllMessages(messages)
+ * .build();
+ * ListenableFuture<PublishResponse> future = publisherApi.publishCallable().futureCall(request);
+ * // Do something
+ * PublishResponse response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -376,6 +446,14 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.getTopic(formattedTopic);
+ * }
+ *
+ *
*
*
*
@@ -383,8 +461,8 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * GetTopicRequest request = GetTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * Topic response = publisherApi.getTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -406,6 +495,19 @@ private Topic getTopic(GetTopicRequest request) {
/**
* Gets the configuration of a topic.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * GetTopicRequest request = GetTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Topic> future = publisherApi.getTopicCallable().futureCall(request);
+ * // Do something
+ * Topic response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -419,6 +521,16 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * for (Topic elements : publisherApi.listTopics(formattedProject)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -426,6 +538,7 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * for (Topic elements : publisherApi.listTopics(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -448,6 +574,21 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * ListenableFuture<PageAccessor<Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
+ * // Do something
+ * for (Topic elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -459,6 +600,28 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * while (true) {
+ * ListTopicsResponse response = publisherApi.listTopicsCallable().call(request);
+ * for (Topic elements : response.getTopicsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -472,6 +635,16 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * for (String elements : publisherApi.listTopicSubscriptions(formattedTopic)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -479,6 +652,7 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * for (String elements : publisherApi.listTopicSubscriptions(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -502,6 +689,21 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<PageAccessor<String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
+ * // Do something
+ * for (String elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -514,6 +716,28 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * while (true) {
+ * ListTopicSubscriptionsResponse response = publisherApi.listTopicSubscriptionsCallable().call(request);
+ * for (String elements : response.getSubscriptionsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -532,6 +756,14 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * publisherApi.deleteTopic(formattedTopic);
+ * }
+ *
+ *
*
*
*
@@ -539,8 +771,8 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * publisherApi.deleteTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -570,6 +813,19 @@ private void deleteTopic(DeleteTopicRequest request) {
* configuration or subscriptions. Existing subscriptions to this topic are
* not deleted, but their `topic` field is set to `_deleted-topic_`.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Void> future = publisherApi.deleteTopicCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
diff --git a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
index dd6275bcd9d0..bbb1bf629f8f 100644
--- a/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
+++ b/gcloud-java-pubsub/baseline/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
@@ -68,11 +68,11 @@
*
*
* try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
- * String name = "";
- * String topic = "";
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
* PushConfig pushConfig = PushConfig.newBuilder().build();
* int ackDeadlineSeconds = 0;
- * Subscription callResult = subscriberApi.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
+ * Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
* }
*
*
@@ -321,6 +321,17 @@ public void close() throws IOException {
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * int ackDeadlineSeconds = 0;
+ * Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
+ * }
+ *
+ *
*
*
*
@@ -356,6 +367,9 @@ public void close() throws IOException {
*/
public final Subscription createSubscription(
String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) {
+ SUBSCRIPTION_PATH_TEMPLATE.validate(name);
+ TOPIC_PATH_TEMPLATE.validate(topic);
+
Subscription request =
Subscription.newBuilder()
.setName(name)
@@ -363,7 +377,6 @@ public final Subscription createSubscription(
.setPushConfig(pushConfig)
.setAckDeadlineSeconds(ackDeadlineSeconds)
.build();
-
return createSubscription(request);
}
@@ -376,6 +389,19 @@ public final Subscription createSubscription(
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Subscription request = Subscription.newBuilder()
+ * .setName(formattedName)
+ * .setTopic(formattedTopic)
+ * .build();
+ * Subscription response = subscriberApi.createSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -395,6 +421,21 @@ public Subscription createSubscription(Subscription request) {
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Subscription request = Subscription.newBuilder()
+ * .setName(formattedName)
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Subscription> future = subscriberApi.createSubscriptionCallable().futureCall(request);
+ * // Do something
+ * Subscription response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -411,6 +452,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * Subscription response = subscriberApi.getSubscription(formattedSubscription);
+ * }
+ *
+ *
*
*
*
@@ -418,9 +467,9 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * Subscription response = subscriberApi.getSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -448,6 +508,19 @@ private Subscription getSubscription(GetSubscriptionRequest request) {
* If the topic of a subscription has been deleted, the subscription itself is
* not deleted, but the value of the `topic` field is set to `_deleted-topic_`.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * ListenableFuture<Subscription> future = subscriberApi.getSubscriptionCallable().futureCall(request);
+ * // Do something
+ * Subscription response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -464,6 +537,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * for (Subscription elements : subscriberApi.listSubscriptions(formattedProject)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -471,6 +554,7 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * for (Subscription elements : subscriberApi.listSubscriptions(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -500,6 +597,21 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * ListenableFuture<PageAccessor<Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
+ * // Do something
+ * for (Subscription elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -515,6 +627,28 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * while (true) {
+ * ListSubscriptionsResponse response = subscriberApi.listSubscriptionsCallable().call(request);
+ * for (Subscription elements : response.getSubscriptionsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -533,6 +667,14 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * subscriberApi.deleteSubscription(formattedSubscription);
+ * }
+ *
+ *
*
*
*
@@ -540,9 +682,9 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * subscriberApi.deleteSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -572,6 +725,19 @@ private void deleteSubscription(DeleteSubscriptionRequest request) {
* the same name, but the new one has no association with the old
* subscription, or its topic unless the same topic is specified.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.deleteSubscriptionCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -588,6 +754,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * subscriberApi.modifyAckDeadline(formattedSubscription, ackIds, ackDeadlineSeconds);
+ * }
+ *
+ *
*
*
*
@@ -602,13 +778,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .setAckDeadlineSeconds(ackDeadlineSeconds)
+ * .build();
+ * subscriberApi.modifyAckDeadline(request);
+ * }
+ *
+ *
*
*
*
@@ -636,6 +828,23 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) {
* subscriber, or to make the message available for redelivery if the
* processing was interrupted.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .setAckDeadlineSeconds(ackDeadlineSeconds)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.modifyAckDeadlineCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -655,6 +864,15 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * subscriberApi.acknowledge(formattedSubscription, ackIds);
+ * }
+ *
+ *
*
*
*
@@ -664,9 +882,10 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .build();
+ * subscriberApi.acknowledge(request);
+ * }
+ *
+ *
*
*
*
@@ -700,6 +932,21 @@ public void acknowledge(AcknowledgeRequest request) {
* but such a message may be redelivered later. Acknowledging a message more
* than once will not result in an error.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.acknowledgeCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -716,6 +963,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * boolean returnImmediately = false;
+ * int maxMessages = 0;
+ * PullResponse response = subscriberApi.pull(formattedSubscription, returnImmediately, maxMessages);
+ * }
+ *
+ *
*
*
*
@@ -729,13 +986,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * int maxMessages = 0;
+ * PullRequest request = PullRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setMaxMessages(maxMessages)
+ * .build();
+ * PullResponse response = subscriberApi.pull(request);
+ * }
+ *
+ *
*
*
*
@@ -763,6 +1034,21 @@ public PullResponse pull(PullRequest request) {
* there are too many concurrent pull requests pending for the given
* subscription.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * int maxMessages = 0;
+ * PullRequest request = PullRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setMaxMessages(maxMessages)
+ * .build();
+ * ListenableFuture<PullResponse> future = subscriberApi.pullCallable().futureCall(request);
+ * // Do something
+ * PullResponse response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -781,6 +1067,15 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * subscriberApi.modifyPushConfig(formattedSubscription, pushConfig);
+ * }
+ *
+ *
*
*
*
@@ -794,12 +1089,13 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setPushConfig(pushConfig)
+ * .build();
+ * subscriberApi.modifyPushConfig(request);
+ * }
+ *
+ *
*
*
*
@@ -831,6 +1140,21 @@ public void modifyPushConfig(ModifyPushConfigRequest request) {
* attributes of a push subscription. Messages will accumulate for delivery
* continuously through the call regardless of changes to the `PushConfig`.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setPushConfig(pushConfig)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.modifyPushConfigCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
diff --git a/gcloud-java-pubsub/pom.xml b/gcloud-java-pubsub/pom.xml
index f9b9b6533f78..77902a588260 100644
--- a/gcloud-java-pubsub/pom.xml
+++ b/gcloud-java-pubsub/pom.xml
@@ -25,7 +25,7 @@
*
* try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
- * String name = "";
- * Topic callResult = publisherApi.createTopic(name);
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.createTopic(formattedName);
* }
*
*
@@ -277,6 +277,14 @@ public void close() throws IOException {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.createTopic(formattedName);
+ * }
+ *
+ *
*
*
*
@@ -289,8 +297,8 @@ public void close() throws IOException {
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Topic createTopic(String name) {
+ TOPIC_PATH_TEMPLATE.validate(name);
Topic request = Topic.newBuilder().setName(name).build();
-
return createTopic(request);
}
@@ -298,6 +306,17 @@ public final Topic createTopic(String name) {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic request = Topic.newBuilder()
+ * .setName(formattedName)
+ * .build();
+ * Topic response = publisherApi.createTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -312,6 +331,19 @@ private Topic createTopic(Topic request) {
/**
* Creates the given topic with the given name.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedName = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic request = Topic.newBuilder()
+ * .setName(formattedName)
+ * .build();
+ * ListenableFuture<Topic> future = publisherApi.createTopicCallable().futureCall(request);
+ * // Do something
+ * Topic response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -327,6 +359,15 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishResponse response = publisherApi.publish(formattedTopic, messages);
+ * }
+ *
+ *
*
*
*
@@ -335,9 +376,10 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishRequest request = PublishRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .addAllMessages(messages)
+ * .build();
+ * PublishResponse response = publisherApi.publish(request);
+ * }
+ *
+ *
*
*
*
@@ -363,6 +418,21 @@ public PublishResponse publish(PublishRequest request) {
* does not exist. The message payload must not be empty; it must contain
* either a non-empty data field, or at least one attribute.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * List<PubsubMessage> messages = new ArrayList<>();
+ * PublishRequest request = PublishRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .addAllMessages(messages)
+ * .build();
+ * ListenableFuture<PublishResponse> future = publisherApi.publishCallable().futureCall(request);
+ * // Do something
+ * PublishResponse response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -376,6 +446,14 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Topic response = publisherApi.getTopic(formattedTopic);
+ * }
+ *
+ *
*
*
*
@@ -383,8 +461,8 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * GetTopicRequest request = GetTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * Topic response = publisherApi.getTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -406,6 +495,19 @@ private Topic getTopic(GetTopicRequest request) {
/**
* Gets the configuration of a topic.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * GetTopicRequest request = GetTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Topic> future = publisherApi.getTopicCallable().futureCall(request);
+ * // Do something
+ * Topic response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -419,6 +521,16 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * for (Topic elements : publisherApi.listTopics(formattedProject)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -426,6 +538,7 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * for (Topic elements : publisherApi.listTopics(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -448,6 +574,21 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * ListenableFuture<PageAccessor<Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
+ * // Do something
+ * for (Topic elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -459,6 +600,28 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
+ * ListTopicsRequest request = ListTopicsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * while (true) {
+ * ListTopicsResponse response = publisherApi.listTopicsCallable().call(request);
+ * for (Topic elements : response.getTopicsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -472,6 +635,16 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * for (String elements : publisherApi.listTopicSubscriptions(formattedTopic)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -479,6 +652,7 @@ public final ApiCallable
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * for (String elements : publisherApi.listTopicSubscriptions(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -502,6 +689,21 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<PageAccessor<String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
+ * // Do something
+ * for (String elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -514,6 +716,28 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * while (true) {
+ * ListTopicSubscriptionsResponse response = publisherApi.listTopicSubscriptionsCallable().call(request);
+ * for (String elements : response.getSubscriptionsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -532,6 +756,14 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * publisherApi.deleteTopic(formattedTopic);
+ * }
+ *
+ *
*
*
*
@@ -539,8 +771,8 @@ public final PageAccessor
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * publisherApi.deleteTopic(request);
+ * }
+ *
+ *
*
*
*
@@ -570,6 +813,19 @@ private void deleteTopic(DeleteTopicRequest request) {
* configuration or subscriptions. Existing subscriptions to this topic are
* not deleted, but their `topic` field is set to `_deleted-topic_`.
*
+ * Sample code:
+ *
+ * try (PublisherApi publisherApi = PublisherApi.createWithDefaults()) {
+ * String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Void> future = publisherApi.deleteTopicCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
diff --git a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
index dd6275bcd9d0..bbb1bf629f8f 100644
--- a/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
+++ b/gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java
@@ -68,11 +68,11 @@
*
*
* try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
- * String name = "";
- * String topic = "";
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
* PushConfig pushConfig = PushConfig.newBuilder().build();
* int ackDeadlineSeconds = 0;
- * Subscription callResult = subscriberApi.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
+ * Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
* }
*
*
@@ -321,6 +321,17 @@ public void close() throws IOException {
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * int ackDeadlineSeconds = 0;
+ * Subscription response = subscriberApi.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds);
+ * }
+ *
+ *
*
*
*
@@ -356,6 +367,9 @@ public void close() throws IOException {
*/
public final Subscription createSubscription(
String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds) {
+ SUBSCRIPTION_PATH_TEMPLATE.validate(name);
+ TOPIC_PATH_TEMPLATE.validate(topic);
+
Subscription request =
Subscription.newBuilder()
.setName(name)
@@ -363,7 +377,6 @@ public final Subscription createSubscription(
.setPushConfig(pushConfig)
.setAckDeadlineSeconds(ackDeadlineSeconds)
.build();
-
return createSubscription(request);
}
@@ -376,6 +389,19 @@ public final Subscription createSubscription(
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Subscription request = Subscription.newBuilder()
+ * .setName(formattedName)
+ * .setTopic(formattedTopic)
+ * .build();
+ * Subscription response = subscriberApi.createSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -395,6 +421,21 @@ public Subscription createSubscription(Subscription request) {
* If the name is not provided in the request, the server will assign a random
* name for this subscription on the same project as the topic.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedName = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * String formattedTopic = SubscriberApi.formatTopicName("[PROJECT]", "[TOPIC]");
+ * Subscription request = Subscription.newBuilder()
+ * .setName(formattedName)
+ * .setTopic(formattedTopic)
+ * .build();
+ * ListenableFuture<Subscription> future = subscriberApi.createSubscriptionCallable().futureCall(request);
+ * // Do something
+ * Subscription response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -411,6 +452,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * Subscription response = subscriberApi.getSubscription(formattedSubscription);
+ * }
+ *
+ *
*
*
*
@@ -418,9 +467,9 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * Subscription response = subscriberApi.getSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -448,6 +508,19 @@ private Subscription getSubscription(GetSubscriptionRequest request) {
* If the topic of a subscription has been deleted, the subscription itself is
* not deleted, but the value of the `topic` field is set to `_deleted-topic_`.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * ListenableFuture<Subscription> future = subscriberApi.getSubscriptionCallable().futureCall(request);
+ * // Do something
+ * Subscription response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -464,6 +537,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * for (Subscription elements : subscriberApi.listSubscriptions(formattedProject)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -471,6 +554,7 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * for (Subscription elements : subscriberApi.listSubscriptions(request)) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*
@@ -500,6 +597,21 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * ListenableFuture<PageAccessor<Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
+ * // Do something
+ * for (Subscription elements : future.get()) {
+ * // doThingsWith(elements);
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -515,6 +627,28 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
+ * ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
+ * .setProject(formattedProject)
+ * .build();
+ * while (true) {
+ * ListSubscriptionsResponse response = subscriberApi.listSubscriptionsCallable().call(request);
+ * for (Subscription elements : response.getSubscriptionsList()) {
+ * // doThingsWith(elements);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ *
+ *
*
*
*/
@@ -533,6 +667,14 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * subscriberApi.deleteSubscription(formattedSubscription);
+ * }
+ *
+ *
*
*
*
@@ -540,9 +682,9 @@ public final PageAccessor
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * subscriberApi.deleteSubscription(request);
+ * }
+ *
+ *
*
*
*
@@ -572,6 +725,19 @@ private void deleteSubscription(DeleteSubscriptionRequest request) {
* the same name, but the new one has no association with the old
* subscription, or its topic unless the same topic is specified.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.deleteSubscriptionCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -588,6 +754,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * subscriberApi.modifyAckDeadline(formattedSubscription, ackIds, ackDeadlineSeconds);
+ * }
+ *
+ *
*
*
*
@@ -602,13 +778,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .setAckDeadlineSeconds(ackDeadlineSeconds)
+ * .build();
+ * subscriberApi.modifyAckDeadline(request);
+ * }
+ *
+ *
*
*
*
@@ -636,6 +828,23 @@ public void modifyAckDeadline(ModifyAckDeadlineRequest request) {
* subscriber, or to make the message available for redelivery if the
* processing was interrupted.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * int ackDeadlineSeconds = 0;
+ * ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .setAckDeadlineSeconds(ackDeadlineSeconds)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.modifyAckDeadlineCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -655,6 +864,15 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * subscriberApi.acknowledge(formattedSubscription, ackIds);
+ * }
+ *
+ *
*
*
*
@@ -664,9 +882,10 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .build();
+ * subscriberApi.acknowledge(request);
+ * }
+ *
+ *
*
*
*
@@ -700,6 +932,21 @@ public void acknowledge(AcknowledgeRequest request) {
* but such a message may be redelivered later. Acknowledging a message more
* than once will not result in an error.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * List<String> ackIds = new ArrayList<>();
+ * AcknowledgeRequest request = AcknowledgeRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .addAllAckIds(ackIds)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.acknowledgeCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/
@@ -716,6 +963,16 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * boolean returnImmediately = false;
+ * int maxMessages = 0;
+ * PullResponse response = subscriberApi.pull(formattedSubscription, returnImmediately, maxMessages);
+ * }
+ *
+ *
*
*
*
@@ -729,13 +986,14 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * int maxMessages = 0;
+ * PullRequest request = PullRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setMaxMessages(maxMessages)
+ * .build();
+ * PullResponse response = subscriberApi.pull(request);
+ * }
+ *
+ *
*
*
*
@@ -763,6 +1034,21 @@ public PullResponse pull(PullRequest request) {
* there are too many concurrent pull requests pending for the given
* subscription.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * int maxMessages = 0;
+ * PullRequest request = PullRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setMaxMessages(maxMessages)
+ * .build();
+ * ListenableFuture<PullResponse> future = subscriberApi.pullCallable().futureCall(request);
+ * // Do something
+ * PullResponse response = future.get();
+ * }
+ *
+ *
*
*
*/
@@ -781,6 +1067,15 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * subscriberApi.modifyPushConfig(formattedSubscription, pushConfig);
+ * }
+ *
+ *
*
*
*
@@ -794,12 +1089,13 @@ public final ApiCallable
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setPushConfig(pushConfig)
+ * .build();
+ * subscriberApi.modifyPushConfig(request);
+ * }
+ *
+ *
*
*
*
@@ -831,6 +1140,21 @@ public void modifyPushConfig(ModifyPushConfigRequest request) {
* attributes of a push subscription. Messages will accumulate for delivery
* continuously through the call regardless of changes to the `PushConfig`.
*
+ * Sample code:
+ *
+ * try (SubscriberApi subscriberApi = SubscriberApi.createWithDefaults()) {
+ * String formattedSubscription = SubscriberApi.formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
+ * PushConfig pushConfig = PushConfig.newBuilder().build();
+ * ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
+ * .setSubscription(formattedSubscription)
+ * .setPushConfig(pushConfig)
+ * .build();
+ * ListenableFuture<Void> future = subscriberApi.modifyPushConfigCallable().futureCall(request);
+ * // Do something
+ * future.get();
+ * }
+ *
+ *
*
*
*/