From affaa8c1b94b589198e229ccc99172920d234255 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 23 Feb 2021 00:50:04 +0000 Subject: [PATCH 01/11] chore(master): release 1.111.2-SNAPSHOT (#517) :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 024e47575..00ec2d18a 100644 --- a/google-cloud-pubsub-bom/pom.xml +++ b/google-cloud-pubsub-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-pubsub-bom - 1.111.1 + 1.111.2-SNAPSHOT pom com.google.cloud @@ -64,17 +64,17 @@ com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT com.google.cloud google-cloud-pubsub - 1.111.1 + 1.111.2-SNAPSHOT diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index 728e677de..2ce378b7a 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-pubsub - 1.111.1 + 1.111.2-SNAPSHOT jar Google Cloud Pub/Sub https://github.com/googleapis/java-pubsub @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pubsub-parent - 1.111.1 + 1.111.2-SNAPSHOT google-cloud-pubsub diff --git a/grpc-google-cloud-pubsub-v1/pom.xml b/grpc-google-cloud-pubsub-v1/pom.xml index c8416b418..38634d6e4 100644 --- a/grpc-google-cloud-pubsub-v1/pom.xml +++ b/grpc-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT grpc-google-cloud-pubsub-v1 GRPC library for grpc-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.111.1 + 1.111.2-SNAPSHOT diff --git a/pom.xml b/pom.xml index 92e596e3e..48e66578e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-pubsub-parent pom - 1.111.1 + 1.111.2-SNAPSHOT Google Cloud Pub/Sub Parent https://github.com/googleapis/java-pubsub @@ -78,17 +78,17 @@ com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT com.google.cloud google-cloud-pubsub - 1.111.1 + 1.111.2-SNAPSHOT diff --git a/proto-google-cloud-pubsub-v1/pom.xml b/proto-google-cloud-pubsub-v1/pom.xml index 7a731c234..a735fc6a4 100644 --- a/proto-google-cloud-pubsub-v1/pom.xml +++ b/proto-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.1 + 1.93.2-SNAPSHOT proto-google-cloud-pubsub-v1 PROTO library for proto-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.111.1 + 1.111.2-SNAPSHOT diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 019092c97..1e3849dae 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -43,7 +43,7 @@ com.google.cloud google-cloud-pubsub - 1.111.1 + 1.111.2-SNAPSHOT diff --git a/versions.txt b/versions.txt index f95206b7f..13a571ecb 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -proto-google-cloud-pubsub-v1:1.93.1:1.93.1 -grpc-google-cloud-pubsub-v1:1.93.1:1.93.1 -google-cloud-pubsub:1.111.1:1.111.1 \ No newline at end of file +proto-google-cloud-pubsub-v1:1.93.1:1.93.2-SNAPSHOT +grpc-google-cloud-pubsub-v1:1.93.1:1.93.2-SNAPSHOT +google-cloud-pubsub:1.111.1:1.111.2-SNAPSHOT \ No newline at end of file From b0e3e765e4d9a0e93eee0c7224563045a36aaff8 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Tue, 23 Feb 2021 16:32:39 -0800 Subject: [PATCH 02/11] test(samples): remove duplicated testing (#519) --- .kokoro/continuous/java11-samples.cfg | 30 --------------- .kokoro/continuous/jave8-samples.cfg | 30 --------------- .kokoro/nightly/java11-samples.cfg | 30 --------------- .kokoro/nightly/java8-samples.cfg | 30 --------------- .kokoro/presubmit/java11-samples.cfg | 30 --------------- .kokoro/presubmit/java8-samples.cfg | 30 --------------- .kokoro/run_samples_tests.sh | 55 --------------------------- 7 files changed, 235 deletions(-) delete mode 100644 .kokoro/continuous/java11-samples.cfg delete mode 100644 .kokoro/continuous/jave8-samples.cfg delete mode 100644 .kokoro/nightly/java11-samples.cfg delete mode 100644 .kokoro/nightly/java8-samples.cfg delete mode 100644 .kokoro/presubmit/java11-samples.cfg delete mode 100644 .kokoro/presubmit/java8-samples.cfg delete mode 100755 .kokoro/run_samples_tests.sh diff --git a/.kokoro/continuous/java11-samples.cfg b/.kokoro/continuous/java11-samples.cfg deleted file mode 100644 index b43371933..000000000 --- a/.kokoro/continuous/java11-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java11" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/continuous/jave8-samples.cfg b/.kokoro/continuous/jave8-samples.cfg deleted file mode 100644 index 3506e1271..000000000 --- a/.kokoro/continuous/jave8-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java8" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/nightly/java11-samples.cfg b/.kokoro/nightly/java11-samples.cfg deleted file mode 100644 index b43371933..000000000 --- a/.kokoro/nightly/java11-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java11" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/nightly/java8-samples.cfg b/.kokoro/nightly/java8-samples.cfg deleted file mode 100644 index 3506e1271..000000000 --- a/.kokoro/nightly/java8-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java8" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/presubmit/java11-samples.cfg b/.kokoro/presubmit/java11-samples.cfg deleted file mode 100644 index b43371933..000000000 --- a/.kokoro/presubmit/java11-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java11" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/presubmit/java8-samples.cfg b/.kokoro/presubmit/java8-samples.cfg deleted file mode 100644 index 3506e1271..000000000 --- a/.kokoro/presubmit/java8-samples.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 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. - -# Format: //devtools/kokoro/config/proto/build.proto - -# Download secrets from Cloud Storage. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/java-docs-samples" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java8" -} - -# Tell trampoline which tests to run. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/java-pubsub/.kokoro/run_samples_tests.sh" -} \ No newline at end of file diff --git a/.kokoro/run_samples_tests.sh b/.kokoro/run_samples_tests.sh deleted file mode 100755 index 5f1e8a27f..000000000 --- a/.kokoro/run_samples_tests.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# Copyright 2020 Google Inc. -# -# 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. - -# `-e` enables the script to automatically fail when a command fails -# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero -set -eo pipefail - -echo "********** MAVEN INFO ***********" -mvn -v - -# Get the directory of the build script -scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) -## cd to the parent directory, i.e. the root of the git repo -cd ${scriptDir}/.. - -# include common functions -source ${scriptDir}/common.sh - -# Setup required env variables -source ${KOKORO_GFILE_DIR}/pubsub_secrets.txt -echo "********** Successfully Set All Environment Variables **********" - -# Attempt to install 3 times with exponential backoff (starting with 10 seconds) -retry_with_backoff 3 10 \ - mvn install -B -V \ - -DskipTests=true \ - -Dclirr.skip=true \ - -Denforcer.skip=true \ - -Dmaven.javadoc.skip=true \ - -Dgcloud.download.skip=true \ - -T 1C - -# Activate service account -gcloud auth activate-service-account \ - --key-file="$GOOGLE_APPLICATION_CREDENTIALS" \ - --project="$GOOGLE_CLOUD_PROJECT" - -# Move into the samples directory -cd samples/ - -echo -e "\n******************** RUNNING SAMPLE TESTS ********************" - -mvn --fail-at-end clean verify From 02783e4f52295c202ae735e41c2ef7f84c8462fb Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 24 Feb 2021 01:35:10 +0100 Subject: [PATCH 03/11] chore(deps): update dependency com.google.cloud:google-cloud-pubsub to v1.111.1 (#518) --- samples/install-without-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 64e1c6957..263a04b10 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-pubsub - 1.111.0 + 1.111.1 From 87f081f5ccadc01ea4d3c5fe188d5e1b6ba32fbe Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Feb 2021 16:48:04 -0800 Subject: [PATCH 04/11] chore: regenerate README (#520) This PR was generated using Autosynth. :rainbow:
Log from Synthtool ``` 2021-02-24 00:35:02,556 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-02-24 00:35:04,292 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ```
Full log will be available here: https://source.cloud.google.com/results/invocations/1554be22-6843-457b-a401-23d0327126bb/targets - [ ] To automatically regenerate this PR, check this box. --- .github/readme/synth.metadata/synth.metadata | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata index 548b73a84..b95b256dd 100644 --- a/.github/readme/synth.metadata/synth.metadata +++ b/.github/readme/synth.metadata/synth.metadata @@ -4,14 +4,14 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-pubsub.git", - "sha": "6e1967add44df377c0b0af82bd5ba35201308feb" + "sha": "b0e3e765e4d9a0e93eee0c7224563045a36aaff8" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "4679e7e415221f03ff2a71e3ffad75b9ec41d87e" + "sha": "79ab0b44a2cc7d803d07c107f9faf07729fc4012" } } ] diff --git a/README.md b/README.md index 131a791f3..1debc71a6 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,12 @@ compile 'com.google.cloud:google-cloud-pubsub' ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-pubsub:1.111.0' +compile 'com.google.cloud:google-cloud-pubsub:1.111.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.111.0" +libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.111.1" ``` ## Authentication From 5ca8d252c239d89575b8abb8631baf381e61332d Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Feb 2021 17:02:02 -0800 Subject: [PATCH 05/11] chore: regenerate README (#521) This PR was generated using Autosynth. :rainbow:
Log from Synthtool ``` 2021-02-24 00:50:21,186 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-02-24 00:50:22,742 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ```
Full log will be available here: https://source.cloud.google.com/results/invocations/045ffc6d-00bb-422b-9e3d-6ab274287a3c/targets - [ ] To automatically regenerate this PR, check this box. --- .github/readme/synth.metadata/synth.metadata | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata index b95b256dd..27d1905c9 100644 --- a/.github/readme/synth.metadata/synth.metadata +++ b/.github/readme/synth.metadata/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-pubsub.git", - "sha": "b0e3e765e4d9a0e93eee0c7224563045a36aaff8" + "sha": "87f081f5ccadc01ea4d3c5fe188d5e1b6ba32fbe" } }, { diff --git a/README.md b/README.md index 1debc71a6..d520c5d4c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ If you are using Maven without BOM, add this to your dependencies: com.google.cloud google-cloud-pubsub - 1.111.0 + 1.111.1 ``` From a71e898ebe768f07966a13779c890818e9dad694 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 24 Feb 2021 09:45:23 -0800 Subject: [PATCH 06/11] samples: add schema samples (#509) * samples: add three schema samples * address kamal's comments * add avro-tools generated class State * add 4 more examples * remove validate schema sample * place common code outside case switch body * add subscribe with avro schema example * move generated class under utitlies * add proto file and generated class * add comment about topic encoding * apply kamal's suggestions * add publish and subscribe proto messages examples * update comment * add resources to install-without-bom and snapshots * Fix schema integration test and avro example * add resources to install-without-bom and snapshots * fix file path * lint * lint: add checkstyle-suppressions.xml * change checkstyle working directory * address kamal's comment about try catch * address kamal's comment about method naming * update assert * address kolea2's comments Co-authored-by: Kamal Aboul-Hosn --- .github/sync-repo-settings.yaml | 2 +- .github/workflows/samples.yaml | 2 +- samples/checkstyle-suppressions.xml | 34 + samples/install-without-bom/pom.xml | 43 + samples/pom.xml | 13 + samples/snapshot/pom.xml | 45 +- samples/snippets/pom.xml | 17 + .../java/pubsub/CreateAvroSchemaExample.java | 68 ++ .../java/pubsub/CreateProtoSchemaExample.java | 68 ++ .../main/java/pubsub/CreateTopicExample.java | 1 - .../pubsub/CreateTopicWithSchemaExample.java | 67 ++ .../main/java/pubsub/DeleteSchemaExample.java | 50 ++ .../pubsub/DetachSubscriptionExample.java | 2 +- .../main/java/pubsub/GetSchemaExample.java | 51 ++ .../main/java/pubsub/ListSchemasExample.java | 44 + .../pubsub/PublishAvroRecordsExample.java | 109 +++ .../PublishProtobufMessagesExample.java | 97 +++ .../pubsub/RemoveDeadLetterPolicyExample.java | 5 +- .../SubscribeWithAvroSchemaExample.java | 109 +++ .../SubscribeWithProtoSchemaExample.java | 94 +++ .../src/main/java/utilities/State.java | 441 ++++++++++ .../src/main/java/utilities/StateProto.java | 781 ++++++++++++++++++ .../src/main/resources/us-states.avsc | 18 + .../src/main/resources/us-states.proto | 9 + .../src/test/java/pubsub/AdminIT.java | 1 - .../src/test/java/pubsub/SchemaIT.java | 191 +++++ .../src/test/resources/us-states.avsc | 18 + .../src/test/resources/us-states.proto | 9 + 28 files changed, 2379 insertions(+), 10 deletions(-) create mode 100644 samples/checkstyle-suppressions.xml create mode 100644 samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/GetSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/ListSchemasExample.java create mode 100644 samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java create mode 100644 samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java create mode 100644 samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java create mode 100644 samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java create mode 100644 samples/snippets/src/main/java/utilities/State.java create mode 100644 samples/snippets/src/main/java/utilities/StateProto.java create mode 100644 samples/snippets/src/main/resources/us-states.avsc create mode 100644 samples/snippets/src/main/resources/us-states.proto create mode 100644 samples/snippets/src/test/java/pubsub/SchemaIT.java create mode 100644 samples/snippets/src/test/resources/us-states.avsc create mode 100644 samples/snippets/src/test/resources/us-states.proto diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 6bddd18ea..b36eb7dee 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -46,4 +46,4 @@ permissionRules: - team: yoshi-java-admins permission: admin - team: yoshi-java - permission: push \ No newline at end of file + permission: push diff --git a/.github/workflows/samples.yaml b/.github/workflows/samples.yaml index c46230a78..016279315 100644 --- a/.github/workflows/samples.yaml +++ b/.github/workflows/samples.yaml @@ -11,4 +11,4 @@ jobs: java-version: 8 - name: Run checkstyle run: mvn -P lint --quiet --batch-mode checkstyle:check - working-directory: samples/snippets + working-directory: samples diff --git a/samples/checkstyle-suppressions.xml b/samples/checkstyle-suppressions.xml new file mode 100644 index 000000000..c1ab01fe8 --- /dev/null +++ b/samples/checkstyle-suppressions.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 263a04b10..9df2bb003 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -48,6 +48,18 @@
+ + org.apache.avro + avro + 1.10.1 + compile + + + org.xerial.snappy + snappy-java + 1.1.8.4 + + junit junit @@ -60,6 +72,11 @@ 1.1.2 test + + com.google.protobuf + protobuf-java-util + 3.14.0 +
@@ -81,6 +98,19 @@ + + add-snippets-resources + + add-resource + + + + + ../snippets/src/main/resources + + + + add-snippets-tests @@ -92,6 +122,19 @@ + + add-snippets-tests-resource + + add-test-resource + + + + + ../snippets/src/test/resources> + + + + diff --git a/samples/pom.xml b/samples/pom.xml index aee27735f..4e20813d1 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -68,4 +68,17 @@ + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.2 + + checkstyle-suppressions.xml + + + + diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 1e3849dae..8268db095 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -47,6 +47,23 @@
+ + org.apache.avro + avro + 1.10.1 + compile + + + org.xerial.snappy + snappy-java + 1.1.8.4 + + + com.google.protobuf + protobuf-java-util + 3.14.0 + + junit junit @@ -80,6 +97,19 @@ + + add-snippets-resources + + add-resource + + + + + ../snippets/src/main/resources + + + + add-snippets-tests @@ -91,8 +121,21 @@ + + add-snippets-tests-resource + + add-test-resource + + + + + ../snippets/src/test/resources> + + + + - \ No newline at end of file + diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index c6af90f82..a578bfadf 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -56,9 +56,26 @@ com.google.cloud google-cloud-pubsub + 1.111.0 + + org.apache.avro + avro + 1.10.1 + + + org.xerial.snappy + snappy-java + 1.1.8.4 + + + com.google.protobuf + protobuf-java-util + 3.14.0 + + junit junit diff --git a/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java b/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java new file mode 100644 index 000000000..7e340cd29 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021 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_create_avro_schema] + +import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.pubsub.v1.ProjectName; +import com.google.pubsub.v1.Schema; +import com.google.pubsub.v1.SchemaName; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class CreateAvroSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String schemaId = "your-schema-id"; + String avscFile = "path/to/an/avro/schema/file/(.avsc)/formatted/in/json"; + + createAvroSchemaExample(projectId, schemaId, avscFile); + } + + public static void createAvroSchemaExample(String projectId, String schemaId, String avscFile) + throws IOException { + + ProjectName projectName = ProjectName.of(projectId); + SchemaName schemaName = SchemaName.of(projectId, schemaId); + + // Read an Avro schema file formatted in JSON as a string. + String avscSource = new String(Files.readAllBytes(Paths.get(avscFile))); + + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + + Schema schema = + schemaServiceClient.createSchema( + projectName, + Schema.newBuilder() + .setName(schemaName.toString()) + .setType(com.google.pubsub.v1.Schema.Type.AVRO) + .setDefinition(avscSource) + .build(), + schemaId); + + System.out.println("Created a schema using an Avro schema:\n" + schema); + } catch (AlreadyExistsException e) { + System.out.println(schemaName + "already exists."); + } + } +} +// [END pubsub_create_avro_schema] diff --git a/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java b/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java new file mode 100644 index 000000000..a8efdeb8e --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021 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_create_proto_schema] + +import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.pubsub.v1.ProjectName; +import com.google.pubsub.v1.Schema; +import com.google.pubsub.v1.SchemaName; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class CreateProtoSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String schemaId = "your-schema-id"; + String protoFile = "path/to/a/proto/file/(.proto)/formatted/in/protocol/buffers"; + + createProtoSchemaExample(projectId, schemaId, protoFile); + } + + public static void createProtoSchemaExample(String projectId, String schemaId, String protoFile) + throws IOException { + + ProjectName projectName = ProjectName.of(projectId); + SchemaName schemaName = SchemaName.of(projectId, schemaId); + + // Read a proto file as a string. + String protoSource = new String(Files.readAllBytes(Paths.get(protoFile))); + + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + + Schema schema = + schemaServiceClient.createSchema( + projectName, + Schema.newBuilder() + .setName(schemaName.toString()) + .setType(Schema.Type.PROTOCOL_BUFFER) + .setDefinition(protoSource) + .build(), + schemaId); + + System.out.println("Created a schema using a protobuf schema:\n" + schema); + } catch (AlreadyExistsException e) { + System.out.println(schemaName + "already exists."); + } + } +} +// [END pubsub_create_proto_schema] diff --git a/samples/snippets/src/main/java/pubsub/CreateTopicExample.java b/samples/snippets/src/main/java/pubsub/CreateTopicExample.java index 3417be7c5..f002ec837 100644 --- a/samples/snippets/src/main/java/pubsub/CreateTopicExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateTopicExample.java @@ -43,4 +43,3 @@ public static void createTopicExample(String projectId, String topicId) throws I } // [END pubsub_create_topic] // [END pubsub_quickstart_create_topic] - diff --git a/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java b/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java new file mode 100644 index 000000000..2ce1a2b53 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.java @@ -0,0 +1,67 @@ +/* + * Copyright 2021 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_create_topic_with_schema] + +import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.pubsub.v1.Encoding; +import com.google.pubsub.v1.SchemaName; +import com.google.pubsub.v1.SchemaSettings; +import com.google.pubsub.v1.Topic; +import com.google.pubsub.v1.TopicName; +import java.io.IOException; + +public class CreateTopicWithSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String topicId = "your-topic-id"; + // Use an existing schema. + String schemaId = "your-schema-id"; + // Choose either BINARY or JSON message serialization in this topic. + Encoding encoding = Encoding.BINARY; + + createTopicWithSchemaExample(projectId, topicId, schemaId, encoding); + } + + public static void createTopicWithSchemaExample( + String projectId, String topicId, String schemaId, Encoding encoding) throws IOException { + TopicName topicName = TopicName.of(projectId, topicId); + SchemaName schemaName = SchemaName.of(projectId, schemaId); + + SchemaSettings schemaSettings = + SchemaSettings.newBuilder().setSchema(schemaName.toString()).setEncoding(encoding).build(); + + try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { + + Topic topic = + topicAdminClient.createTopic( + Topic.newBuilder() + .setName(topicName.toString()) + .setSchemaSettings(schemaSettings) + .build()); + + System.out.println("Created topic with schema: " + topic.getName()); + } catch (AlreadyExistsException e) { + System.out.println(schemaName + "already exists."); + } + } +} +// [END pubsub_create_topic_with_schema] diff --git a/samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java b/samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java new file mode 100644 index 000000000..2cd5fa522 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/DeleteSchemaExample.java @@ -0,0 +1,50 @@ +/* + * Copyright 2021 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_delete_schema] + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.pubsub.v1.SchemaName; +import java.io.IOException; + +public class DeleteSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String schemaId = "your-schema-id"; + + deleteSchemaExample(projectId, schemaId); + } + + public static void deleteSchemaExample(String projectId, String schemaId) throws IOException { + SchemaName schemaName = SchemaName.of(projectId, schemaId); + + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + + schemaServiceClient.deleteSchema(schemaName); + + System.out.println("Deleted a schema:" + schemaName); + + } catch (NotFoundException e) { + System.out.println(schemaName + "not found."); + } + } +} +// [END pubsub_delete_schema] diff --git a/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java index ac04c1c90..88ebb8e05 100644 --- a/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.java @@ -56,4 +56,4 @@ public static void detachSubscriptionExample(String projectId, String subscripti } } } -// [END pubsub_detach_subscription] \ No newline at end of file +// [END pubsub_detach_subscription] diff --git a/samples/snippets/src/main/java/pubsub/GetSchemaExample.java b/samples/snippets/src/main/java/pubsub/GetSchemaExample.java new file mode 100644 index 000000000..a3b72895a --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/GetSchemaExample.java @@ -0,0 +1,51 @@ +/* + * Copyright 2021 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_get_schema] + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.pubsub.v1.Schema; +import com.google.pubsub.v1.SchemaName; +import java.io.IOException; + +public class GetSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + String schemaId = "your-schema-id"; + + getSchemaExample(projectId, schemaId); + } + + public static void getSchemaExample(String projectId, String schemaId) throws IOException { + SchemaName schemaName = SchemaName.of(projectId, schemaId); + + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + + Schema schema = schemaServiceClient.getSchema(schemaName); + + System.out.println("Got a schema:\n" + schema); + + } catch (NotFoundException e) { + System.out.println(schemaName + "not found."); + } + } +} +// [END pubsub_get_schema] diff --git a/samples/snippets/src/main/java/pubsub/ListSchemasExample.java b/samples/snippets/src/main/java/pubsub/ListSchemasExample.java new file mode 100644 index 000000000..8447184ae --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/ListSchemasExample.java @@ -0,0 +1,44 @@ +/* + * Copyright 2021 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_list_schemas] +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.pubsub.v1.ProjectName; +import com.google.pubsub.v1.Schema; +import java.io.IOException; + +public class ListSchemasExample { + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + + listSchemasExample(projectId); + } + + public static void listSchemasExample(String projectId) throws IOException { + ProjectName projectName = ProjectName.of(projectId); + + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + for (Schema schema : schemaServiceClient.listSchemas(projectName).iterateAll()) { + System.out.println(schema); + } + System.out.println("Listed schemas."); + } + } +} +// [END pubsub_list_schemas] diff --git a/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java b/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java new file mode 100644 index 000000000..0bfed04e5 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java @@ -0,0 +1,109 @@ +/* + * Copyright 2021 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_publish_avro_records] + +import com.google.api.core.ApiFuture; +import com.google.cloud.pubsub.v1.Publisher; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.protobuf.ByteString; +import com.google.pubsub.v1.Encoding; +import com.google.pubsub.v1.PubsubMessage; +import com.google.pubsub.v1.TopicName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import org.apache.avro.io.Encoder; +import org.apache.avro.io.EncoderFactory; +import utilities.State; + +public class PublishAvroRecordsExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + // Use a topic created with an Avro schema. + String topicId = "your-topic-id"; + + publishAvroRecordsExample(projectId, topicId); + } + + public static void publishAvroRecordsExample(String projectId, String topicId) + throws IOException, ExecutionException, InterruptedException { + + Encoding encoding = null; + + TopicName topicName = TopicName.of(projectId, topicId); + + // Get the topic encoding type. + try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { + encoding = topicAdminClient.getTopic(topicName).getSchemaSettings().getEncoding(); + } + + // Create an object of an avro-tools-generated class. + State state = State.newBuilder().setName("Alaska").setPostAbbr("AK").build(); + + Publisher publisher = null; + + block: + try { + publisher = Publisher.newBuilder(topicName).build(); + + // Prepare to serialize the object to the output stream. + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + + Encoder encoder = null; + + // Prepare an appropriate encoder for publishing to the topic. + switch (encoding) { + case BINARY: + System.out.println("Preparing a BINARY encoder..."); + encoder = EncoderFactory.get().directBinaryEncoder(byteStream, /*reuse=*/ null); + break; + + case JSON: + System.out.println("Preparing a JSON encoder..."); + encoder = EncoderFactory.get().jsonEncoder(State.getClassSchema(), byteStream); + break; + + default: + break block; + } + + // Encode the object and write it to the output stream. + state.customEncode(encoder); + encoder.flush(); + + // Publish the encoded object as a Pub/Sub message. + ByteString data = ByteString.copyFrom(byteStream.toByteArray()); + PubsubMessage message = PubsubMessage.newBuilder().setData(data).build(); + System.out.println("Publishing message: " + message); + + ApiFuture future = publisher.publish(message); + System.out.println("Published message ID: " + future.get()); + + } finally { + if (publisher != null) { + publisher.shutdown(); + publisher.awaitTermination(1, TimeUnit.MINUTES); + } + } + } +} +// [END pubsub_publish_avro_records] diff --git a/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java b/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java new file mode 100644 index 000000000..c1cdba1d7 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java @@ -0,0 +1,97 @@ +/* + * Copyright 2021 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_publish_proto_messages] + +import com.google.api.core.ApiFuture; +import com.google.cloud.pubsub.v1.Publisher; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.util.JsonFormat; +import com.google.pubsub.v1.Encoding; +import com.google.pubsub.v1.PubsubMessage; +import com.google.pubsub.v1.TopicName; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import utilities.StateProto.State; + +public class PublishProtobufMessagesExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + // Use a topic created with a proto schema. + String topicId = "your-topic-id"; + + publishProtobufMessagesExample(projectId, topicId); + } + + public static void publishProtobufMessagesExample(String projectId, String topicId) + throws IOException, ExecutionException, InterruptedException { + + Encoding encoding = null; + + TopicName topicName = TopicName.of(projectId, topicId); + + // Get the topic encoding type. + try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { + encoding = topicAdminClient.getTopic(topicName).getSchemaSettings().getEncoding(); + } + + Publisher publisher = null; + + // Create an object of an avro-tools-generated class. + State state = State.newBuilder().setName("Alaska").setPostAbbr("AK").build(); + + block: + try { + publisher = Publisher.newBuilder(topicName).build(); + + PubsubMessage.Builder message = PubsubMessage.newBuilder(); + + // Prepare an appropriately formatted message based on topic encoding. + switch (encoding) { + case BINARY: + message.setData(state.toByteString()); + System.out.println("Publishing a BINARY-formatted message:\n" + message); + break; + + case JSON: + String jsonString = JsonFormat.printer().omittingInsignificantWhitespace().print(state); + message.setData(ByteString.copyFromUtf8(jsonString)); + System.out.println("Publishing a JSON-formatted message:\n" + message); + break; + + default: + break block; + } + + // Publish the message. + ApiFuture future = publisher.publish(message.build()); + System.out.println("Published message ID: " + future.get()); + + } finally { + if (publisher != null) { + publisher.shutdown(); + publisher.awaitTermination(1, TimeUnit.MINUTES); + } + } + } +} +// [END pubsub_publish_proto_messages] diff --git a/samples/snippets/src/main/java/pubsub/RemoveDeadLetterPolicyExample.java b/samples/snippets/src/main/java/pubsub/RemoveDeadLetterPolicyExample.java index 04718d419..529850574 100644 --- a/samples/snippets/src/main/java/pubsub/RemoveDeadLetterPolicyExample.java +++ b/samples/snippets/src/main/java/pubsub/RemoveDeadLetterPolicyExample.java @@ -56,10 +56,7 @@ public static void removeDeadLetterPolicyExample( .build(); // Construct a field mask to indicate which field to update in the subscription. - FieldMask updateMask = - FieldMask.newBuilder() - .addPaths("dead_letter_policy") - .build(); + FieldMask updateMask = FieldMask.newBuilder().addPaths("dead_letter_policy").build(); UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder() diff --git a/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java b/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java new file mode 100644 index 000000000..65b1937b8 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.java @@ -0,0 +1,109 @@ +/* + * Copyright 2021 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_subscribe_avro_records] + +import com.google.cloud.pubsub.v1.AckReplyConsumer; +import com.google.cloud.pubsub.v1.MessageReceiver; +import com.google.cloud.pubsub.v1.Subscriber; +import com.google.protobuf.ByteString; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.PubsubMessage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.avro.io.Decoder; +import org.apache.avro.io.DecoderFactory; +import org.apache.avro.specific.SpecificDatumReader; +import utilities.State; + +public class SubscribeWithAvroSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + // Use an existing subscription. + String subscriptionId = "your-subscription-id"; + + subscribeWithAvroSchemaExample(projectId, subscriptionId); + } + + public static void subscribeWithAvroSchemaExample(String projectId, String subscriptionId) { + + ProjectSubscriptionName subscriptionName = + ProjectSubscriptionName.of(projectId, subscriptionId); + + // Prepare a reader for the encoded Avro records. + SpecificDatumReader reader = new SpecificDatumReader<>(State.getClassSchema()); + + // Instantiate an asynchronous message receiver. + MessageReceiver receiver = + (PubsubMessage message, AckReplyConsumer consumer) -> { + ByteString data = message.getData(); + + // Get the schema encoding type. + String encoding = message.getAttributesMap().get("googclient_schemaencoding"); + + // Send the message data to a byte[] input stream. + InputStream inputStream = new ByteArrayInputStream(data.toByteArray()); + + Decoder decoder = null; + + // Prepare an appropriate decoder for the message data in the input stream + // based on the schema encoding type. + block: + try { + switch (encoding) { + case "BINARY": + decoder = DecoderFactory.get().directBinaryDecoder(inputStream, /*reuse=*/ null); + System.out.println("Receiving a binary-encoded message:"); + break; + case "JSON": + decoder = DecoderFactory.get().jsonDecoder(State.getClassSchema(), inputStream); + System.out.println("Receiving a JSON-encoded message:"); + break; + default: + break block; + } + + // Obtain an object of the generated Avro class using the decoder. + State state = reader.read(null, decoder); + System.out.println(state.getName() + " is abbreviated as " + state.getPostAbbr()); + + } catch (IOException e) { + System.err.println(e); + } + + // Ack the message. + consumer.ack(); + }; + + Subscriber subscriber = null; + try { + subscriber = Subscriber.newBuilder(subscriptionName, receiver).build(); + subscriber.startAsync().awaitRunning(); + System.out.printf("Listening for messages on %s:\n", subscriptionName.toString()); + subscriber.awaitTerminated(30, TimeUnit.SECONDS); + } catch (TimeoutException timeoutException) { + subscriber.stopAsync(); + } + } +} +// [END pubsub_subscribe_avro_records] diff --git a/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java b/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java new file mode 100644 index 000000000..65ff2b39d --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/SubscribeWithProtoSchemaExample.java @@ -0,0 +1,94 @@ +/* + * Copyright 2021 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_subscribe_proto_messages] + +import com.google.cloud.pubsub.v1.AckReplyConsumer; +import com.google.cloud.pubsub.v1.MessageReceiver; +import com.google.cloud.pubsub.v1.Subscriber; +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.util.JsonFormat; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.PubsubMessage; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import utilities.StateProto.State; + +public class SubscribeWithProtoSchemaExample { + + public static void main(String... args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "your-project-id"; + // Use an existing subscription. + String subscriptionId = "your-subscription-id"; + + subscribeWithProtoSchemaExample(projectId, subscriptionId); + } + + public static void subscribeWithProtoSchemaExample(String projectId, String subscriptionId) { + + ProjectSubscriptionName subscriptionName = + ProjectSubscriptionName.of(projectId, subscriptionId); + + MessageReceiver receiver = + (PubsubMessage message, AckReplyConsumer consumer) -> { + ByteString data = message.getData(); + + // Get the schema encoding type. + String encoding = message.getAttributesMap().get("googclient_schemaencoding"); + + block: + try { + switch (encoding) { + case "BINARY": + // Obtain an object of the generated proto class. + State state = State.parseFrom(data); + System.out.println("Received a BINARY-formatted message: " + state); + break; + + case "JSON": + State.Builder stateBuilder = State.newBuilder(); + JsonFormat.parser().merge(data.toStringUtf8(), stateBuilder); + System.out.println("Received a JSON-formatted message:" + stateBuilder.build()); + break; + + default: + break block; + } + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + } + + consumer.ack(); + System.out.println("Ack'ed the message"); + }; + + // Create subscriber client. + Subscriber subscriber = Subscriber.newBuilder(subscriptionName, receiver).build(); + + try { + subscriber.startAsync().awaitRunning(); + System.out.printf("Listening for messages on %s:\n", subscriptionName); + subscriber.awaitTerminated(30, TimeUnit.SECONDS); + } catch (TimeoutException timeoutException) { + subscriber.stopAsync(); + } + } +} +// [END pubsub_subscribe_proto_messages] diff --git a/samples/snippets/src/main/java/utilities/State.java b/samples/snippets/src/main/java/utilities/State.java new file mode 100644 index 000000000..a3d837e85 --- /dev/null +++ b/samples/snippets/src/main/java/utilities/State.java @@ -0,0 +1,441 @@ +/* + * Copyright 2021 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. + */ + +/** + * Autogenerated by Avro + * + *

DO NOT EDIT DIRECTLY + */ +package utilities; + +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.SchemaStore; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; + +/** A list of states in the United States of America. */ +@org.apache.avro.specific.AvroGenerated +public class State extends org.apache.avro.specific.SpecificRecordBase + implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = -6098929419967278282L; + public static final org.apache.avro.Schema SCHEMA$ = + new org.apache.avro.Schema.Parser() + .parse( + "{\"type\":\"record\",\"name\":\"State\",\"namespace\":\"utilities\",\"doc\":\"A list of states in the United States of America.\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"The common name of the state.\"},{\"name\":\"post_abbr\",\"type\":\"string\",\"doc\":\"The postal code abbreviation of the state.\"}]}"); + + public static org.apache.avro.Schema getClassSchema() { + return SCHEMA$; + } + + private static SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link + * SchemaStore}. + * + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this State to a ByteBuffer. + * + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a State from a ByteBuffer. + * + * @param b a byte buffer holding serialized data for an instance of this class + * @return a State instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of + * this class + */ + public static State fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + /** The common name of the state. */ + private java.lang.CharSequence name; + /** The postal code abbreviation of the state. */ + private java.lang.CharSequence post_abbr; + + /** + * Default constructor. Note that this does not initialize fields to their default values from the + * schema. If that is desired then one should use newBuilder(). + */ + public State() {} + + /** + * All-args constructor. + * + * @param name The common name of the state. + * @param post_abbr The postal code abbreviation of the state. + */ + public State(java.lang.CharSequence name, java.lang.CharSequence post_abbr) { + this.name = name; + this.post_abbr = post_abbr; + } + + public org.apache.avro.specific.SpecificData getSpecificData() { + return MODEL$; + } + + public org.apache.avro.Schema getSchema() { + return SCHEMA$; + } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: + return name; + case 1: + return post_abbr; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value = "unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: + name = (java.lang.CharSequence) value$; + break; + case 1: + post_abbr = (java.lang.CharSequence) value$; + break; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + /** + * Gets the value of the 'name' field. + * + * @return The common name of the state. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. The common name of the state. + * + * @param value the value to set. + */ + public void setName(java.lang.CharSequence value) { + this.name = value; + } + + /** + * Gets the value of the 'post_abbr' field. + * + * @return The postal code abbreviation of the state. + */ + public java.lang.CharSequence getPostAbbr() { + return post_abbr; + } + + /** + * Sets the value of the 'post_abbr' field. The postal code abbreviation of the state. + * + * @param value the value to set. + */ + public void setPostAbbr(java.lang.CharSequence value) { + this.post_abbr = value; + } + + /** + * Creates a new State RecordBuilder. + * + * @return A new State RecordBuilder + */ + public static utilities.State.Builder newBuilder() { + return new utilities.State.Builder(); + } + + /** + * Creates a new State RecordBuilder by copying an existing Builder. + * + * @param other The existing builder to copy. + * @return A new State RecordBuilder + */ + public static utilities.State.Builder newBuilder(utilities.State.Builder other) { + if (other == null) { + return new utilities.State.Builder(); + } else { + return new utilities.State.Builder(other); + } + } + + /** + * Creates a new State RecordBuilder by copying an existing State instance. + * + * @param other The existing instance to copy. + * @return A new State RecordBuilder + */ + public static utilities.State.Builder newBuilder(utilities.State other) { + if (other == null) { + return new utilities.State.Builder(); + } else { + return new utilities.State.Builder(other); + } + } + + /** RecordBuilder for State instances. */ + @org.apache.avro.specific.AvroGenerated + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + /** The common name of the state. */ + private java.lang.CharSequence name; + /** The postal code abbreviation of the state. */ + private java.lang.CharSequence post_abbr; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * + * @param other The existing Builder to copy. + */ + private Builder(utilities.State.Builder other) { + super(other); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.post_abbr)) { + this.post_abbr = data().deepCopy(fields()[1].schema(), other.post_abbr); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + } + + /** + * Creates a Builder by copying an existing State instance + * + * @param other The existing instance to copy. + */ + private Builder(utilities.State other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.post_abbr)) { + this.post_abbr = data().deepCopy(fields()[1].schema(), other.post_abbr); + fieldSetFlags()[1] = true; + } + } + + /** + * Gets the value of the 'name' field. The common name of the state. + * + * @return The value. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. The common name of the state. + * + * @param value The value of 'name'. + * @return This builder. + */ + public utilities.State.Builder setName(java.lang.CharSequence value) { + validate(fields()[0], value); + this.name = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'name' field has been set. The common name of the state. + * + * @return True if the 'name' field has been set, false otherwise. + */ + public boolean hasName() { + return fieldSetFlags()[0]; + } + + /** + * Clears the value of the 'name' field. The common name of the state. + * + * @return This builder. + */ + public utilities.State.Builder clearName() { + name = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'post_abbr' field. The postal code abbreviation of the state. + * + * @return The value. + */ + public java.lang.CharSequence getPostAbbr() { + return post_abbr; + } + + /** + * Sets the value of the 'post_abbr' field. The postal code abbreviation of the state. + * + * @param value The value of 'post_abbr'. + * @return This builder. + */ + public utilities.State.Builder setPostAbbr(java.lang.CharSequence value) { + validate(fields()[1], value); + this.post_abbr = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'post_abbr' field has been set. The postal code abbreviation of the state. + * + * @return True if the 'post_abbr' field has been set, false otherwise. + */ + public boolean hasPostAbbr() { + return fieldSetFlags()[1]; + } + + /** + * Clears the value of the 'post_abbr' field. The postal code abbreviation of the state. + * + * @return This builder. + */ + public utilities.State.Builder clearPostAbbr() { + post_abbr = null; + fieldSetFlags()[1] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public State build() { + try { + State record = new State(); + record.name = + fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]); + record.post_abbr = + fieldSetFlags()[1] + ? this.post_abbr + : (java.lang.CharSequence) defaultValue(fields()[1]); + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter WRITER$ = + (org.apache.avro.io.DatumWriter) MODEL$.createDatumWriter(SCHEMA$); + + @Override + public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader READER$ = + (org.apache.avro.io.DatumReader) MODEL$.createDatumReader(SCHEMA$); + + @Override + public void readExternal(java.io.ObjectInput in) throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override + protected boolean hasCustomCoders() { + return true; + } + + @Override + public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException { + out.writeString(this.name); + + out.writeString(this.post_abbr); + } + + @Override + public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null); + + this.post_abbr = in.readString(this.post_abbr instanceof Utf8 ? (Utf8) this.post_abbr : null); + + } else { + for (int i = 0; i < 2; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null); + break; + + case 1: + this.post_abbr = + in.readString(this.post_abbr instanceof Utf8 ? (Utf8) this.post_abbr : null); + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} diff --git a/samples/snippets/src/main/java/utilities/StateProto.java b/samples/snippets/src/main/java/utilities/StateProto.java new file mode 100644 index 000000000..7afab1ca2 --- /dev/null +++ b/samples/snippets/src/main/java/utilities/StateProto.java @@ -0,0 +1,781 @@ +/* + * Copyright 2021 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. + */ + +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: us-states.proto + +package utilities; + +public final class StateProto { + private StateProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + public interface StateOrBuilder + extends + // @@protoc_insertion_point(interface_extends:utilities.State) + com.google.protobuf.MessageOrBuilder { + + /** + * string name = 1; + * + * @return The name. + */ + java.lang.String getName(); + /** + * string name = 1; + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * string post_abbr = 2; + * + * @return The postAbbr. + */ + java.lang.String getPostAbbr(); + /** + * string post_abbr = 2; + * + * @return The bytes for postAbbr. + */ + com.google.protobuf.ByteString getPostAbbrBytes(); + } + /** Protobuf type {@code utilities.State} */ + public static final class State extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:utilities.State) + StateOrBuilder { + private static final long serialVersionUID = 0L; + // Use State.newBuilder() to construct. + private State(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private State() { + name_ = ""; + postAbbr_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new State(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return this.unknownFields; + } + + private State( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + java.lang.String s = input.readStringRequireUtf8(); + + name_ = s; + break; + } + case 18: + { + java.lang.String s = input.readStringRequireUtf8(); + + postAbbr_ = s; + break; + } + default: + { + if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return utilities.StateProto.internal_static_utilities_State_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return utilities.StateProto.internal_static_utilities_State_fieldAccessorTable + .ensureFieldAccessorsInitialized( + utilities.StateProto.State.class, utilities.StateProto.State.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + private volatile java.lang.Object name_; + /** + * string name = 1; + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * string name = 1; + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int POST_ABBR_FIELD_NUMBER = 2; + private volatile java.lang.Object postAbbr_; + /** + * string post_abbr = 2; + * + * @return The postAbbr. + */ + @java.lang.Override + public java.lang.String getPostAbbr() { + java.lang.Object ref = postAbbr_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + postAbbr_ = s; + return s; + } + } + /** + * string post_abbr = 2; + * + * @return The bytes for postAbbr. + */ + @java.lang.Override + public com.google.protobuf.ByteString getPostAbbrBytes() { + java.lang.Object ref = postAbbr_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + postAbbr_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!getNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (!getPostAbbrBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, postAbbr_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (!getPostAbbrBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, postAbbr_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof utilities.StateProto.State)) { + return super.equals(obj); + } + utilities.StateProto.State other = (utilities.StateProto.State) obj; + + if (!getName().equals(other.getName())) return false; + if (!getPostAbbr().equals(other.getPostAbbr())) return false; + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (37 * hash) + POST_ABBR_FIELD_NUMBER; + hash = (53 * hash) + getPostAbbr().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static utilities.StateProto.State parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static utilities.StateProto.State parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static utilities.StateProto.State parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static utilities.StateProto.State parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static utilities.StateProto.State parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static utilities.StateProto.State parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static utilities.StateProto.State parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static utilities.StateProto.State parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static utilities.StateProto.State parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static utilities.StateProto.State parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static utilities.StateProto.State parseFrom(com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static utilities.StateProto.State parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(utilities.StateProto.State prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** Protobuf type {@code utilities.State} */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:utilities.State) + utilities.StateProto.StateOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return utilities.StateProto.internal_static_utilities_State_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return utilities.StateProto.internal_static_utilities_State_fieldAccessorTable + .ensureFieldAccessorsInitialized( + utilities.StateProto.State.class, utilities.StateProto.State.Builder.class); + } + + // Construct using utilities.StateProto.State.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {} + } + + @java.lang.Override + public Builder clear() { + super.clear(); + name_ = ""; + + postAbbr_ = ""; + + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return utilities.StateProto.internal_static_utilities_State_descriptor; + } + + @java.lang.Override + public utilities.StateProto.State getDefaultInstanceForType() { + return utilities.StateProto.State.getDefaultInstance(); + } + + @java.lang.Override + public utilities.StateProto.State build() { + utilities.StateProto.State result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public utilities.StateProto.State buildPartial() { + utilities.StateProto.State result = new utilities.StateProto.State(this); + result.name_ = name_; + result.postAbbr_ = postAbbr_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof utilities.StateProto.State) { + return mergeFrom((utilities.StateProto.State) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(utilities.StateProto.State other) { + if (other == utilities.StateProto.State.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + onChanged(); + } + if (!other.getPostAbbr().isEmpty()) { + postAbbr_ = other.postAbbr_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + utilities.StateProto.State parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (utilities.StateProto.State) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object name_ = ""; + /** + * string name = 1; + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string name = 1; + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string name = 1; + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + name_ = value; + onChanged(); + return this; + } + /** + * string name = 1; + * + * @return This builder for chaining. + */ + public Builder clearName() { + + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * string name = 1; + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + name_ = value; + onChanged(); + return this; + } + + private java.lang.Object postAbbr_ = ""; + /** + * string post_abbr = 2; + * + * @return The postAbbr. + */ + public java.lang.String getPostAbbr() { + java.lang.Object ref = postAbbr_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + postAbbr_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string post_abbr = 2; + * + * @return The bytes for postAbbr. + */ + public com.google.protobuf.ByteString getPostAbbrBytes() { + java.lang.Object ref = postAbbr_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + postAbbr_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string post_abbr = 2; + * + * @param value The postAbbr to set. + * @return This builder for chaining. + */ + public Builder setPostAbbr(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + postAbbr_ = value; + onChanged(); + return this; + } + /** + * string post_abbr = 2; + * + * @return This builder for chaining. + */ + public Builder clearPostAbbr() { + + postAbbr_ = getDefaultInstance().getPostAbbr(); + onChanged(); + return this; + } + /** + * string post_abbr = 2; + * + * @param value The bytes for postAbbr to set. + * @return This builder for chaining. + */ + public Builder setPostAbbrBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + postAbbr_ = value; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:utilities.State) + } + + // @@protoc_insertion_point(class_scope:utilities.State) + private static final utilities.StateProto.State DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new utilities.StateProto.State(); + } + + public static utilities.StateProto.State getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public State parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new State(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public utilities.StateProto.State getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_utilities_State_descriptor; + private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_utilities_State_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n\017us-states.proto\022\tutilities\"(\n\005State\022\014\n" + + "\004name\030\001 \001(\t\022\021\n\tpost_abbr\030\002 \001(\tB\014B\nStateP" + + "rotob\006proto3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); + internal_static_utilities_State_descriptor = getDescriptor().getMessageTypes().get(0); + internal_static_utilities_State_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_utilities_State_descriptor, + new java.lang.String[] { + "Name", "PostAbbr", + }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/samples/snippets/src/main/resources/us-states.avsc b/samples/snippets/src/main/resources/us-states.avsc new file mode 100644 index 000000000..7521882c7 --- /dev/null +++ b/samples/snippets/src/main/resources/us-states.avsc @@ -0,0 +1,18 @@ +{ + "type":"record", + "name":"State", + "namespace":"utilities", + "doc":"A list of states in the United States of America.", + "fields":[ + { + "name":"name", + "type":"string", + "doc":"The common name of the state." + }, + { + "name":"post_abbr", + "type":"string", + "doc":"The postal code abbreviation of the state." + } + ] +} \ No newline at end of file diff --git a/samples/snippets/src/main/resources/us-states.proto b/samples/snippets/src/main/resources/us-states.proto new file mode 100644 index 000000000..819387558 --- /dev/null +++ b/samples/snippets/src/main/resources/us-states.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package utilities; +option java_outer_classname = "StateProto"; + +message State { + string name = 1; + string post_abbr = 2; +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/pubsub/AdminIT.java b/samples/snippets/src/test/java/pubsub/AdminIT.java index 42825d63a..1d198044d 100644 --- a/samples/snippets/src/test/java/pubsub/AdminIT.java +++ b/samples/snippets/src/test/java/pubsub/AdminIT.java @@ -183,7 +183,6 @@ public void testAdmin() throws Exception { assertThat(bout.toString()).contains("Created a subscription with ordering"); assertThat(bout.toString()).contains("enable_message_ordering=true"); - bout.reset(); // Test delete subscription. Run twice to delete both pull and push subscriptions. DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId); diff --git a/samples/snippets/src/test/java/pubsub/SchemaIT.java b/samples/snippets/src/test/java/pubsub/SchemaIT.java new file mode 100644 index 000000000..45e899619 --- /dev/null +++ b/samples/snippets/src/test/java/pubsub/SchemaIT.java @@ -0,0 +1,191 @@ +/* + * Copyright 2021 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 static junit.framework.TestCase.assertNotNull; + +import com.google.api.gax.rpc.NotFoundException; +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.cloud.pubsub.v1.SubscriptionAdminClient; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.pubsub.v1.Encoding; +import com.google.pubsub.v1.ProjectSubscriptionName; +import com.google.pubsub.v1.SchemaName; +import com.google.pubsub.v1.TopicName; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +public class SchemaIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String _suffix = UUID.randomUUID().toString(); + private static final String avroTopicId = "avro-topic-" + _suffix; + private static final String protoTopicId = "proto-topic-" + _suffix; + private static final String avroSubscriptionId = "avro-subscription-" + _suffix; + private static final String protoSubscriptionId = "proto-subscription-" + _suffix; + private static final String avroSchemaId = "avro-schema-" + _suffix; + private static final String protoSchemaId = "proto-schema-" + _suffix; + + ClassLoader classLoader = getClass().getClassLoader(); + File avscFile = new File(classLoader.getResource("us-states.avsc").getFile()); + String absoluteAvscFilePath = avscFile.getAbsolutePath(); + + File protoFile = new File(classLoader.getResource("us-states.proto").getFile()); + String absoluteProtoFilePath = protoFile.getAbsolutePath(); + + private static final TopicName avroTopicName = TopicName.of(projectId, avroTopicId); + private static final TopicName protoTopicName = TopicName.of(projectId, protoTopicId); + private static final ProjectSubscriptionName avroSubscriptionName = + ProjectSubscriptionName.of(projectId, avroSubscriptionId); + private static final ProjectSubscriptionName protoSubscriptionName = + ProjectSubscriptionName.of(projectId, protoSubscriptionId); + private static final SchemaName avroSchemaName = SchemaName.of(projectId, avroSchemaId); + private static final SchemaName protoSchemaName = SchemaName.of(projectId, protoSchemaId); + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable " + varName + " is required to perform these tests.", + System.getenv(varName)); + } + + @Rule public Timeout globalTimeout = Timeout.seconds(300); // 5 minute timeout + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws Exception { + // Delete the schemas if they have not been cleaned up. + try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) { + schemaServiceClient.deleteSchema(protoSchemaName); + schemaServiceClient.deleteSchema(avroSchemaName); + } catch (NotFoundException ignored) { + // Ignore this as resources may have already been cleaned up. + } + + // Delete the subscriptions. + try (SubscriptionAdminClient subscriptionAdmin = SubscriptionAdminClient.create()) { + subscriptionAdmin.deleteSubscription(avroSubscriptionName.toString()); + subscriptionAdmin.deleteSubscription(protoSubscriptionName.toString()); + } catch (NotFoundException ignored) { + // Ignore this as resources may have already been cleaned up. + } + + // Delete the topics. + try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { + topicAdminClient.deleteTopic(avroTopicName.toString()); + topicAdminClient.deleteTopic(protoTopicName.toString()); + } catch (NotFoundException ignored) { + // Ignore this as resources may have already been cleaned up. + } + System.setOut(null); + } + + @Test + public void testSchema() throws Exception { + // Test creating Avro schema. + CreateAvroSchemaExample.createAvroSchemaExample(projectId, avroSchemaId, absoluteAvscFilePath); + assertThat(bout.toString()).contains("Created a schema using an Avro schema:"); + assertThat(bout.toString()).contains(avroSchemaName.toString()); + + // Test creating Proto schema. + CreateProtoSchemaExample.createProtoSchemaExample( + projectId, protoSchemaId, absoluteProtoFilePath); + assertThat(bout.toString()).contains("Created a schema using a protobuf schema:"); + assertThat(bout.toString()).contains(protoSchemaName.toString()); + + bout.reset(); + // Test getting a schema. + GetSchemaExample.getSchemaExample(projectId, avroSchemaId); + assertThat(bout.toString()).contains("Got a schema:"); + assertThat(bout.toString()).contains(avroSchemaName.toString()); + + bout.reset(); + // Test listing schemas. + ListSchemasExample.listSchemasExample(projectId); + assertThat(bout.toString()).contains("Listed schemas."); + assertThat(bout.toString()).contains(avroSchemaName.toString()); + + bout.reset(); + // Test creating a topic with an Avro schema with BINARY encoding. + CreateTopicWithSchemaExample.createTopicWithSchemaExample( + projectId, avroTopicId, avroSchemaId, Encoding.BINARY); + assertThat(bout.toString()).contains("Created topic with schema: " + avroTopicName.toString()); + + bout.reset(); + // Test creating a topic with a proto schema with JSON encoding. + CreateTopicWithSchemaExample.createTopicWithSchemaExample( + projectId, protoTopicId, protoSchemaId, Encoding.JSON); + assertThat(bout.toString()).contains("Created topic with schema: " + protoTopicName.toString()); + + // Attach a default pull subscription to each topic. + CreatePullSubscriptionExample.createPullSubscriptionExample( + projectId, avroSubscriptionId, avroTopicId); + CreatePullSubscriptionExample.createPullSubscriptionExample( + projectId, protoSubscriptionId, protoTopicId); + + bout.reset(); + // Test publishing BINARY-encoded Avro records. + PublishAvroRecordsExample.publishAvroRecordsExample(projectId, avroTopicId); + assertThat(bout.toString()).contains("Preparing a BINARY encoder..."); + assertThat(bout.toString()).contains("Published message ID:"); + + bout.reset(); + // Test publishing JSON-encoded proto messages. + PublishProtobufMessagesExample.publishProtobufMessagesExample(projectId, protoTopicId); + assertThat(bout.toString()).contains("Publishing a JSON-formatted message:"); + assertThat(bout.toString()).contains("Published message ID:"); + + bout.reset(); + // Test receiving BINARY-encoded Avro records. + SubscribeWithAvroSchemaExample.subscribeWithAvroSchemaExample(projectId, avroSubscriptionId); + assertThat(bout.toString()).contains("Receiving a binary-encoded message:"); + assertThat(bout.toString()).contains(" is abbreviated as "); + + bout.reset(); + // Test receiving JSON-encoded proto messages. + SubscribeWithProtoSchemaExample.subscribeWithProtoSchemaExample(projectId, protoSubscriptionId); + assertThat(bout.toString()).contains("Received a JSON-formatted message:"); + assertThat(bout.toString()).contains("Ack'ed the message"); + + bout.reset(); + // Test deleting a schema. + DeleteSchemaExample.deleteSchemaExample(projectId, avroSchemaId); + assertThat(bout.toString()).contains("Deleted a schema:"); + assertThat(bout.toString()).contains(avroSchemaName.toString()); + } +} diff --git a/samples/snippets/src/test/resources/us-states.avsc b/samples/snippets/src/test/resources/us-states.avsc new file mode 100644 index 000000000..7521882c7 --- /dev/null +++ b/samples/snippets/src/test/resources/us-states.avsc @@ -0,0 +1,18 @@ +{ + "type":"record", + "name":"State", + "namespace":"utilities", + "doc":"A list of states in the United States of America.", + "fields":[ + { + "name":"name", + "type":"string", + "doc":"The common name of the state." + }, + { + "name":"post_abbr", + "type":"string", + "doc":"The postal code abbreviation of the state." + } + ] +} \ No newline at end of file diff --git a/samples/snippets/src/test/resources/us-states.proto b/samples/snippets/src/test/resources/us-states.proto new file mode 100644 index 000000000..819387558 --- /dev/null +++ b/samples/snippets/src/test/resources/us-states.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package utilities; +option java_outer_classname = "StateProto"; + +message State { + string name = 1; + string post_abbr = 2; +} \ No newline at end of file From 9f95e90948d7f8f076e95e9e59f3e3593df6155d Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 24 Feb 2021 10:02:03 -0800 Subject: [PATCH 07/11] chore: regenerate README (#523) This PR was generated using Autosynth. :rainbow:

