From eb19b4f3da5426c1babbee08d65677bfad5237db Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Fri, 4 Mar 2022 18:14:12 +0000
Subject: [PATCH 01/22] chore(main): release 1.116.1-SNAPSHOT (#1039)
:robot: I have created a release *beep* *boop*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
---
google-cloud-pubsub-bom/pom.xml | 8 ++++----
google-cloud-pubsub/pom.xml | 4 ++--
grpc-google-cloud-pubsub-v1/pom.xml | 4 ++--
pom.xml | 8 ++++----
proto-google-cloud-pubsub-v1/pom.xml | 4 ++--
samples/snapshot/pom.xml | 2 +-
versions.txt | 6 +++---
7 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/google-cloud-pubsub-bom/pom.xml b/google-cloud-pubsub-bom/pom.xml
index 12b602ac7..29368bb2a 100644
--- a/google-cloud-pubsub-bom/pom.xml
+++ b/google-cloud-pubsub-bom/pom.xml
@@ -3,7 +3,7 @@
4.0.0com.google.cloudgoogle-cloud-pubsub-bom
- 1.116.0
+ 1.116.1-SNAPSHOTpomcom.google.cloud
@@ -52,17 +52,17 @@
com.google.cloudgoogle-cloud-pubsub
- 1.116.0
+ 1.116.1-SNAPSHOTcom.google.api.grpcgrpc-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOTcom.google.api.grpcproto-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOT
diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml
index fa0c376b3..b8f6268bf 100644
--- a/google-cloud-pubsub/pom.xml
+++ b/google-cloud-pubsub/pom.xml
@@ -3,7 +3,7 @@
4.0.0com.google.cloudgoogle-cloud-pubsub
- 1.116.0
+ 1.116.1-SNAPSHOTjarGoogle Cloud Pub/Subhttps://github.com/googleapis/java-pubsub
@@ -11,7 +11,7 @@
com.google.cloudgoogle-cloud-pubsub-parent
- 1.116.0
+ 1.116.1-SNAPSHOTgoogle-cloud-pubsub
diff --git a/grpc-google-cloud-pubsub-v1/pom.xml b/grpc-google-cloud-pubsub-v1/pom.xml
index 7e6e4f55b..f04935a8b 100644
--- a/grpc-google-cloud-pubsub-v1/pom.xml
+++ b/grpc-google-cloud-pubsub-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0com.google.api.grpcgrpc-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOTgrpc-google-cloud-pubsub-v1GRPC library for grpc-google-cloud-pubsub-v1com.google.cloudgoogle-cloud-pubsub-parent
- 1.116.0
+ 1.116.1-SNAPSHOT
diff --git a/pom.xml b/pom.xml
index 871761a9c..8511099e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.google.cloudgoogle-cloud-pubsub-parentpom
- 1.116.0
+ 1.116.1-SNAPSHOTGoogle Cloud Pub/Sub Parenthttps://github.com/googleapis/java-pubsub
@@ -69,17 +69,17 @@
com.google.api.grpcproto-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOTcom.google.api.grpcgrpc-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOTcom.google.cloudgoogle-cloud-pubsub
- 1.116.0
+ 1.116.1-SNAPSHOT
diff --git a/proto-google-cloud-pubsub-v1/pom.xml b/proto-google-cloud-pubsub-v1/pom.xml
index 439e1e4a0..2ec5b2342 100644
--- a/proto-google-cloud-pubsub-v1/pom.xml
+++ b/proto-google-cloud-pubsub-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0com.google.api.grpcproto-google-cloud-pubsub-v1
- 1.98.0
+ 1.98.1-SNAPSHOTproto-google-cloud-pubsub-v1PROTO library for proto-google-cloud-pubsub-v1com.google.cloudgoogle-cloud-pubsub-parent
- 1.116.0
+ 1.116.1-SNAPSHOT
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 29fc16f4d..2b875a222 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -43,7 +43,7 @@
com.google.cloudgoogle-cloud-pubsub
- 1.116.0
+ 1.116.1-SNAPSHOT
diff --git a/versions.txt b/versions.txt
index d4d5bbb2c..7603c3542 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,6 +1,6 @@
# Format:
# module:released-version:current-version
-google-cloud-pubsub:1.116.0:1.116.0
-grpc-google-cloud-pubsub-v1:1.98.0:1.98.0
-proto-google-cloud-pubsub-v1:1.98.0:1.98.0
+google-cloud-pubsub:1.116.0:1.116.1-SNAPSHOT
+grpc-google-cloud-pubsub-v1:1.98.0:1.98.1-SNAPSHOT
+proto-google-cloud-pubsub-v1:1.98.0:1.98.1-SNAPSHOT
From 3cd8bd1f816cb4037f9a9c956c8c60a9f2b2a906 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Fri, 4 Mar 2022 20:00:16 +0100
Subject: [PATCH 02/22] chore(deps): update dependency
com.google.cloud:google-cloud-pubsub to v1.116.0 (#1040)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* chore(deps): update dependency com.google.cloud:google-cloud-pubsub to v1.116.0
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: Owl Bot
---
README.md | 6 +++---
samples/install-without-bom/pom.xml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index fa6ddbde2..a3df31f5b 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ If you are using Maven without BOM, add this to your dependencies:
com.google.cloudgoogle-cloud-pubsub
- 1.115.5
+ 1.116.0
```
@@ -58,13 +58,13 @@ implementation 'com.google.cloud:google-cloud-pubsub'
If you are using Gradle without BOM, add this to your dependencies
```Groovy
-implementation 'com.google.cloud:google-cloud-pubsub:1.115.5'
+implementation 'com.google.cloud:google-cloud-pubsub:1.116.0'
```
If you are using SBT, add this to your dependencies
```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.115.5"
+libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.116.0"
```
## Authentication
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 444c5c709..ca6c776db 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -44,7 +44,7 @@
com.google.cloudgoogle-cloud-pubsub
- 1.115.5
+ 1.116.0
From a4fa69b99f34304f7ee7a56fb3c633f018905f09 Mon Sep 17 00:00:00 2001
From: Mridula <66699525+mpeddada1@users.noreply.github.com>
Date: Fri, 4 Mar 2022 16:43:15 -0500
Subject: [PATCH 03/22] docs(sample): Add sample for Native Image support in
Pub/Sub (#1026)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* docs(sample): Add sample for Native Image support in Pub/Sub
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* fix checkstyle issues
* fix header and modify copyright year to 2022
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* fix link in copyright
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* Add helper class to utilities directory
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
fix checkstyle
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* fix sample to also run with standard java
Co-authored-by: Owl Bot
---
README.md | 2 +
samples/native-image-sample/README.md | 77 ++++
samples/native-image-sample/pom.xml | 175 ++++++++
.../java/pubsub/NativeImagePubSubSample.java | 385 ++++++++++++++++++
.../java/utilities/PublishOperations.java | 159 ++++++++
.../pubsub/NativeImagePubSubSampleIT.java | 139 +++++++
samples/pom.xml | 1 +
7 files changed, 938 insertions(+)
create mode 100644 samples/native-image-sample/README.md
create mode 100644 samples/native-image-sample/pom.xml
create mode 100644 samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java
create mode 100644 samples/native-image-sample/src/main/java/utilities/PublishOperations.java
create mode 100644 samples/native-image-sample/src/test/java/pubsub/NativeImagePubSubSampleIT.java
diff --git a/README.md b/README.md
index a3df31f5b..8f60b60bb 100644
--- a/README.md
+++ b/README.md
@@ -240,6 +240,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m
| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
+| Native Image Pub Sub Sample | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java) |
+| Publish Operations | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/native-image-sample/src/main/java/utilities/PublishOperations.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/native-image-sample/src/main/java/utilities/PublishOperations.java) |
| Create Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java) |
| Create Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) |
| Create Pull Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) |
diff --git a/samples/native-image-sample/README.md b/samples/native-image-sample/README.md
new file mode 100644
index 000000000..ace93bd8e
--- /dev/null
+++ b/samples/native-image-sample/README.md
@@ -0,0 +1,77 @@
+# Pub/Sub Sample Application with Native Image
+
+The Pub/Sub sample application demonstrates some common operations with Pub/Sub and is compatible with Native Image compilation.
+
+## Setup Instructions
+
+You will need to follow these prerequisite steps in order to run the samples:
+
+1. If you have not already, [create a Google Cloud Platform Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project).
+
+2. Install the [Google Cloud SDK](https://cloud.google.com/sdk/) which will allow you to run the sample with your project's credentials.
+
+ Once installed, log in with Application Default Credentials using the following command:
+
+ ```
+ gcloud auth application-default login
+ ```
+
+ **Note:** Authenticating with Application Default Credentials is convenient to use during development, but we recommend [alternate methods of authentication](https://cloud.google.com/docs/authentication/production) during production use.
+
+3. Install the GraalVM compiler.
+
+ You can follow the [official installation instructions](https://www.graalvm.org/docs/getting-started/#install-graalvm) from the GraalVM website.
+ After following the instructions, ensure that you install the native image extension installed by running:
+
+ ```
+ gu install native-image
+ ```
+
+ Once you finish following the instructions, verify that the default version of Java is set to the GraalVM version by running `java -version` in a terminal.
+
+ You will see something similar to the below output:
+
+ ```
+ $ java -version
+
+ openjdk version "11.0.7" 2020-04-14
+ OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
+ OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
+ ```
+
+4. [Enable the Pub/Sub APIs](https://console.cloud.google.com/apis/api/pubsub.googleapis.com).
+
+### Sample
+
+Navigate to this directory in a new terminal.
+
+1. Compile the application using the Native Image Compiler. This step may take a few minutes.
+
+ ```
+ mvn package -P native -DskipTests
+ ```
+
+2. Run the application:
+
+ ```
+ ./target/native-image-sample
+ ```
+
+3. The application will create a new Pub/Sub topic, send and receive a message from it, and then delete the topic.
+
+ ```
+ Created topic: projects/YOUR_PROJECT_ID/topics/graal-pubsub-test-00e72640-4e36-4aff-84d2-13b7569b2289 under project: YOUR_PROJECT_ID
+ Created pull subscription: projects/YOUR_PROJECT_ID/subscriptions/graal-pubsub-test-sub2fb5e3f3-cb26-439b-b88c-9cb0cfca9e45
+ Published message with ID: 457327433078420
+ Received Payload: Pub/Sub Native Image Test published message at timestamp: 2020-09-23T19:45:42.746514Z
+ Deleted topic projects/YOUR_PROJECT_ID/topics/graal-pubsub-test-00e72640-4e36-4aff-84d2-13b7569b2289
+ Deleted subscription projects/YOUR_PROJECT_ID/subscriptions/graal-pubsub-test-sub2fb5e3f3-cb26-439b-b88c-9cb0cfca9e45
+ ```
+
+## Sample Integration Test with native Image Support
+
+In order to run the sample integration test as a native image, call the following command:
+
+ ```
+ mvn test -Pnative
+ ```
\ No newline at end of file
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
new file mode 100644
index 000000000..afdfa8e56
--- /dev/null
+++ b/samples/native-image-sample/pom.xml
@@ -0,0 +1,175 @@
+
+
+ 4.0.0
+ com.google.cloud
+ native-image-sample
+ Native Image Sample
+ https://github.com/googleapis/java-pubsub
+
+
+
+ com.google.cloud.samples
+ shared-configuration
+ 1.2.0
+
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+
+ com.google.cloud
+ libraries-bom
+ 24.3.0
+ pom
+ import
+
+
+
+
+
+
+ com.google.cloud
+ google-cloud-core
+
+
+ com.google.cloud
+ google-cloud-pubsub
+
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ com.google.truth
+ truth
+ 1.1.3
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ dependency-jars/
+ pubsub.NativeImagePubSubSample
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.2.0
+
+
+ copy-dependencies
+ package
+
+ copy-dependencies
+
+
+
+ ${project.build.directory}/dependency-jars/
+
+
+
+
+
+
+
+
+
+
+
+ native
+
+
+
+ com.google.cloud
+ native-image-support
+ 0.12.4
+
+
+ org.junit.vintage
+ junit-vintage-engine
+ 5.8.2
+ test
+
+
+ org.graalvm.buildtools
+ junit-platform-native
+ 0.9.9
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 2.22.2
+
+
+ **/*IT
+
+
+
+
+ org.graalvm.buildtools
+ native-maven-plugin
+ 0.9.9
+ true
+
+ pubsub.NativeImagePubSubSample
+
+
+ --no-fallback
+ --no-server
+ --features=com.google.cloud.nativeimage.features.ProtobufMessageFeature
+
+
+
+
+ build-native
+
+ build
+ test
+
+ package
+
+
+ test-native
+
+ test
+
+ test
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java b/samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java
new file mode 100644
index 000000000..2e96091a6
--- /dev/null
+++ b/samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pubsub;
+
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.cloud.ServiceOptions;
+import com.google.cloud.pubsub.v1.AckReplyConsumer;
+import com.google.cloud.pubsub.v1.MessageReceiver;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
+import com.google.cloud.pubsub.v1.TopicAdminClient;
+import com.google.cloud.pubsub.v1.stub.GrpcSubscriberStub;
+import com.google.cloud.pubsub.v1.stub.SubscriberStub;
+import com.google.cloud.pubsub.v1.stub.SubscriberStubSettings;
+import com.google.iam.v1.GetIamPolicyRequest;
+import com.google.iam.v1.Policy;
+import com.google.iam.v1.TestIamPermissionsRequest;
+import com.google.iam.v1.TestIamPermissionsResponse;
+import com.google.protobuf.FieldMask;
+import com.google.pubsub.v1.AcknowledgeRequest;
+import com.google.pubsub.v1.DeadLetterPolicy;
+import com.google.pubsub.v1.DetachSubscriptionRequest;
+import com.google.pubsub.v1.ProjectName;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.ProjectTopicName;
+import com.google.pubsub.v1.PubsubMessage;
+import com.google.pubsub.v1.PullRequest;
+import com.google.pubsub.v1.PullResponse;
+import com.google.pubsub.v1.PushConfig;
+import com.google.pubsub.v1.ReceivedMessage;
+import com.google.pubsub.v1.Subscription;
+import com.google.pubsub.v1.Topic;
+import com.google.pubsub.v1.TopicName;
+import com.google.pubsub.v1.UpdateSubscriptionRequest;
+import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import utilities.PublishOperations;
+
+/** Pub/Sub sample application compiled with Native Image. */
+public class NativeImagePubSubSample {
+
+ /** Driver for the Pub/Sub Sample application which publishes a message to a specified topic. */
+ public static void main(String[] args) throws Exception {
+ Instant startTime = Instant.now();
+ String projectId = ServiceOptions.getDefaultProjectId();
+
+ String topicId = "native-pubsub-test-" + UUID.randomUUID().toString();
+ String pullSubId = "native-pubsub-test-sub" + UUID.randomUUID().toString();
+ String pushSubId = "native-pubsub-test-sub" + UUID.randomUUID().toString();
+
+ try {
+ // Topic management operations
+ createTopic(projectId, topicId);
+ createPullSubscription(projectId, pullSubId, topicId);
+ createPushSubscription(projectId, pushSubId, topicId);
+ detachSubscription(projectId, pushSubId);
+ getTopicPolicy(projectId, topicId);
+ getSubscriptionPolicy(projectId, pullSubId);
+ listSubscriptionInProject(projectId);
+ listSubscriptionInTopic(projectId, topicId);
+ listTopics(projectId);
+ updateSubscriptionDeadLetterTopic(projectId, pushSubId, topicId, topicId);
+ testTopicPermissions(projectId, topicId);
+ testSubscriptionPermissions(projectId, pushSubId);
+
+ // Publish Operations
+ PublishOperations.publishMessage(projectId, topicId);
+ PublishOperations.publishWithBatchSettings(projectId, topicId);
+ PublishOperations.publishWithCustomAttributes(projectId, topicId);
+ PublishOperations.publishWithErrorHandler(projectId, topicId);
+
+ // Receive messages
+ subscribeSync(projectId, pullSubId);
+ receiveMessagesWithDeliveryAttempts(projectId, pullSubId);
+ } finally {
+ deleteTopic(projectId, topicId);
+ deleteSubscription(projectId, pullSubId);
+ deleteSubscription(projectId, pushSubId);
+ }
+ Instant endTime = Instant.now();
+ Duration duration = Duration.between(startTime, endTime);
+ System.out.println("Duration: " + duration.toString());
+ }
+
+ static void createTopic(String projectId, String topicId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ Topic topic = topicAdminClient.createTopic(topicName);
+ System.out.println("Created topic: " + topic.getName() + " under project: " + projectId);
+ }
+ }
+
+ static void createPullSubscription(String projectId, String subscriptionId, String topicId)
+ throws IOException {
+
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+ Subscription subscription =
+ subscriptionAdminClient.createSubscription(
+ subscriptionName, topicName, PushConfig.getDefaultInstance(), 10);
+ System.out.println("Created pull subscription: " + subscription.getName());
+ }
+ }
+
+ static void createPushSubscription(String projectId, String subscriptionId, String topicId)
+ throws IOException {
+
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ // Intentionally set pushEndpoint empty just to exercise API call
+ PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint("").build();
+
+ Subscription subscription =
+ subscriptionAdminClient.createSubscription(subscriptionName, topicName, pushConfig, 10);
+ System.out.println("Created push subscription: " + subscription.getName());
+ }
+ }
+
+ static void detachSubscription(String projectId, String subscriptionId) throws IOException {
+
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ topicAdminClient.detachSubscription(
+ DetachSubscriptionRequest.newBuilder()
+ .setSubscription(subscriptionName.toString())
+ .build());
+ }
+
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ Subscription subscription = subscriptionAdminClient.getSubscription(subscriptionName);
+ if (subscription.getDetached()) {
+ System.out.println("Subscription is detached.");
+ } else {
+ throw new RuntimeException("Subscription detachment was not successful.");
+ }
+ }
+ }
+
+ static void getSubscriptionPolicy(String projectId, String subscriptionId) throws IOException {
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+ GetIamPolicyRequest getIamPolicyRequest =
+ GetIamPolicyRequest.newBuilder().setResource(subscriptionName.toString()).build();
+ Policy policy = subscriptionAdminClient.getIamPolicy(getIamPolicyRequest);
+ System.out.println("Subscription policy: " + policy.toString().trim());
+ }
+ }
+
+ static void getTopicPolicy(String projectId, String topicId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ GetIamPolicyRequest getIamPolicyRequest =
+ GetIamPolicyRequest.newBuilder().setResource(topicName.toString()).build();
+ Policy policy = topicAdminClient.getIamPolicy(getIamPolicyRequest);
+ System.out.println("Topic policy: " + policy.toString().trim());
+ }
+ }
+
+ static void listSubscriptionInProject(String projectId) throws IOException {
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ ProjectName projectName = ProjectName.of(projectId);
+ int count = 0;
+ for (Subscription subscription :
+ subscriptionAdminClient.listSubscriptions(projectName).iterateAll()) {
+ count += 1;
+ }
+ System.out.println("Subscriptions in project count: " + count);
+ }
+ }
+
+ static void listSubscriptionInTopic(String projectId, String topicId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ int count = 0;
+ for (String subscription : topicAdminClient.listTopicSubscriptions(topicName).iterateAll()) {
+ count += 1;
+ }
+ System.out.println("Subscriptions under topic: " + count);
+ }
+ }
+
+ static void listTopics(String projectId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ ProjectName projectName = ProjectName.of(projectId);
+ int count = 0;
+ for (Topic topic : topicAdminClient.listTopics(projectName).iterateAll()) {
+ count += 1;
+ }
+ System.out.println("Topic count under project: " + count);
+ }
+ }
+
+ static void receiveMessagesWithDeliveryAttempts(String projectId, String subscriptionId) {
+
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ // Instantiate an asynchronous message receiver.
+ MessageReceiver receiver =
+ new MessageReceiver() {
+ @Override
+ public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
+ consumer.ack();
+ }
+ };
+
+ Subscriber subscriber = null;
+ try {
+ subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
+ // Start the subscriber.
+ subscriber.startAsync().awaitRunning();
+ System.out.println("Successfully started an async message receiver.");
+ } finally {
+ // Shut down the subscriber after 10s. Stop receiving messages.
+ subscriber.stopAsync();
+ }
+ }
+
+ static void subscribeSync(String projectId, String subscriptionId) throws IOException {
+ SubscriberStubSettings subscriberStubSettings =
+ SubscriberStubSettings.newBuilder()
+ .setTransportChannelProvider(
+ SubscriberStubSettings.defaultGrpcTransportProviderBuilder()
+ .setMaxInboundMessageSize(20 * 1024 * 1024) // 20MB (maximum message size).
+ .build())
+ .build();
+
+ try (SubscriberStub subscriber = GrpcSubscriberStub.create(subscriberStubSettings)) {
+ String subscriptionName = ProjectSubscriptionName.format(projectId, subscriptionId);
+ PullRequest pullRequest =
+ PullRequest.newBuilder().setMaxMessages(1).setSubscription(subscriptionName).build();
+
+ PullResponse pullResponse = subscriber.pullCallable().call(pullRequest);
+ List ackIds = new ArrayList<>();
+ for (ReceivedMessage message : pullResponse.getReceivedMessagesList()) {
+ String payload = message.getMessage().getData().toStringUtf8();
+ ackIds.add(message.getAckId());
+ System.out.println("Received Payload: " + payload);
+ }
+
+ AcknowledgeRequest acknowledgeRequest =
+ AcknowledgeRequest.newBuilder()
+ .setSubscription(subscriptionName)
+ .addAllAckIds(ackIds)
+ .build();
+
+ subscriber.acknowledgeCallable().call(acknowledgeRequest);
+ }
+ }
+
+ static void updateSubscriptionDeadLetterTopic(
+ String projectId, String subscriptionId, String topicId, String deadLetterTopicId)
+ throws IOException {
+
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ TopicName topicName = TopicName.of(projectId, topicId);
+ TopicName deadLetterTopicName = TopicName.of(projectId, deadLetterTopicId);
+
+ DeadLetterPolicy deadLetterPolicy =
+ DeadLetterPolicy.newBuilder()
+ .setDeadLetterTopic(deadLetterTopicName.toString())
+ .setMaxDeliveryAttempts(20)
+ .build();
+
+ Subscription subscription =
+ Subscription.newBuilder()
+ .setName(subscriptionName.toString())
+ .setTopic(topicName.toString())
+ .setDeadLetterPolicy(deadLetterPolicy)
+ .build();
+
+ FieldMask updateMask = FieldMask.newBuilder().addPaths("dead_letter_policy").build();
+
+ UpdateSubscriptionRequest request =
+ UpdateSubscriptionRequest.newBuilder()
+ .setSubscription(subscription)
+ .setUpdateMask(updateMask)
+ .build();
+
+ Subscription response = subscriptionAdminClient.updateSubscription(request);
+ System.out.println("Updated subscription " + response.getName());
+ }
+ }
+
+ static void testSubscriptionPermissions(String projectId, String subscriptionId)
+ throws IOException {
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ List permissions = new ArrayList<>();
+ permissions.add("pubsub.subscriptions.consume");
+ permissions.add("pubsub.subscriptions.update");
+
+ TestIamPermissionsRequest testIamPermissionsRequest =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(subscriptionName.toString())
+ .addAllPermissions(permissions)
+ .build();
+
+ TestIamPermissionsResponse testedPermissionsResponse =
+ subscriptionAdminClient.testIamPermissions(testIamPermissionsRequest);
+
+ System.out.println(
+ "Tested PubSub subscription permissions\n" + testedPermissionsResponse.toString().trim());
+ }
+ }
+
+ static void testTopicPermissions(String projectId, String topicId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
+
+ List permissions = new ArrayList<>();
+ permissions.add("pubsub.topics.attachSubscription");
+ permissions.add("pubsub.topics.publish");
+ permissions.add("pubsub.topics.update");
+
+ TestIamPermissionsRequest testIamPermissionsRequest =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(topicName.toString())
+ .addAllPermissions(permissions)
+ .build();
+
+ TestIamPermissionsResponse testedPermissionsResponse =
+ topicAdminClient.testIamPermissions(testIamPermissionsRequest);
+
+ System.out.println(
+ "Tested topic permissions\n" + testedPermissionsResponse.toString().trim());
+ }
+ }
+
+ static void deleteTopic(String projectId, String topicId) throws IOException {
+ try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
+ TopicName topicName = TopicName.of(projectId, topicId);
+ try {
+ topicAdminClient.deleteTopic(topicName);
+ System.out.println("Deleted topic " + topicName);
+ } catch (NotFoundException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ static void deleteSubscription(String projectId, String subscriptionId) throws IOException {
+ try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+ try {
+ subscriptionAdminClient.deleteSubscription(subscriptionName);
+ System.out.println("Deleted subscription " + subscriptionName);
+ } catch (NotFoundException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+}
diff --git a/samples/native-image-sample/src/main/java/utilities/PublishOperations.java b/samples/native-image-sample/src/main/java/utilities/PublishOperations.java
new file mode 100644
index 000000000..068312025
--- /dev/null
+++ b/samples/native-image-sample/src/main/java/utilities/PublishOperations.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package utilities;
+
+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.cloud.pubsub.v1.Publisher;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.protobuf.ByteString;
+import com.google.pubsub.v1.PubsubMessage;
+import com.google.pubsub.v1.TopicName;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+/** Sample methods for Publishing messages to a topic in Pub/Sub. */
+public class PublishOperations {
+
+ public static void publishMessage(String projectId, String topicId) throws Exception {
+
+ Publisher publisher = Publisher.newBuilder(TopicName.of(projectId, topicId)).build();
+
+ try {
+ String message = "Pub/Sub Native Image Test published message at timestamp: " + Instant.now();
+ ByteString data = ByteString.copyFromUtf8(message);
+ PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
+
+ publisher.publish(pubsubMessage);
+
+ ApiFuture messageIdFuture = publisher.publish(pubsubMessage);
+ String messageId = messageIdFuture.get();
+
+ System.out.println("Published message with ID: " + messageId);
+ } finally {
+ publisher.shutdown();
+ }
+ }
+
+ public static void publishWithCustomAttributes(String projectId, String topicId)
+ throws Exception {
+
+ TopicName topicName = TopicName.of(projectId, topicId);
+ Publisher publisher = Publisher.newBuilder(topicName).build();
+
+ try {
+ String message = "first message";
+ ByteString data = ByteString.copyFromUtf8(message);
+ PubsubMessage pubsubMessage =
+ PubsubMessage.newBuilder()
+ .setData(data)
+ .putAllAttributes(Collections.singletonMap("year", "2020"))
+ .build();
+
+ // Once published, returns a server-assigned message id (unique within the topic)
+ ApiFuture messageIdFuture = publisher.publish(pubsubMessage);
+ String messageId = messageIdFuture.get();
+ System.out.println("Published a message with custom attributes: " + messageId);
+ } finally {
+ publisher.shutdown();
+ }
+ }
+
+ public static void publishWithBatchSettings(String projectId, String topicId)
+ throws IOException, ExecutionException, InterruptedException {
+
+ TopicName topicName = TopicName.of(projectId, topicId);
+ Publisher publisher = Publisher.newBuilder(topicName).build();
+ List> messageIdFutures = new ArrayList<>();
+
+ try {
+ // schedule publishing one message at a time : messages get automatically batched
+ for (int i = 0; i < 100; i++) {
+ String message = "message " + i;
+ ByteString data = ByteString.copyFromUtf8(message);
+ PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
+
+ // Once published, returns a server-assigned message id (unique within the topic)
+ ApiFuture messageIdFuture = publisher.publish(pubsubMessage);
+ messageIdFutures.add(messageIdFuture);
+ }
+ } finally {
+ // Wait on any pending publish requests.
+ List messageIds = ApiFutures.allAsList(messageIdFutures).get();
+ System.out.println("Published " + messageIds.size() + " messages with batch settings.");
+
+ publisher.shutdown();
+ }
+ }
+
+ public static void publishWithErrorHandler(String projectId, String topicId) throws IOException {
+
+ TopicName topicName = TopicName.of(projectId, topicId);
+ Publisher publisher = null;
+
+ try {
+ // Create a publisher instance with default settings bound to the topic
+ publisher = Publisher.newBuilder(topicName).build();
+
+ List messages = Arrays.asList("first message", "second message");
+
+ for (final String message : messages) {
+ ByteString data = ByteString.copyFromUtf8(message);
+ PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
+
+ // Once published, returns a server-assigned message id (unique within the topic)
+ ApiFuture future = publisher.publish(pubsubMessage);
+
+ // Add an asynchronous callback to handle success / failure
+ ApiFutures.addCallback(
+ future,
+ new ApiFutureCallback() {
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ if (throwable instanceof ApiException) {
+ ApiException apiException = ((ApiException) throwable);
+ // details on the API exception
+ System.out.println(apiException.getStatusCode().getCode());
+ System.out.println(apiException.isRetryable());
+ }
+ System.out.println("Error publishing message : " + message);
+ }
+
+ @Override
+ public void onSuccess(String messageId) {
+ // Once published, returns server-assigned message ids (unique within the topic)
+ System.out.println("Success Callback: Published message " + messageId);
+ }
+ },
+ MoreExecutors.directExecutor());
+ }
+ } finally {
+ if (publisher != null) {
+ // When finished with the publisher, shutdown to free up resources.
+ publisher.shutdown();
+ }
+ }
+ }
+}
diff --git a/samples/native-image-sample/src/test/java/pubsub/NativeImagePubSubSampleIT.java b/samples/native-image-sample/src/test/java/pubsub/NativeImagePubSubSampleIT.java
new file mode 100644
index 000000000..c221d735a
--- /dev/null
+++ b/samples/native-image-sample/src/test/java/pubsub/NativeImagePubSubSampleIT.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pubsub;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.cloud.ServiceOptions;
+import com.google.pubsub.v1.SubscriptionName;
+import com.google.pubsub.v1.TopicName;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import utilities.PublishOperations;
+
+public class NativeImagePubSubSampleIT {
+
+ private static String TOPIC_ID = "native-pubsub-test-" + UUID.randomUUID();
+ private static String PULL_SUB_ID = "native-pubsub-test-sub" + UUID.randomUUID();
+ private static String PUSH_SUB_ID = "native-pubsub-test-sub" + UUID.randomUUID();
+ private static String PROJECT_ID = ServiceOptions.getDefaultProjectId();
+ private static final TopicName TOPIC_NAME = TopicName.of(PROJECT_ID, TOPIC_ID);
+ private static final SubscriptionName PULL_SUBSCRIPTION_NAME =
+ SubscriptionName.of(PROJECT_ID, PULL_SUB_ID);
+ private static final SubscriptionName PUSH_SUBSCRIPTION_NAME =
+ SubscriptionName.of(PROJECT_ID, PUSH_SUB_ID);
+
+ private ByteArrayOutputStream bout;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ bout = new ByteArrayOutputStream();
+ out = new PrintStream(bout);
+ System.setOut(out);
+ }
+
+ @After
+ public void cleanUp() throws IOException {
+ NativeImagePubSubSample.deleteTopic(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.deleteSubscription(PROJECT_ID, PULL_SUB_ID);
+ NativeImagePubSubSample.deleteSubscription(PROJECT_ID, PUSH_SUB_ID);
+ }
+
+ @Test
+ public void testRunTopicManagementOperations() throws IOException {
+ // Topic management operations
+ NativeImagePubSubSample.createTopic(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.createPullSubscription(PROJECT_ID, PULL_SUB_ID, TOPIC_ID);
+ NativeImagePubSubSample.createPushSubscription(PROJECT_ID, PUSH_SUB_ID, TOPIC_ID);
+ NativeImagePubSubSample.detachSubscription(PROJECT_ID, PUSH_SUB_ID);
+ NativeImagePubSubSample.getTopicPolicy(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.getSubscriptionPolicy(PROJECT_ID, PULL_SUB_ID);
+ NativeImagePubSubSample.listSubscriptionInProject(PROJECT_ID);
+ NativeImagePubSubSample.listSubscriptionInTopic(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.listTopics(PROJECT_ID);
+ NativeImagePubSubSample.updateSubscriptionDeadLetterTopic(
+ PROJECT_ID, PUSH_SUB_ID, TOPIC_ID, TOPIC_ID);
+ NativeImagePubSubSample.testTopicPermissions(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.testSubscriptionPermissions(PROJECT_ID, PUSH_SUB_ID);
+
+ // Verify create topic and subscriptions
+ assertThat(bout.toString())
+ .contains("Created topic: " + TOPIC_NAME.toString() + " under project: " + PROJECT_ID);
+ assertThat(bout.toString())
+ .contains("Created pull subscription: " + PULL_SUBSCRIPTION_NAME.toString());
+ assertThat(bout.toString())
+ .contains("Created push subscription: " + PUSH_SUBSCRIPTION_NAME.toString());
+
+ // Verify detach subscription
+ assertThat(bout.toString()).contains("Subscription is detached");
+
+ // Verify topic and subscription IAM policy
+ assertThat(bout.toString()).contains("Topic policy: etag: \"\\000 \\001");
+ assertThat(bout.toString()).contains("Subscription policy: etag: \"\\000 \\001\"");
+
+ // Verify listing of subscriptions and topics
+ assertThat(bout.toString()).contains("Subscriptions in project count:");
+ assertThat(bout.toString()).contains("Subscriptions under topic:");
+ assertThat(bout.toString()).contains("Topic count under project:");
+
+ // Verify update of subscription
+ assertThat(bout.toString()).contains("Updated subscription " + PUSH_SUBSCRIPTION_NAME);
+
+ // Verify topic permissions
+ assertThat(bout.toString()).contains("Tested topic permissions");
+ assertThat(bout.toString()).contains("permissions: \"pubsub.topics.attachSubscription\"");
+ assertThat(bout.toString()).contains("permissions: \"pubsub.topics.publish\"");
+ assertThat(bout.toString()).contains("permissions: \"pubsub.topics.update\"");
+
+ // Verify subscription permissions
+ assertThat(bout.toString()).contains("Tested PubSub subscription permissions");
+ assertThat(bout.toString()).contains("permissions: \"pubsub.subscriptions.consume\"");
+ assertThat(bout.toString()).contains("permissions: \"pubsub.subscriptions.update\"");
+ }
+
+ @Test
+ public void testPublishAndSubscribe() throws Exception {
+ NativeImagePubSubSample.createTopic(PROJECT_ID, TOPIC_ID);
+ NativeImagePubSubSample.createPullSubscription(PROJECT_ID, PULL_SUB_ID, TOPIC_ID);
+
+ bout.reset();
+
+ // Publish
+ PublishOperations.publishMessage(PROJECT_ID, TOPIC_ID);
+ PublishOperations.publishWithBatchSettings(PROJECT_ID, TOPIC_ID);
+ PublishOperations.publishWithCustomAttributes(PROJECT_ID, TOPIC_ID);
+ PublishOperations.publishWithErrorHandler(PROJECT_ID, TOPIC_ID);
+
+ // Subscribe
+ NativeImagePubSubSample.subscribeSync(PROJECT_ID, PULL_SUB_ID);
+ NativeImagePubSubSample.receiveMessagesWithDeliveryAttempts(PROJECT_ID, PULL_SUB_ID);
+
+ assertThat(bout.toString()).contains("Published message with ID");
+ assertThat(bout.toString()).contains("Published 100 messages with batch settings.");
+ assertThat(bout.toString()).contains("Published a message with custom attributes");
+ assertThat(bout.toString()).contains("Success Callback: Published message");
+ assertThat(bout.toString()).contains("Success Callback: Published message");
+ assertThat(bout.toString()).contains("Received Payload");
+ assertThat(bout.toString()).contains("Successfully started an async message receiver");
+ }
+}
diff --git a/samples/pom.xml b/samples/pom.xml
index c3399fdec..e138ae3bc 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -46,6 +46,7 @@
install-without-bomsnapshotsnippets
+ native-image-sample
From 7c9beab944f0b404cec764b3c9c062122a6d5ab0 Mon Sep 17 00:00:00 2001
From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com>
Date: Tue, 8 Mar 2022 02:43:06 +0000
Subject: [PATCH 04/22] chore: update java template (#1367) (#1045)
* chore: update java template
* chore: fix tests
* chore: fix tests
* chore: update project
Source-Link: https://github.com/googleapis/synthtool/commit/1155a97fed1c195d10ad406d483bc8ac2507f1d7
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:b0b1c1c89570e229b1026372a2b8989ba31495007055b8d30178b7648503eefa
---
.github/.OwlBot.lock.yaml | 2 +-
.kokoro/nightly/integration.cfg | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml
index 3473042c0..426cf83e2 100644
--- a/.github/.OwlBot.lock.yaml
+++ b/.github/.OwlBot.lock.yaml
@@ -13,4 +13,4 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
- digest: sha256:df8d7b2cc0dbc65871e7edd86601901a0612b272fa3f7f0eb590c5c53aa5f92e
+ digest: sha256:b0b1c1c89570e229b1026372a2b8989ba31495007055b8d30178b7648503eefa
diff --git a/.kokoro/nightly/integration.cfg b/.kokoro/nightly/integration.cfg
index e51c7b4c6..a2907a257 100644
--- a/.kokoro/nightly/integration.cfg
+++ b/.kokoro/nightly/integration.cfg
@@ -13,12 +13,12 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
- value: "gcloud-devel"
+ value: "java-docs-samples-testing"
}
env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
- value: "gcloud-devel"
+ value: "java-docs-samples-testing"
}
env_vars: {
From 158e7f884660a312b7168cecfa85cf594071a7be Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 8 Mar 2022 04:00:34 +0100
Subject: [PATCH 05/22] deps: update dependency
org.graalvm.buildtools:native-maven-plugin to v0.9.10 (#1044)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.graalvm.buildtools:native-maven-plugin](https://togithub.com/graalvm/native-build-tools) | `0.9.9` -> `0.9.10` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Release Notes
graalvm/native-build-tools
### [`v0.9.10`](https://togithub.com/graalvm/native-build-tools/releases/0.9.10)
[Compare Source](https://togithub.com/graalvm/native-build-tools/compare/0.9.9...0.9.10)
#### What's Changed
Read what's new in the [documentation](https://graalvm.github.io/native-build-tools/latest/index.html#changelog).
- Introduce skipNativeTests flag in Maven plugin by [@sbrannen](https://togithub.com/sbrannen) in [https://github.com/graalvm/native-build-tools/pull/193](https://togithub.com/graalvm/native-build-tools/pull/193)
- Fix system property breaking build cacheability by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/192](https://togithub.com/graalvm/native-build-tools/pull/192)
- Make sure executable ends with `.exe` under Windows by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/199](https://togithub.com/graalvm/native-build-tools/pull/199)
- Make it possible to override the classpath by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/200](https://togithub.com/graalvm/native-build-tools/pull/200)
- Upgrade to Gradle 7.4 by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/202](https://togithub.com/graalvm/native-build-tools/pull/202)
- Fix race condition if tests are executed in parallel by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/195](https://togithub.com/graalvm/native-build-tools/pull/195)
- Add support for `@arg` file by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/205](https://togithub.com/graalvm/native-build-tools/pull/205)
**Full Changelog**: https://github.com/graalvm/native-build-tools/compare/0.9.9...0.9.10
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
â™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-pubsub).
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index afdfa8e56..0520e1e81 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -139,7 +139,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
org.graalvm.buildtoolsnative-maven-plugin
- 0.9.9
+ 0.9.10truepubsub.NativeImagePubSubSample
From 5884bdfafc5ee621935b620e763ca6c0adf67ff7 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 8 Mar 2022 04:00:51 +0100
Subject: [PATCH 06/22] deps: update dependency
org.graalvm.buildtools:junit-platform-native to v0.9.10 (#1043)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.graalvm.buildtools:junit-platform-native](https://togithub.com/graalvm/native-build-tools) | `0.9.9` -> `0.9.10` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Release Notes
graalvm/native-build-tools
### [`v0.9.10`](https://togithub.com/graalvm/native-build-tools/releases/0.9.10)
[Compare Source](https://togithub.com/graalvm/native-build-tools/compare/0.9.9...0.9.10)
#### What's Changed
Read what's new in the [documentation](https://graalvm.github.io/native-build-tools/latest/index.html#changelog).
- Introduce skipNativeTests flag in Maven plugin by [@sbrannen](https://togithub.com/sbrannen) in [https://github.com/graalvm/native-build-tools/pull/193](https://togithub.com/graalvm/native-build-tools/pull/193)
- Fix system property breaking build cacheability by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/192](https://togithub.com/graalvm/native-build-tools/pull/192)
- Make sure executable ends with `.exe` under Windows by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/199](https://togithub.com/graalvm/native-build-tools/pull/199)
- Make it possible to override the classpath by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/200](https://togithub.com/graalvm/native-build-tools/pull/200)
- Upgrade to Gradle 7.4 by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/202](https://togithub.com/graalvm/native-build-tools/pull/202)
- Fix race condition if tests are executed in parallel by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/195](https://togithub.com/graalvm/native-build-tools/pull/195)
- Add support for `@arg` file by [@melix](https://togithub.com/melix) in [https://github.com/graalvm/native-build-tools/pull/205](https://togithub.com/graalvm/native-build-tools/pull/205)
**Full Changelog**: https://github.com/graalvm/native-build-tools/compare/0.9.9...0.9.10
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
â™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-pubsub).
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 0520e1e81..5725bad2c 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -118,7 +118,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
org.graalvm.buildtoolsjunit-platform-native
- 0.9.9
+ 0.9.10test
From 6ae2932fb65b4dd43085d37e235c348ff48b0234 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 8 Mar 2022 17:26:19 +0100
Subject: [PATCH 07/22] build(deps): update dependency
com.google.cloud:google-cloud-shared-config to v1.3.0 (#1046)
---
google-cloud-pubsub-bom/pom.xml | 2 +-
pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/google-cloud-pubsub-bom/pom.xml b/google-cloud-pubsub-bom/pom.xml
index 29368bb2a..0810409ba 100644
--- a/google-cloud-pubsub-bom/pom.xml
+++ b/google-cloud-pubsub-bom/pom.xml
@@ -8,7 +8,7 @@
com.google.cloudgoogle-cloud-shared-config
- 1.2.7
+ 1.3.0Google Cloud pubsub BOM
diff --git a/pom.xml b/pom.xml
index 8511099e7..5ab2a032d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
com.google.cloudgoogle-cloud-shared-config
- 1.2.7
+ 1.3.0
From fd52aa8ffaa4d7cb8e0ad19bb6993b5616eb81df Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 8 Mar 2022 17:26:36 +0100
Subject: [PATCH 08/22] deps: update dependency
com.google.cloud:native-image-support to v0.12.7 (#1042)
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 5725bad2c..774dc4a83 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -107,7 +107,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
com.google.cloudnative-image-support
- 0.12.4
+ 0.12.7org.junit.vintage
From eaeedd8bbe31cad3810687a29c5999f76876671d Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 8 Mar 2022 18:15:19 +0100
Subject: [PATCH 09/22] test(deps): update dependency org.mockito:mockito-core
to v4.4.0 (#1047)
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5ab2a032d..41eb4d685 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,7 +92,7 @@
org.mockitomockito-core
- 4.3.1
+ 4.4.0test
From c7551d621343eac4476a16579763e3aab7f71ea9 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Wed, 9 Mar 2022 18:30:16 +0100
Subject: [PATCH 10/22] deps: update dependency
com.google.cloud:google-cloud-core to v2.5.8 (#1050)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-core](https://togithub.com/googleapis/java-core) | `2.5.6` -> `2.5.8` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Release Notes
googleapis/java-core
### [`v2.5.8`](https://togithub.com/googleapis/java-core/blob/HEAD/CHANGELOG.md#258-httpsgithubcomgoogleapisjava-corecomparev257v258-2022-03-08)
[Compare Source](https://togithub.com/googleapis/java-core/compare/v2.5.7...v2.5.8)
### [`v2.5.7`](https://togithub.com/googleapis/java-core/blob/HEAD/CHANGELOG.md#257-httpsgithubcomgoogleapisjava-corecomparev256v257-2022-03-08)
[Compare Source](https://togithub.com/googleapis/java-core/compare/v2.5.6...v2.5.7)
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
â™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-pubsub).
---
samples/install-without-bom/pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index ca6c776db..7125a24ad 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -80,7 +80,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.6
+ 2.5.8tests
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 2b875a222..164a24231 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -79,7 +79,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.6
+ 2.5.8tests
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 01f343c68..8eb6e56c0 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -90,7 +90,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.6
+ 2.5.8tests
From 9add53894981d862ac1348d0b641e472b3b3aa79 Mon Sep 17 00:00:00 2001
From: Mike Micatka <31972785+mmicatka@users.noreply.github.com>
Date: Wed, 9 Mar 2022 14:12:08 -0500
Subject: [PATCH 11/22] Fix: Removed EnableExactlyOnceDelivery from Builders
(#1052)
Removed EnableExactlyOnceDelivery from `Subscriber.Builder`, `StreamingSubscriberConnection.Builder`, and `MessageDispatcher.Builder`.
Added comments to `AckReplyConsumerWithResponse` to be in line with `AckReplyConsumer`
---
.../clirr-ignored-differences.xml | 20 +++++++++++
.../v1/AckReplyConsumerWithResponse.java | 26 ++++++++++++++
.../cloud/pubsub/v1/MessageDispatcher.java | 21 ++++--------
.../v1/StreamingSubscriberConnection.java | 23 +++----------
.../google/cloud/pubsub/v1/Subscriber.java | 22 ------------
.../google/cloud/pubsub/it/ITPubSubTest.java | 3 --
.../pubsub/v1/MessageDispatcherTest.java | 34 +++++++++++++------
.../v1/StreamingSubscriberConnectionTest.java | 16 +++++----
.../cloud/pubsub/v1/SubscriberTest.java | 11 ------
9 files changed, 92 insertions(+), 84 deletions(-)
create mode 100644 google-cloud-pubsub/clirr-ignored-differences.xml
diff --git a/google-cloud-pubsub/clirr-ignored-differences.xml b/google-cloud-pubsub/clirr-ignored-differences.xml
new file mode 100644
index 000000000..610c1b362
--- /dev/null
+++ b/google-cloud-pubsub/clirr-ignored-differences.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+ 7002
+ com/google/cloud/pubsub/v1/Subscriber$Builder
+ com.google.cloud.pubsub.v1.Subscriber$Builder setExactlyOnceDeliveryEnabled(boolean)
+
+
+ 7002
+ com/google/cloud/pubsub/v1/StreamingSubscriberConnection$Builder
+ com.google.cloud.pubsub.v1.StreamingSubscriberConnection$Builder setExactlyOnceDeliveryEnabled(boolean)
+
+
+ 7002
+ com/google/cloud/pubsub/v1/MessageDispatcher$Builder
+ com.google.cloud.pubsub.v1.MessageDispatcher$Builder setEnableExactlyOnceDelivery(boolean)
+
+
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/AckReplyConsumerWithResponse.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/AckReplyConsumerWithResponse.java
index 199186004..ec2a27f3b 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/AckReplyConsumerWithResponse.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/AckReplyConsumerWithResponse.java
@@ -18,8 +18,34 @@
import java.util.concurrent.Future;
+/**
+ * Acknowledging a message in Pub/Sub means that you are done with it, and it will not be delivered
+ * to this subscription again. You should avoid acknowledging messages until you have *finished*
+ * processing them, so that in the event of a failure, you receive the message again.
+ *
+ *
If exactly-once delivery is enabled on the subscription, the future returned by the ack/nack
+ * methods track the state of acknowledgement operation by the server. If the future completes
+ * successfully, the message is guaranteed NOT to be re-delivered. Otherwise, the future will
+ * contain an exception with more details about the failure and the message may be re-delivered.
+ *
+ *
If exactly-once delivery is NOT enabled on the subscription, the future returns immediately
+ * with an AckResponse.SUCCESS. Because re-deliveries are possible, you should ensure that your
+ * processing code is idempotent, as you may receive any given message more than once.
+ */
public interface AckReplyConsumerWithResponse {
+ /**
+ * Acknowledges that the message has been successfully processed. The service will not send the
+ * message again.
+ *
+ *
A future representing the server response is returned
+ */
Future ack();
+ /**
+ * Signals that the message has not been successfully processed. The service should resend the
+ * message.
+ *
+ *
A future representing the server response is returned
+ */
Future nack();
}
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/MessageDispatcher.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/MessageDispatcher.java
index a9f73d5c3..31693a189 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/MessageDispatcher.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/MessageDispatcher.java
@@ -70,7 +70,7 @@ class MessageDispatcher {
private final FlowController flowController;
- private AtomicBoolean enableExactlyOnceDelivery;
+ private AtomicBoolean exactlyOnceDeliveryEnabled = new AtomicBoolean(false);
private final Waiter messagesWaiter;
@@ -198,7 +198,6 @@ private MessageDispatcher(Builder builder) {
ackProcessor = builder.ackProcessor;
flowController = builder.flowController;
- enableExactlyOnceDelivery = new AtomicBoolean(builder.enableExactlyOnceDelivery);
ackLatencyDistribution = builder.ackLatencyDistribution;
clock = builder.clock;
jobLock = new ReentrantLock();
@@ -296,13 +295,13 @@ int getMessageDeadlineSeconds() {
}
@InternalApi
- void setEnableExactlyOnceDelivery(boolean enableExactlyOnceDelivery) {
- // Sanity check that we are changing the enableExactlyOnceDelivery state
- if (enableExactlyOnceDelivery == this.enableExactlyOnceDelivery.get()) {
+ void setExactlyOnceDeliveryEnabled(boolean exactlyOnceDeliveryEnabled) {
+ // Sanity check that we are changing the exactlyOnceDeliveryEnabled state
+ if (exactlyOnceDeliveryEnabled == this.exactlyOnceDeliveryEnabled.get()) {
return;
}
- this.enableExactlyOnceDelivery.set(enableExactlyOnceDelivery);
+ this.exactlyOnceDeliveryEnabled.set(exactlyOnceDeliveryEnabled);
// If a custom value for minDurationPerAckExtension, we should respect that
if (!minDurationPerAckExtensionDefaultUsed) {
@@ -313,7 +312,7 @@ void setEnableExactlyOnceDelivery(boolean enableExactlyOnceDelivery) {
// maxDurationPerAckExtensionSeconds does not change
int possibleNewMinAckDeadlineExtensionSeconds;
- if (enableExactlyOnceDelivery) {
+ if (exactlyOnceDeliveryEnabled) {
possibleNewMinAckDeadlineExtensionSeconds =
Math.toIntExact(
Subscriber.DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY.getSeconds());
@@ -323,7 +322,7 @@ void setEnableExactlyOnceDelivery(boolean enableExactlyOnceDelivery) {
}
// If we are not using the default maxDurationAckExtension, check if the
- // minAckDeadlineExtensionExactlyOnce needs to be bounded by the set max
+ // minAckDeadlineExtensionExactlyOnceDelivery needs to be bounded by the set max
if (!maxDurationPerAckExtensionDefaultUsed
&& (possibleNewMinAckDeadlineExtensionSeconds > maxDurationPerAckExtensionSeconds)) {
minDurationPerAckExtensionSeconds = maxDurationPerAckExtensionSeconds;
@@ -580,7 +579,6 @@ public static final class Builder {
private Distribution ackLatencyDistribution;
private FlowController flowController;
- private boolean enableExactlyOnceDelivery;
private Executor executor;
private ScheduledExecutorService systemExecutor;
@@ -641,11 +639,6 @@ public Builder setFlowController(FlowController flowController) {
return this;
}
- public Builder setEnableExactlyOnceDelivery(boolean enableExactlyOnceDelivery) {
- this.enableExactlyOnceDelivery = enableExactlyOnceDelivery;
- return this;
- }
-
public Builder setExecutor(Executor executor) {
this.executor = executor;
return this;
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java
index d1af3a3e9..78f35efea 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnection.java
@@ -103,12 +103,7 @@ private StreamingSubscriberConnection(Builder builder) {
// We need to set the default stream ack deadline on the initial request, this will be
// updated by modack requests in the message dispatcher
if (builder.maxDurationPerAckExtensionDefaultUsed) {
- // If the default is used, check if exactly once is enabled and set appropriately
- if (builder.exactlyOnceDeliveryEnabled) {
- inititalStreamAckDeadline = Subscriber.STREAM_ACK_DEADLINE_EXACTLY_ONCE_DELIVERY_DEFAULT;
- } else {
- inititalStreamAckDeadline = Subscriber.STREAM_ACK_DEADLINE_DEFAULT;
- }
+ inititalStreamAckDeadline = Subscriber.STREAM_ACK_DEADLINE_DEFAULT;
} else if (builder.maxDurationPerAckExtension.compareTo(Subscriber.MIN_STREAM_ACK_DEADLINE)
< 0) {
// We will not be able to extend more than the default minimum
@@ -123,7 +118,6 @@ private StreamingSubscriberConnection(Builder builder) {
subscriberStub = builder.subscriberStub;
channelAffinity = builder.channelAffinity;
- exactlyOnceDeliveryEnabled.set(builder.exactlyOnceDeliveryEnabled);
MessageDispatcher.Builder messageDispatcherBuilder;
if (builder.receiver != null) {
@@ -143,7 +137,6 @@ private StreamingSubscriberConnection(Builder builder) {
.setMaxDurationPerAckExtensionDefaultUsed(builder.maxDurationPerAckExtensionDefaultUsed)
.setAckLatencyDistribution(builder.ackLatencyDistribution)
.setFlowController(builder.flowController)
- .setEnableExactlyOnceDelivery(builder.exactlyOnceDeliveryEnabled)
.setExecutor(builder.executor)
.setSystemExecutor(builder.systemExecutor)
.setApiClock(builder.clock)
@@ -159,7 +152,7 @@ public StreamingSubscriberConnection setExactlyOnceDeliveryEnabled(
return this;
}
- public boolean isExactlyOnceDeliveryEnabled() {
+ public boolean getExactlyOnceDeliveryEnabled() {
return exactlyOnceDeliveryEnabled.get();
}
@@ -221,7 +214,7 @@ public void onResponse(StreamingPullResponse response) {
response.getSubscriptionProperties().getExactlyOnceDeliveryEnabled();
setExactlyOnceDeliveryEnabled(exactlyOnceDeliveryEnabledResponse);
- messageDispatcher.setEnableExactlyOnceDelivery(exactlyOnceDeliveryEnabledResponse);
+ messageDispatcher.setExactlyOnceDeliveryEnabled(exactlyOnceDeliveryEnabledResponse);
messageDispatcher.processReceivedMessages(response.getReceivedMessagesList());
// Only request more if we're not shutdown.
@@ -370,7 +363,7 @@ public void setResponseOutstandingMessages(AckResponse ackResponse) {
private void setFailureFutureOutstandingMessages(Throwable t) {
AckResponse ackResponse;
- if (isExactlyOnceDeliveryEnabled()) {
+ if (getExactlyOnceDeliveryEnabled()) {
if (!(t instanceof ApiException)) {
ackResponse = AckResponse.OTHER;
}
@@ -518,7 +511,7 @@ public void onFailure(Throwable t) {
// Remove from our pending operations
ackOperationsWaiter.incrementPendingCount(-1);
- if (!isExactlyOnceDeliveryEnabled()) {
+ if (!getExactlyOnceDeliveryEnabled()) {
Level level = isAlive() ? Level.WARNING : Level.FINER;
logger.log(level, "failed to send operations", t);
return;
@@ -609,7 +602,6 @@ public static final class Builder {
private int channelAffinity;
private FlowController flowController;
private FlowControlSettings flowControlSettings;
- private boolean exactlyOnceDeliveryEnabled;
private boolean useLegacyFlowControl;
private ScheduledExecutorService executor;
private ScheduledExecutorService systemExecutor;
@@ -690,11 +682,6 @@ public Builder setUseLegacyFlowControl(boolean useLegacyFlowControl) {
return this;
}
- public Builder setExactlyOnceDeliveryEnabled(boolean exactlyOnceDeliveryEnabled) {
- this.exactlyOnceDeliveryEnabled = exactlyOnceDeliveryEnabled;
- return this;
- }
-
public Builder setExecutor(ScheduledExecutorService executor) {
this.executor = executor;
return this;
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java
index 4ee66b031..1bd74f3bb 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java
@@ -134,7 +134,6 @@ public class Subscriber extends AbstractApiService implements SubscriberInterfac
private SubscriberStub subscriberStub;
private final SubscriberStubSettings subStubSettings;
private final FlowController flowController;
- private boolean exactlyOnceDeliveryEnabled = false;
private final int numPullers;
private final MessageReceiver receiver;
@@ -166,8 +165,6 @@ private Subscriber(Builder builder) {
.setLimitExceededBehavior(LimitExceededBehavior.Block)
.build());
- exactlyOnceDeliveryEnabled = builder.exactlyOnceDeliveryEnabled;
-
this.numPullers = builder.parallelPullCount;
executorProvider = builder.executorProvider;
@@ -385,7 +382,6 @@ private void startStreamingConnections() {
.setExecutor(executor)
.setSystemExecutor(alarmsExecutor)
.setClock(clock)
- .setExactlyOnceDeliveryEnabled(exactlyOnceDeliveryEnabled)
.build();
streamingSubscriberConnections.add(streamingSubscriberConnection);
@@ -479,8 +475,6 @@ public static final class Builder {
private boolean useLegacyFlowControl = false;
private FlowControlSettings flowControlSettings = DEFAULT_FLOW_CONTROL_SETTINGS;
- private boolean exactlyOnceDeliveryEnabled = false;
-
private ExecutorProvider executorProvider = DEFAULT_EXECUTOR_PROVIDER;
private ExecutorProvider systemExecutorProvider = null;
private TransportChannelProvider channelProvider =
@@ -573,22 +567,6 @@ public Builder setUseLegacyFlowControl(boolean value) {
return this;
}
- /**
- * Enables/Disabled ExactlyOnceDelivery
- *
- *
Will update the minDurationPerAckExtension if a user-provided value is not set
- */
- public Builder setExactlyOnceDeliveryEnabled(boolean exactlyOnceDeliveryEnabled) {
- // If exactlyOnceDeliveryIsEnabled we want to update the default minAckDeadlineExtension if
- // applicable
- if (exactlyOnceDeliveryEnabled && this.minDurationPerAckExtensionDefaultUsed) {
- this.minDurationPerAckExtension = DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY;
- }
-
- this.exactlyOnceDeliveryEnabled = exactlyOnceDeliveryEnabled;
- return this;
- }
-
/**
* Set the maximum period a message ack deadline will be extended. Defaults to one hour.
*
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java
index 7fcee6b2e..c72d52d3d 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java
@@ -209,7 +209,6 @@ public void receiveMessage(
receiveQueue.offer(MessageAndConsumer.create(message, consumer));
}
})
- .setExactlyOnceDeliveryEnabled(true)
.build();
subscriber.addListener(
new Subscriber.Listener() {
@@ -282,7 +281,6 @@ public void receiveMessage(
SubscriptionAdminSettings.defaultGrpcTransportProviderBuilder()
.setMaxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
.build())
- .setExactlyOnceDeliveryEnabled(false)
.build();
subscriber.addListener(
new Subscriber.Listener() {
@@ -360,7 +358,6 @@ public void receiveMessage(
SubscriptionAdminSettings.defaultGrpcTransportProviderBuilder()
.setMaxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
.build())
- .setExactlyOnceDeliveryEnabled(false)
.build();
subscriber.addListener(
new Subscriber.Listener() {
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java
index 3ff13acfc..0b48e0991 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java
@@ -337,8 +337,7 @@ public void testExtension_GiveUp() throws Exception {
}
@Test
- public void testAckExtensionDefaultsExactlyOnceDeliveryOffThenOn() {
- // EnableExactlyOnceDelivery is turned off by default
+ public void testAckExtensionDefaultsExactlyOnceDeliveryDisabledThenEnabled() {
MessageDispatcher messageDispatcher =
MessageDispatcher.newBuilder(mock(MessageReceiver.class))
.setAckLatencyDistribution(mockAckLatencyDistribution)
@@ -348,13 +347,17 @@ public void testAckExtensionDefaultsExactlyOnceDeliveryOffThenOn() {
.setMaxDurationPerAckExtensionDefaultUsed(true)
.build();
+ // ExactlyOnceDeliveryEnabled is turned off by default
+
// We should be using the Subscriber set hard deadlines
assertMinAndMaxAckDeadlines(
messageDispatcher,
Math.toIntExact(Subscriber.MIN_STREAM_ACK_DEADLINE.getSeconds()),
Math.toIntExact(Subscriber.MAX_STREAM_ACK_DEADLINE.getSeconds()));
- messageDispatcher.setEnableExactlyOnceDelivery(true);
+ // This would normally be set from the streaming pull response in the
+ // StreamingSubscriberConnection
+ messageDispatcher.setExactlyOnceDeliveryEnabled(true);
// Should only change min deadline
assertMinAndMaxAckDeadlines(
@@ -365,11 +368,10 @@ public void testAckExtensionDefaultsExactlyOnceDeliveryOffThenOn() {
}
@Test
- public void testAckExtensionDefaultsExactlyOnceDeliveryOnThenOff() {
+ public void testAckExtensionDefaultsExactlyOnceDeliveryEnabledThenDisabled() {
MessageDispatcher messageDispatcher =
MessageDispatcher.newBuilder(mock(MessageReceiver.class))
.setAckLatencyDistribution(mockAckLatencyDistribution)
- .setEnableExactlyOnceDelivery(true)
.setMinDurationPerAckExtension(
Subscriber.DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY)
.setMinDurationPerAckExtensionDefaultUsed(true)
@@ -377,13 +379,19 @@ public void testAckExtensionDefaultsExactlyOnceDeliveryOnThenOff() {
.setMaxDurationPerAckExtensionDefaultUsed(true)
.build();
+ // This would normally be set from the streaming pull response in the
+ // StreamingSubscriberConnection
+ messageDispatcher.setExactlyOnceDeliveryEnabled(true);
+
assertMinAndMaxAckDeadlines(
messageDispatcher,
Math.toIntExact(
Subscriber.DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY.getSeconds()),
Math.toIntExact(Subscriber.MAX_STREAM_ACK_DEADLINE.getSeconds()));
- messageDispatcher.setEnableExactlyOnceDelivery(false);
+ // This would normally be set from the streaming pull response in the
+ // StreamingSubscriberConnection
+ messageDispatcher.setExactlyOnceDeliveryEnabled(false);
// Should change min deadline
assertMinAndMaxAckDeadlines(
@@ -393,7 +401,7 @@ public void testAckExtensionDefaultsExactlyOnceDeliveryOnThenOff() {
}
@Test
- public void testAckExtensionCustomMinExactlyOnceDeliveryOffThenOn() {
+ public void testAckExtensionCustomMinExactlyOnceDeliveryDisabledThenEnabled() {
int customMinSeconds = 30;
MessageDispatcher messageDispatcher =
MessageDispatcher.newBuilder(mock(MessageReceiver.class))
@@ -404,12 +412,15 @@ public void testAckExtensionCustomMinExactlyOnceDeliveryOffThenOn() {
.setMaxDurationPerAckExtensionDefaultUsed(true)
.build();
+ // ExactlyOnceDeliveryEnabled is turned off by default
assertMinAndMaxAckDeadlines(
messageDispatcher,
customMinSeconds,
Math.toIntExact(Subscriber.MAX_STREAM_ACK_DEADLINE.getSeconds()));
- messageDispatcher.setEnableExactlyOnceDelivery(true);
+ // This would normally be set from the streaming pull response in the
+ // StreamingSubscriberConnection
+ messageDispatcher.setExactlyOnceDeliveryEnabled(true);
// no changes should occur
assertMinAndMaxAckDeadlines(
@@ -419,7 +430,7 @@ public void testAckExtensionCustomMinExactlyOnceDeliveryOffThenOn() {
}
@Test
- public void testAckExtensionCustomMaxExactlyOnceDeliveryOffThenOn() {
+ public void testAckExtensionCustomMaxExactlyOnceDeliveryDisabledThenEnabled() {
int customMaxSeconds = 30;
MessageDispatcher messageDispatcher =
MessageDispatcher.newBuilder(mock(MessageReceiver.class))
@@ -430,12 +441,15 @@ public void testAckExtensionCustomMaxExactlyOnceDeliveryOffThenOn() {
.setMaxDurationPerAckExtensionDefaultUsed(false)
.build();
+ // ExactlyOnceDeliveryEnabled is turned off by default
assertMinAndMaxAckDeadlines(
messageDispatcher,
Math.toIntExact(Subscriber.MIN_STREAM_ACK_DEADLINE.getSeconds()),
customMaxSeconds);
- messageDispatcher.setEnableExactlyOnceDelivery(true);
+ // This would normally be set from the streaming pull response in the
+ // StreamingSubscriberConnection
+ messageDispatcher.setExactlyOnceDeliveryEnabled(true);
// Because the customMaxSeconds is above the
// DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY, we should use the customMaxSeconds
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnectionTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnectionTest.java
index 6ad951001..d8e1878dd 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnectionTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/StreamingSubscriberConnectionTest.java
@@ -452,13 +452,18 @@ public void testSetFailureResponseOutstandingMessages() {
private StreamingSubscriberConnection getStreamingSubscriberConnection(
boolean exactlyOnceDeliveryEnabled) {
- return getStreamingSubscriberReceiverFromBuilder(
- StreamingSubscriberConnection.newBuilder(mock(MessageReceiverWithAckResponse.class)),
- exactlyOnceDeliveryEnabled);
+ StreamingSubscriberConnection streamingSubscriberConnection =
+ getStreamingSubscriberConnectionFromBuilder(
+ StreamingSubscriberConnection.newBuilder(mock(MessageReceiverWithAckResponse.class)));
+
+ // This would normally be set from the streaming pull response
+ streamingSubscriberConnection.setExactlyOnceDeliveryEnabled(exactlyOnceDeliveryEnabled);
+
+ return streamingSubscriberConnection;
}
- private StreamingSubscriberConnection getStreamingSubscriberReceiverFromBuilder(
- StreamingSubscriberConnection.Builder builder, boolean exactlyOnceDeliveryEnabled) {
+ private StreamingSubscriberConnection getStreamingSubscriberConnectionFromBuilder(
+ StreamingSubscriberConnection.Builder builder) {
return builder
.setSubscription(MOCK_SUBSCRIPTION_NAME)
.setAckExpirationPadding(ACK_EXPIRATION_PADDING_DEFAULT)
@@ -474,7 +479,6 @@ private StreamingSubscriberConnection getStreamingSubscriberReceiverFromBuilder(
.setMinDurationPerAckExtensionDefaultUsed(true)
.setMaxDurationPerAckExtension(Subscriber.DEFAULT_MAX_ACK_DEADLINE_EXTENSION)
.setMaxDurationPerAckExtensionDefaultUsed(true)
- .setExactlyOnceDeliveryEnabled(exactlyOnceDeliveryEnabled)
.build();
}
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java
index ab7021bba..612c244fe 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java
@@ -287,16 +287,6 @@ public void testStreamAckDeadlineIsSetCorrectly() throws Exception {
fakeSubscriberServiceImpl.getLastSeenRequest().getStreamAckDeadlineSeconds());
subscriber.stopAsync().awaitTerminated();
-
- // maxDurationPerAckExtension is unset with exactly once enabled
- subscriber =
- startSubscriber(getTestSubscriberBuilder(testReceiver).setExactlyOnceDeliveryEnabled(true));
- assertEquals(
- expectedChannelCount, fakeSubscriberServiceImpl.waitForOpenedStreams(expectedChannelCount));
- assertEquals(
- Math.toIntExact(Subscriber.STREAM_ACK_DEADLINE_EXACTLY_ONCE_DELIVERY_DEFAULT.getSeconds()),
- fakeSubscriberServiceImpl.getLastSeenRequest().getStreamAckDeadlineSeconds());
- subscriber.stopAsync().awaitTerminated();
}
@Test
@@ -358,7 +348,6 @@ private Builder getTestSubscriberBuilder(
.setCredentialsProvider(NoCredentialsProvider.create())
.setClock(fakeExecutor.getClock())
.setParallelPullCount(1)
- .setExactlyOnceDeliveryEnabled(true)
.setFlowControlSettings(
FlowControlSettings.newBuilder().setMaxOutstandingElementCount(1000L).build());
}
From da2d3fa91fe4f07455fbe0aa3ccac15e456666c7 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Wed, 9 Mar 2022 20:30:36 +0100
Subject: [PATCH 12/22] deps: update dependency
com.google.cloud:native-image-support to v0.12.8 (#1051)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:native-image-support](https://togithub.com/googleapis/java-core) | `0.12.7` -> `0.12.8` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
â™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-pubsub).
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 774dc4a83..3c28907e8 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -107,7 +107,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
com.google.cloudnative-image-support
- 0.12.7
+ 0.12.8org.junit.vintage
From 6e97d5222994dc567bc24ab3457f3431ed000134 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Wed, 9 Mar 2022 21:36:36 +0100
Subject: [PATCH 13/22] deps: update dependency
com.google.cloud:native-image-support to v0.12.9 (#1053)
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 3c28907e8..9e5929d77 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -107,7 +107,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
com.google.cloudnative-image-support
- 0.12.8
+ 0.12.9org.junit.vintage
From 5b3227f4013a5121a3db34702f90be5a9ba41748 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Thu, 10 Mar 2022 18:11:45 +0100
Subject: [PATCH 14/22] deps: update dependency
com.google.cloud:google-cloud-core to v2.5.9 (#1054)
---
samples/install-without-bom/pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 7125a24ad..8724d7e43 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -80,7 +80,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.8
+ 2.5.9tests
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 164a24231..c8def65fd 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -79,7 +79,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.8
+ 2.5.9tests
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 8eb6e56c0..1841793e5 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -90,7 +90,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.8
+ 2.5.9tests
From 194b3c396c9fec1381e91e63886e00524345325b Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Mon, 14 Mar 2022 17:49:10 +0100
Subject: [PATCH 15/22] chore(deps): update dependency
com.google.cloud:libraries-bom to v25 (#1059)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* chore(deps): update dependency com.google.cloud:libraries-bom to v25
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: Owl Bot
---
README.md | 4 ++--
samples/native-image-sample/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 8f60b60bb..664dc9b7b 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
com.google.cloudlibraries-bom
- 24.4.0
+ 25.0.0pomimport
@@ -51,7 +51,7 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies
```Groovy
-implementation platform('com.google.cloud:libraries-bom:24.4.0')
+implementation platform('com.google.cloud:libraries-bom:25.0.0')
implementation 'com.google.cloud:google-cloud-pubsub'
```
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 9e5929d77..9fae435dd 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -30,7 +30,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
com.google.cloudlibraries-bom
- 24.3.0
+ 25.0.0pomimport
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 1841793e5..303ec3d8a 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -45,7 +45,7 @@
com.google.cloudlibraries-bom
- 24.4.0
+ 25.0.0pomimport
From 3c71272fcdb28b9de945b2c8d8391960bffe817c Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Mon, 14 Mar 2022 17:49:26 +0100
Subject: [PATCH 16/22] build(deps): update dependency
org.apache.maven.plugins:maven-compiler-plugin to v3.10.1 (#1056)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* build(deps): update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.10.1
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: Owl Bot
---
google-cloud-pubsub/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml
index b8f6268bf..b641a6856 100644
--- a/google-cloud-pubsub/pom.xml
+++ b/google-cloud-pubsub/pom.xml
@@ -164,7 +164,7 @@
maven-compiler-plugin
- 3.10.0
+ 3.10.11.81.8
From 0b7d19fe39326c36152267e4d2a13a2b51530ac2 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Mon, 14 Mar 2022 18:15:11 +0100
Subject: [PATCH 17/22] deps: update dependency
com.google.cloud:google-cloud-core to v2.5.10 (#1057)
---
samples/install-without-bom/pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 8724d7e43..6203e22f9 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -80,7 +80,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.9
+ 2.5.10tests
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index c8def65fd..d34849c6e 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -79,7 +79,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.9
+ 2.5.10tests
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 303ec3d8a..1bbe63219 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -90,7 +90,7 @@
com.google.cloudgoogle-cloud-core
- 2.5.9
+ 2.5.10tests
From fe583cb866d7586edda71f7e5901392f6b0da4ea Mon Sep 17 00:00:00 2001
From: Mike Micatka <31972785+mmicatka@users.noreply.github.com>
Date: Tue, 15 Mar 2022 12:43:59 -0400
Subject: [PATCH 18/22] samples: add exactly once subscribe sample (#1029)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* created exactly once subscription example
* updated example
* updated sample
* removed tag
* cleanup + add tests
* checkstyle
* formatting
* updated some comments, added try-catch
* added switch statement to handle ackResponses + minDuration option
* added (redundant) default for enum switch statement
* copy-paste issue
* changed wording in sample
* updated wording
* code review changes
* update comments
* Update samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java
Co-authored-by: Tianzi Cai
* update comments
* add a test subscription with exactly once delivery
* add imports
* remove topicId
* updated samples tests
* removed extra space
* handling null message
* combined a try-catch
* added new topic in sample test for exactly once delivery
* added cleanup
* fixed formatting
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: Tianzi Cai
Co-authored-by: Owl Bot
---
README.md | 1 +
...xactlyOnceConsumerWithResponseExample.java | 110 ++++++++++++++++++
.../src/test/java/pubsub/SubscriberIT.java | 40 ++++++-
3 files changed, 149 insertions(+), 2 deletions(-)
create mode 100644 samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java
diff --git a/README.md b/README.md
index 664dc9b7b..807cbdc75 100644
--- a/README.md
+++ b/README.md
@@ -285,6 +285,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m
| Subscribe With Concurrency Control Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithConcurrencyControlExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithConcurrencyControlExample.java) |
| Subscribe With Custom Attributes Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithCustomAttributesExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithCustomAttributesExample.java) |
| Subscribe With Error Listener Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithErrorListenerExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithErrorListenerExample.java) |
+| Subscribe With Exactly Once Consumer With Response Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java) |
| Subscribe With Flow Control Settings Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithFlowControlSettingsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithFlowControlSettingsExample.java) |
| Subscribe With Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java) |
| Test Subscription Permissions Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/TestSubscriptionPermissionsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/TestSubscriptionPermissionsExample.java) |
diff --git a/samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java b/samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java
new file mode 100644
index 000000000..8c85364c0
--- /dev/null
+++ b/samples/snippets/src/main/java/pubsub/SubscribeWithExactlyOnceConsumerWithResponseExample.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pubsub;
+
+// [START pubsub_subscriber_exactly_once]
+
+import com.google.cloud.pubsub.v1.AckReplyConsumerWithResponse;
+import com.google.cloud.pubsub.v1.AckResponse;
+import com.google.cloud.pubsub.v1.MessageReceiverWithAckResponse;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.PubsubMessage;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class SubscribeWithExactlyOnceConsumerWithResponseExample {
+ public static void main(String... args) throws Exception {
+ // TODO(developer): Replace these variables before running the sample.
+ String projectId = "your-project-id";
+ String subscriptionId = "your-subscription-id";
+
+ subscribeWithExactlyOnceConsumerWithResponseExample(projectId, subscriptionId);
+ }
+
+ public static void subscribeWithExactlyOnceConsumerWithResponseExample(
+ String projectId, String subscriptionId) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscriptionId);
+
+ // Instantiate an asynchronous message receiver using `AckReplyConsumerWithResponse`
+ // instead of `AckReplyConsumer` to get a future that tracks the result of the ack call.
+ // When exactly once delivery is enabled on the subscription, the message is guaranteed
+ // to not be delivered again if the ack future succeeds.
+ MessageReceiverWithAckResponse receiverWithResponse =
+ (PubsubMessage message, AckReplyConsumerWithResponse consumerWithResponse) -> {
+ try {
+ // Handle incoming message, then ack the message, and receive an ack response.
+ System.out.println("Message received: " + message.getData().toStringUtf8());
+ Future ackResponseFuture = consumerWithResponse.ack();
+
+ // Retrieve the completed future for the ack response from the server.
+ AckResponse ackResponse = ackResponseFuture.get();
+
+ switch (ackResponse) {
+ case SUCCESSFUL:
+ // Success code means that this MessageID will not be delivered again.
+ System.out.println("Message successfully acked: " + message.getMessageId());
+ break;
+ case INVALID:
+ System.out.println(
+ "Message failed to ack with a response of Invalid. Id: "
+ + message.getMessageId());
+ break;
+ case PERMISSION_DENIED:
+ System.out.println(
+ "Message failed to ack with a response of Permission Denied. Id: "
+ + message.getMessageId());
+ break;
+ case FAILED_PRECONDITION:
+ System.out.println(
+ "Message failed to ack with a response of Failed Precondition. Id: "
+ + message.getMessageId());
+ break;
+ case OTHER:
+ System.out.println(
+ "Message failed to ack with a response of Other. Id: "
+ + message.getMessageId());
+ break;
+ default:
+ break;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ System.out.println(
+ "MessageId: " + message.getMessageId() + " failed when retrieving future");
+ } catch (Throwable t) {
+ System.out.println("Throwable caught" + t.getMessage());
+ }
+ };
+
+ Subscriber subscriber = null;
+ try {
+ subscriber = Subscriber.newBuilder(subscriptionName, receiverWithResponse).build();
+ // Start the subscriber.
+ subscriber.startAsync().awaitRunning();
+ System.out.printf("Listening for messages on %s:\n", subscriptionName.toString());
+ // Allow the subscriber to run for 30s unless an unrecoverable error occurs.
+ subscriber.awaitTerminated(30, TimeUnit.SECONDS);
+ } catch (TimeoutException timeoutException) {
+ // Shut down the subscriber after 30s. Stop receiving messages.
+ subscriber.stopAsync();
+ }
+ }
+}
+// [END pubsub_subscriber_exactly_once]
diff --git a/samples/snippets/src/test/java/pubsub/SubscriberIT.java b/samples/snippets/src/test/java/pubsub/SubscriberIT.java
index d0946202c..ee4e03068 100644
--- a/samples/snippets/src/test/java/pubsub/SubscriberIT.java
+++ b/samples/snippets/src/test/java/pubsub/SubscriberIT.java
@@ -52,10 +52,16 @@ public class SubscriberIT {
private static final String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String _suffix = UUID.randomUUID().toString();
private static final String topicId = "subscriber-test-topic-" + _suffix;
+ private static final String topicIdEod = "subscriber-test-topic-eod" + _suffix;
private static final String subscriptionId = "subscriber-test-subscription-" + _suffix;
+ // For a subscription with exactly once delivery enabled.
+ private static final String subscriptionEodId = "subscriber-test-subscription-eod" + _suffix;
private static final TopicName topicName = TopicName.of(projectId, topicId);
+ private static final TopicName topicNameEod = TopicName.of(projectId, topicIdEod);
private static final ProjectSubscriptionName subscriptionName =
ProjectSubscriptionName.of(projectId, subscriptionId);
+ private static final ProjectSubscriptionName subscriptionEodName =
+ ProjectSubscriptionName.of(projectId, subscriptionEodId);
private static void requireEnvVar(String varName) {
assertNotNull(
@@ -63,8 +69,13 @@ private static void requireEnvVar(String varName) {
System.getenv(varName));
}
+ private static List publishSomeMessages(Integer numOfMessages) throws Exception {
+ return publishSomeMessages(numOfMessages, topicId);
+ }
+
// Helper function to publish some messages.
- private static void publishSomeMessages(Integer numOfMessages) throws Exception {
+ private static List publishSomeMessages(Integer numOfMessages, String topicId)
+ throws Exception {
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
Publisher publisher = Publisher.newBuilder(topicName).build();
List> messageIdFutures = new ArrayList<>();
@@ -78,7 +89,7 @@ private static void publishSomeMessages(Integer numOfMessages) throws Exception
ApiFuture messageIdFuture = publisher.publish(pubsubMessage);
messageIdFutures.add(messageIdFuture);
}
- ApiFutures.allAsList(messageIdFutures).get();
+ return ApiFutures.allAsList(messageIdFutures).get();
}
// Helper function to retry synchronous pull attempts until all outstanding messages are received.
@@ -123,6 +134,9 @@ public void setUp() throws Exception {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic topic = Topic.newBuilder().setName(topicName.toString()).build();
topicAdminClient.createTopic(topic);
+
+ Topic topicEod = Topic.newBuilder().setName(topicNameEod.toString()).build();
+ topicAdminClient.createTopic(topicEod);
}
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
@@ -132,6 +146,15 @@ public void setUp() throws Exception {
.setTopic(topicName.toString())
.build();
subscriptionAdminClient.createSubscription(subscription);
+
+ Subscription subscriptionEod =
+ Subscription.newBuilder()
+ .setName(subscriptionEodName.toString())
+ .setTopic(topicNameEod.toString())
+ // Enable exactly once delivery in the subscription.
+ .setEnableExactlyOnceDelivery(true)
+ .build();
+ subscriptionAdminClient.createSubscription(subscriptionEod);
}
}
@@ -139,10 +162,12 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
subscriptionAdminClient.deleteSubscription(subscriptionName.toString());
+ subscriptionAdminClient.deleteSubscription(subscriptionEodName.toString());
}
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topicName.toString());
+ topicAdminClient.deleteTopic(topicNameEod.toString());
}
System.setOut(null);
@@ -204,4 +229,15 @@ public void testSubscriber() throws Exception {
SubscribeSyncWithLeaseExample.subscribeSyncWithLeaseExample(
projectId, subscriptionId, 10));
}
+
+ @Test
+ public void testSubscriberExactlyOnceDelivery() throws Exception {
+ List messageIds = publishSomeMessages(10, topicIdEod);
+ bout.reset();
+ SubscribeWithExactlyOnceConsumerWithResponseExample
+ .subscribeWithExactlyOnceConsumerWithResponseExample(projectId, subscriptionEodId);
+ for (String messageId : messageIds) {
+ assertThat(bout.toString()).contains("Message successfully acked: " + messageId);
+ }
+ }
}
From af2b3640eb22e8e78f5beea07a73e2b3127cce71 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Tue, 15 Mar 2022 18:50:55 +0100
Subject: [PATCH 19/22] deps: update dependency
com.google.cloud:native-image-support to v0.12.10 (#1058)
---
samples/native-image-sample/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 9fae435dd..1a562dcd1 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -107,7 +107,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
com.google.cloudnative-image-support
- 0.12.9
+ 0.12.10org.junit.vintage
From 2d5c0109fe797698749d2c198cbb5a8a1a9d11dc Mon Sep 17 00:00:00 2001
From: Mridula <66699525+mpeddada1@users.noreply.github.com>
Date: Fri, 18 Mar 2022 14:48:04 -0400
Subject: [PATCH 20/22] docs(sample): use Java 8 for native image sample
(#1060)
---
samples/native-image-sample/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index 1a562dcd1..aa2384f8d 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -20,8 +20,8 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">