From 3625c16ed176356defac28f5840b86e70b83ce5d Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Mon, 5 Jun 2023 18:00:20 +0000 Subject: [PATCH 1/3] adding pubsub emulator example --- .../java/pubsub/UsePubSubEmulatorExample.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java diff --git a/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java new file mode 100644 index 000000000..9a65e4cfe --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java @@ -0,0 +1,70 @@ +/* + * Copyright 2017 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pubsub; + +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.rpc.FixedTransportChannelProvider; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.cloud.pubsub.v1.Publisher; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.cloud.pubsub.v1.TopicAdminSettings; +import com.google.pubsub.v1.TopicName; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.io.IOException; + +/** + * Snippet that demonstrates creating Pub/Sub clients using the Google Cloud Pub/Sub emulator. + * + *

Note: clients cannot start/stop the emulator. + */ +public class UsePubSubEmulatorExample { + + public static void main(String... args) throws IOException { + // [START pubsub_use_emulator] + String hostport = System.getenv("PUBSUB_EMULATOR_HOST"); + ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build(); + try { + TransportChannelProvider channelProvider = + FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); + CredentialsProvider credentialsProvider = NoCredentialsProvider.create(); + + // Set the channel and credentials provider when creating a `TopicAdminClient`. + // Similarly for SubscriptionAdminClient + TopicAdminClient topicClient = + TopicAdminClient.create( + TopicAdminSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build()); + + TopicName topicName = TopicName.of("my-project-id", "my-topic-id"); + // Set the channel and credentials provider when creating a `Publisher`. + // Similarly for Subscriber + Publisher publisher = + Publisher.newBuilder(topicName) + .setChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build(); + } finally { + channel.shutdown(); + } + // [END pubsub_use_emulator] + } +} \ No newline at end of file From 1f1cbe8cc1a82b873679a7cfca5558060b36bb08 Mon Sep 17 00:00:00 2001 From: Maitri Mangal Date: Mon, 5 Jun 2023 18:00:20 +0000 Subject: [PATCH 2/3] docs: adding pubsub emulator example --- .../java/pubsub/UsePubSubEmulatorExample.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java diff --git a/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java new file mode 100644 index 000000000..9a65e4cfe --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java @@ -0,0 +1,70 @@ +/* + * Copyright 2017 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pubsub; + +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.rpc.FixedTransportChannelProvider; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.cloud.pubsub.v1.Publisher; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.cloud.pubsub.v1.TopicAdminSettings; +import com.google.pubsub.v1.TopicName; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.io.IOException; + +/** + * Snippet that demonstrates creating Pub/Sub clients using the Google Cloud Pub/Sub emulator. + * + *

Note: clients cannot start/stop the emulator. + */ +public class UsePubSubEmulatorExample { + + public static void main(String... args) throws IOException { + // [START pubsub_use_emulator] + String hostport = System.getenv("PUBSUB_EMULATOR_HOST"); + ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build(); + try { + TransportChannelProvider channelProvider = + FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); + CredentialsProvider credentialsProvider = NoCredentialsProvider.create(); + + // Set the channel and credentials provider when creating a `TopicAdminClient`. + // Similarly for SubscriptionAdminClient + TopicAdminClient topicClient = + TopicAdminClient.create( + TopicAdminSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build()); + + TopicName topicName = TopicName.of("my-project-id", "my-topic-id"); + // Set the channel and credentials provider when creating a `Publisher`. + // Similarly for Subscriber + Publisher publisher = + Publisher.newBuilder(topicName) + .setChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build(); + } finally { + channel.shutdown(); + } + // [END pubsub_use_emulator] + } +} \ No newline at end of file From 42efa1490507e1ba5c138b082407132e4f3a85c8 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 5 Jun 2023 20:57:01 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 7 ++++--- .../src/main/java/pubsub/UsePubSubEmulatorExample.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ff71d5c59..419792896 100644 --- a/README.md +++ b/README.md @@ -51,20 +51,20 @@ 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:26.1.5') +implementation platform('com.google.cloud:libraries-bom:26.16.0') implementation 'com.google.cloud:google-cloud-pubsub' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-pubsub:1.122.1' +implementation 'com.google.cloud:google-cloud-pubsub:1.123.13' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.122.1" +libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.123.13" ``` ## Authentication @@ -294,6 +294,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m | Test Topic Permissions Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/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/main/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/main/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) | +| Use Pub Sub Emulator Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.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/UsePubSubEmulatorExample.java) | | State | [source code](https://github.com/googleapis/java-pubsub/blob/main/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/main/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) | diff --git a/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java index 9a65e4cfe..f4c69eac4 100644 --- a/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java +++ b/samples/snippets/src/main/java/pubsub/UsePubSubEmulatorExample.java @@ -67,4 +67,4 @@ public static void main(String... args) throws IOException { } // [END pubsub_use_emulator] } -} \ No newline at end of file +}