Log from Synthtool ``` 2021-02-24 17:47:45,183 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-02-24 17:47:46,809 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ```
Full log will be available here: https://source.cloud.google.com/results/invocations/befb92b0-6e17-4478-a77c-3b6600ad2335/targets - [ ] To automatically regenerate this PR, check this box. --- .github/readme/synth.metadata/synth.metadata | 2 +- README.md | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata index 27d1905c9..692be94f5 100644 --- a/.github/readme/synth.metadata/synth.metadata +++ b/.github/readme/synth.metadata/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-pubsub.git", - "sha": "87f081f5ccadc01ea4d3c5fe188d5e1b6ba32fbe" + "sha": "a71e898ebe768f07966a13779c890818e9dad694" } }, { diff --git a/README.md b/README.md index d520c5d4c..a427555a1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file com.google.cloud google-cloud-pubsub + 1.111.0 ``` @@ -45,7 +46,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:16.4.0') +implementation platform('com.google.cloud:libraries-bom:17.0.0') compile 'com.google.cloud:google-cloud-pubsub' ``` @@ -229,19 +230,27 @@ has instructions for running the samples. | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | +| Create Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/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/master/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/master/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) | | Create Push Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.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/CreatePushSubscriptionExample.java) | | Create Subscription With Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.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/CreateSubscriptionWithDeadLetterPolicyExample.java) | | Create Subscription With Ordering | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithOrdering.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/CreateSubscriptionWithOrdering.java) | | Create Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateTopicExample.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/CreateTopicExample.java) | +| Create Topic With Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/CreateTopicWithSchemaExample.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/CreateTopicWithSchemaExample.java) | +| Delete Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteSchemaExample.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/DeleteSchemaExample.java) | | Delete Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteSubscriptionExample.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/DeleteSubscriptionExample.java) | | Delete Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DeleteTopicExample.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/DeleteTopicExample.java) | | Detach Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/DetachSubscriptionExample.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/DetachSubscriptionExample.java) | +| Get Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetSchemaExample.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/GetSchemaExample.java) | | Get Subscription Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetSubscriptionPolicyExample.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/GetSubscriptionPolicyExample.java) | | Get Topic Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/GetTopicPolicyExample.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/GetTopicPolicyExample.java) | +| List Schemas Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSchemasExample.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/ListSchemasExample.java) | | List Subscriptions In Project Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSubscriptionsInProjectExample.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/ListSubscriptionsInProjectExample.java) | | List Subscriptions In Topic Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListSubscriptionsInTopicExample.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/ListSubscriptionsInTopicExample.java) | | List Topics Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/ListTopicsExample.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/ListTopicsExample.java) | +| Publish Avro Records Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.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/PublishAvroRecordsExample.java) | +| Publish Protobuf Messages Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.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/PublishProtobufMessagesExample.java) | | Publish With Batch Settings Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithBatchSettingsExample.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/PublishWithBatchSettingsExample.java) | | Publish With Concurrency Control Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithConcurrencyControlExample.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/PublishWithConcurrencyControlExample.java) | | Publish With Custom Attributes Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/PublishWithCustomAttributesExample.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/PublishWithCustomAttributesExample.java) | @@ -257,14 +266,18 @@ has instructions for running the samples. | Subscribe Async Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeAsyncExample.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/SubscribeAsyncExample.java) | | Subscribe Sync Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeSyncExample.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/SubscribeSyncExample.java) | | Subscribe Sync With Lease Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeSyncWithLeaseExample.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/SubscribeSyncWithLeaseExample.java) | +| Subscribe With Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/SubscribeWithAvroSchemaExample.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/SubscribeWithAvroSchemaExample.java) | | Subscribe With Concurrency Control Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/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/master/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/master/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 Flow Control Settings Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/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/master/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/master/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) | | Test Topic Permissions Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/TestTopicPermissionsExample.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/TestTopicPermissionsExample.java) | | Update Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/UpdateDeadLetterPolicyExample.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/UpdateDeadLetterPolicyExample.java) | | Update Push Configuration Example | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/pubsub/UpdatePushConfigurationExample.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/UpdatePushConfigurationExample.java) | +| State | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/utilities/State.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/utilities/State.java) | +| State Proto | [source code](https://github.com/googleapis/java-pubsub/blob/master/samples/snippets/src/main/java/utilities/StateProto.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/utilities/StateProto.java) | From c1642a5fb732eda9bbb00d1cabae50fc3d03dec3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 24 Feb 2021 19:02:38 +0100 Subject: [PATCH 08/11] chore(deps): update dependency com.google.cloud:libraries-bom to v17 (#522) --- samples/snippets/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index a578bfadf..d44a8e465 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -45,7 +45,7 @@ com.google.cloud libraries-bom - 16.4.0 + 17.0.0 pom import From 868060214e0f1f3da770d9160753794680b761e9 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 24 Feb 2021 10:16:03 -0800 Subject: [PATCH 09/11] chore: regenerate README (#525) This PR was generated using Autosynth. :rainbow:
Log from Synthtool ``` 2021-02-24 18:04:44,617 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsub/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-02-24 18:04:46,208 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ```
Full log will be available here: https://source.cloud.google.com/results/invocations/d41edf21-6233-4fc3-bb67-99b8c66e4b94/targets - [ ] To automatically regenerate this PR, check this box. --- .github/readme/synth.metadata/synth.metadata | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata index 692be94f5..d7583f371 100644 --- a/.github/readme/synth.metadata/synth.metadata +++ b/.github/readme/synth.metadata/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-pubsub.git", - "sha": "a71e898ebe768f07966a13779c890818e9dad694" + "sha": "c1642a5fb732eda9bbb00d1cabae50fc3d03dec3" } }, { diff --git a/README.md b/README.md index a427555a1..153aaf6ef 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file com.google.cloud libraries-bom - 16.4.0 + 17.0.0 pom import From b5e07a866f096744feafc6187bcb022669f5fa26 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 24 Feb 2021 19:54:12 +0100 Subject: [PATCH 10/11] deps: update dependency com.google.protobuf:protobuf-java-util to v3.15.2 (#524) --- 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 9df2bb003..b1f9c28d6 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -75,7 +75,7 @@ com.google.protobuf protobuf-java-util - 3.14.0 + 3.15.2
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 8268db095..c2f0f3203 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -61,7 +61,7 @@ com.google.protobuf protobuf-java-util - 3.14.0 + 3.15.2 diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index d44a8e465..43d0bb023 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -73,7 +73,7 @@ com.google.protobuf protobuf-java-util - 3.14.0 + 3.15.2 From 3a7c4d0e9346c4d177a2df48f0278e7e895a40ce Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 24 Feb 2021 19:10:05 +0000 Subject: [PATCH 11/11] chore(master): release 1.111.2 (#526) :robot: I have created a release \*beep\* \*boop\* --- ### [1.111.2](https://www.github.com/googleapis/java-pubsub/compare/v1.111.1...v1.111.2) (2021-02-24) ### Dependencies * update dependency com.google.protobuf:protobuf-java-util to v3.15.2 ([#524](https://www.github.com/googleapis/java-pubsub/issues/524)) ([b5e07a8](https://www.github.com/googleapis/java-pubsub/commit/b5e07a866f096744feafc6187bcb022669f5fa26)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- CHANGELOG.md | 7 +++++++ 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 +++--- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c4d2080c..89aeb1a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [1.111.2](https://www.github.com/googleapis/java-pubsub/compare/v1.111.1...v1.111.2) (2021-02-24) + + +### Dependencies + +* update dependency com.google.protobuf:protobuf-java-util to v3.15.2 ([#524](https://www.github.com/googleapis/java-pubsub/issues/524)) ([b5e07a8](https://www.github.com/googleapis/java-pubsub/commit/b5e07a866f096744feafc6187bcb022669f5fa26)) + ### [1.111.1](https://www.github.com/googleapis/java-pubsub/compare/v1.111.0...v1.111.1) (2021-02-23) diff --git a/google-cloud-pubsub-bom/pom.xml b/google-cloud-pubsub-bom/pom.xml index 00ec2d18a..7359bd2f0 100644 --- a/google-cloud-pubsub-bom/pom.xml +++ b/google-cloud-pubsub-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-pubsub-bom - 1.111.2-SNAPSHOT + 1.111.2 pom com.google.cloud @@ -64,17 +64,17 @@ com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 com.google.cloud google-cloud-pubsub - 1.111.2-SNAPSHOT + 1.111.2 diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index 2ce378b7a..c82ec886d 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-pubsub - 1.111.2-SNAPSHOT + 1.111.2 jar Google Cloud Pub/Sub https://github.com/googleapis/java-pubsub @@ -11,7 +11,7 @@ com.google.cloud google-cloud-pubsub-parent - 1.111.2-SNAPSHOT + 1.111.2 google-cloud-pubsub diff --git a/grpc-google-cloud-pubsub-v1/pom.xml b/grpc-google-cloud-pubsub-v1/pom.xml index 38634d6e4..77fa71574 100644 --- a/grpc-google-cloud-pubsub-v1/pom.xml +++ b/grpc-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 grpc-google-cloud-pubsub-v1 GRPC library for grpc-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.111.2-SNAPSHOT + 1.111.2 diff --git a/pom.xml b/pom.xml index 48e66578e..7cfe9b140 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-pubsub-parent pom - 1.111.2-SNAPSHOT + 1.111.2 Google Cloud Pub/Sub Parent https://github.com/googleapis/java-pubsub @@ -78,17 +78,17 @@ com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 com.google.api.grpc grpc-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 com.google.cloud google-cloud-pubsub - 1.111.2-SNAPSHOT + 1.111.2 diff --git a/proto-google-cloud-pubsub-v1/pom.xml b/proto-google-cloud-pubsub-v1/pom.xml index a735fc6a4..84fabe418 100644 --- a/proto-google-cloud-pubsub-v1/pom.xml +++ b/proto-google-cloud-pubsub-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-pubsub-v1 - 1.93.2-SNAPSHOT + 1.93.2 proto-google-cloud-pubsub-v1 PROTO library for proto-google-cloud-pubsub-v1 com.google.cloud google-cloud-pubsub-parent - 1.111.2-SNAPSHOT + 1.111.2 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index c2f0f3203..f8da12d97 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -43,7 +43,7 @@ com.google.cloud google-cloud-pubsub - 1.111.2-SNAPSHOT + 1.111.2 diff --git a/versions.txt b/versions.txt index 13a571ecb..c1cf8a46f 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -proto-google-cloud-pubsub-v1:1.93.1:1.93.2-SNAPSHOT -grpc-google-cloud-pubsub-v1:1.93.1:1.93.2-SNAPSHOT -google-cloud-pubsub:1.111.1:1.111.2-SNAPSHOT \ No newline at end of file +proto-google-cloud-pubsub-v1:1.93.2:1.93.2 +grpc-google-cloud-pubsub-v1:1.93.2:1.93.2 +google-cloud-pubsub:1.111.2:1.111.2 \ No newline at end of file