diff --git a/google-cloud-pubsub/.rubocop.yml b/google-cloud-pubsub/.rubocop.yml index a8938fb82daf..5eb3c63d18a6 100644 --- a/google-cloud-pubsub/.rubocop.yml +++ b/google-cloud-pubsub/.rubocop.yml @@ -7,7 +7,6 @@ AllCops: - "support/**/*" - "test/**/*" - "samples/utilities/**/*" - - "v2samples/**/*" Style/Documentation: Enabled: false diff --git a/google-cloud-pubsub/v2samples/Gemfile b/google-cloud-pubsub/v2samples/Gemfile deleted file mode 100644 index 7cb35b395703..000000000000 --- a/google-cloud-pubsub/v2samples/Gemfile +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2021 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. - -# [START pubsub_old_version_dependencies] -source "https://rubygems.org" - -# [END pubsub_old_version_dependencies] - -if ENV["GOOGLE_CLOUD_SAMPLES_TEST"] == "master" - gem "google-cloud-pubsub", path: "../../google-cloud-pubsub" -else - # [START pubsub_old_version_dependencies] - gem "google-cloud-pubsub" - # [END pubsub_old_version_dependencies] -end - -gem "sinatra" - -group :test do - gem "avro", "~> 1.10" - gem "google-cloud-bigquery" - gem "google-style", "~> 1.25.1" - gem "minitest", "~> 5.14" - gem "minitest-focus", "~> 1.1" - gem "minitest-hooks", "~> 1.5" - gem "rack-test" - gem "rake" - gem "toys-core" -end diff --git a/google-cloud-pubsub/v2samples/README.md b/google-cloud-pubsub/v2samples/README.md deleted file mode 100644 index 3326bbc2e80f..000000000000 --- a/google-cloud-pubsub/v2samples/README.md +++ /dev/null @@ -1,129 +0,0 @@ -Google Cloud Platform logo - -# Google Cloud Pub/Sub Ruby Samples - -[Google Cloud Pub/Sub][language_docs] is a simple, reliable, scalable foundation for stream analytics -and event-driven computing systems. - -[language_docs]: https://cloud.google.com/pubsub/docs/ - -## Setup - -### Authentication - -Authentication is typically done through [Application Default Credentials](https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow) -, which means you do not have to change the code to authenticate as long as your -environment has credentials. You have a few options for setting up -authentication: - -1. When running locally, use the [Google Cloud SDK](https://cloud.google.com/sdk/) - - gcloud auth application-default login - -1. When running on App Engine or Compute Engine, credentials are already set-up. -However, you may need to configure your Compute Engine instance with -[additional scopes](https://cloud.google.com/compute/docs/authentication#using). - -1. You can create a [Service Account key file](https://cloud.google.com/docs/authentication#service_accounts) -. This file can be used to authenticate to Google Cloud Platform services from -any environment. To use the file, set the `GOOGLE_APPLICATION_CREDENTIALS` -environment variable to the path to the key file, for example: - - export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json - -### Set Project ID - -Next, set the `GOOGLE_CLOUD_PROJECT` environment variable to the project name -set in the -[Google Cloud Platform Developer Console](https://console.cloud.google.com): - - export GOOGLE_CLOUD_PROJECT="YOUR-PROJECT-ID" - -### Install Dependencies - -1. Install the [Bundler](http://bundler.io/) gem. - -1. Install dependencies using: - - bundle install - -## Run samples - -If using the `topics.rb create_push_subscription` command (see below), first deploy the push listener -App Engine app defined in `listener.rb` and configured in `app.yaml`. The `endpoint` argument to -`create_push_subscription` should look like `https://my-project.appspot.com/push`. You can see messages -pushed to the listener in [Google Cloud Logging](https://cloud.google.com/logging/docs/), or simply -run `tail` on the logs as shown below. - - gcloud app deploy --promote - gcloud app logs tail -s default - -Run the quickstart sample to create a topic: - - bundle exec ruby quickstart.rb - -Run the sample for using topics: - - bundle exec ruby topics.rb - -Usage: - - bundle exec ruby topics.rb [command] [arguments] - - Commands: - create_topic Create a topic - list_topics List topics in a project - list_topic_subscriptions List subscriptions in a topic - delete_topic Delete topic policies - get_topic_policy Get topic policies - set_topic_policy Set topic policies - test_topic_permissions Test topic permissions - create_pull_subscription Create a pull subscription - create_push_subscription Create a push subscription - publish_message Publish message - publish_message_async Publish messages asynchronously - publish_messages_async_with_batch_settings Publish messages asynchronously in batch - publish_message_async_with_custom_attributes Publish messages asynchronously with custom attributes - publish_messages_async_with_concurrency_control Publish messages asynchronously with concurrency control - -Example: - - bundle exec ruby topics.rb create_topic my-new-topic - - Topic my-new-topic created. - -Run the sample for using subscriptions: - - bundle exec ruby subscriptions.rb - -Usage: - - bundle exec ruby subscriptions.rb [command] [arguments] - - Commands: - update_push_configuration Update the endpoint of a push subscription - list_subscriptions List subscriptions of a project - delete_subscription Delete a subscription - get_subscription_policy Get policies of a subscription - set_subscription_policy Set policies of a subscription - test_subscription_policy Test policies of a subscription - listen_for_messages Listen for messages - listen_for_messages_with_custom_attributes Listen for messages with custom attributes - pull_messages Pull messages - listen_for_messages_with_error_handler Listen for messages with an error handler - listen_for_messages_with_flow_control Listen for messages with flow control - listen_for_messages_with_concurrency_control Listen for messages with concurrency control - -Example: - - bundle exec ruby subscriptions.rb list_subscriptions - - Subscriptions: - YOUR-SUBSCRIPTION - - -## Test samples - -Test the samples using the Project ID configured above: - - bundle exec rake test diff --git a/google-cloud-pubsub/v2samples/listener.rb b/google-cloud-pubsub/v2samples/listener.rb deleted file mode 100644 index 5689d562b1c5..000000000000 --- a/google-cloud-pubsub/v2samples/listener.rb +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2021 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. - -require "sinatra" -require "json" -require "base64" - -post "/push" do - message = JSON.parse request.body.read - data = Base64.decode64 message["message"]["data"] - logger.info "Pushed Message: #{data}" - response.status = 204 -end - -set :port, 8080 diff --git a/google-cloud-pubsub/v2samples/pubsub_commit_proto_schema.rb b/google-cloud-pubsub/v2samples/pubsub_commit_proto_schema.rb deleted file mode 100644 index 23129c5d1fbb..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_commit_proto_schema.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2025 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. - -require "google/cloud/pubsub" - -def commit_proto_schema schema_id:, proto_file: - # [START pubsub_old_version_commit_proto_schema] - # schema_id = "your-schema-id" - # proto_file = "path/to/a/proto_file.proto" - - pubsub = Google::Cloud::Pubsub.new - schema = pubsub.schema schema_id - - definition = File.read proto_file - - result = schema.commit definition, :protocol_buffer - - puts "Schema committed with revision #{result.revision_id}." - result - # [END pubsub_old_version_commit_proto_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_avro_schema.rb b/google-cloud-pubsub/v2samples/pubsub_create_avro_schema.rb deleted file mode 100644 index ed4811383f59..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_avro_schema.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_avro_schema schema_id:, avsc_file: - # [START pubsub_old_version_create_avro_schema] - # schema_id = "your-schema-id" - # avsc_file = "path/to/an/avro/schema/file/(.avsc)/formatted/in/json" - - pubsub = Google::Cloud::Pubsub.new - - definition = File.read avsc_file - schema = pubsub.create_schema schema_id, :avro, definition - - puts "Schema #{schema.name} created." - # [END pubsub_old_version_create_avro_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_bigquery_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_create_bigquery_subscription.rb deleted file mode 100644 index 1d63be51c3bd..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_bigquery_subscription.rb +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START pubsub_old_version_create_bigquery_subscription] -require "google/cloud/pubsub" - -## -# Shows how to create a BigQuery subscription where messages published -# to a topic populates a BigQuery table. -# -# @param project_id [String] -# Your Google Cloud project (e.g. "my-project") -# @param topic_id [String] -# Your topic name (e.g. "my-secret") -# @param subscription_id [String] -# ID for new subscription to be created (e.g. "my-subscription") -# @param bigquery_table_id [String] -# ID of bigquery table (e.g "my-project:dataset-id.table-id") -# -def pubsub_old_version_create_bigquery_subscription project_id:, topic_id:, subscription_id:, bigquery_table_id: - pubsub = Google::Cloud::Pubsub.new project_id: project_id - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id, - bigquery_config: { - table: bigquery_table_id, - write_metadata: true - } - puts "BigQuery subscription created: #{subscription_id}." - puts "Table for subscription is: #{bigquery_table_id}" -end -# [END pubsub_old_version_create_bigquery_subscription] diff --git a/google-cloud-pubsub/v2samples/pubsub_create_proto_schema.rb b/google-cloud-pubsub/v2samples/pubsub_create_proto_schema.rb deleted file mode 100644 index de6ff05299b1..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_proto_schema.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_proto_schema schema_id:, proto_file: - # [START pubsub_old_version_create_proto_schema] - # schema_id = "your-schema-id" - # proto_file = "path/to/a/proto/file/(.proto)/formatted/in/protocol/buffers" - - pubsub = Google::Cloud::Pubsub.new - - definition = File.read proto_file - schema = pubsub.create_schema schema_id, :protocol_buffer, definition - - puts "Schema #{schema.name} created." - # [END pubsub_old_version_create_proto_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_pull_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_create_pull_subscription.rb deleted file mode 100644 index dd08e2fda0b9..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_pull_subscription.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_pull_subscription topic_id:, subscription_id: - # [START pubsub_old_version_create_pull_subscription] - # topic_id = "your-topic-id" - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id - - puts "Pull subscription #{subscription_id} created." - # [END pubsub_old_version_create_pull_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_push_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_create_push_subscription.rb deleted file mode 100644 index 522ec5aad68f..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_push_subscription.rb +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_push_subscription topic_id:, subscription_id:, endpoint: - # [START pubsub_old_version_create_push_subscription] - # topic_id = "your-topic-id" - # subscription_id = "your-subscription-id" - # endpoint = "https://your-test-project.appspot.com/push" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id, - endpoint: endpoint - - puts "Push subscription #{subscription_id} created." - # [END pubsub_old_version_create_push_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_exactly_once_delivery.rb b/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_exactly_once_delivery.rb deleted file mode 100644 index 57bf15f818f1..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_exactly_once_delivery.rb +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START pubsub_old_version_create_subscription_with_exactly_once_delivery] -require "google/cloud/pubsub" - -# Shows how to create a new subscription with exactly once delivery enabled -class PubsubCreateSubscriptionWithExactlyOnceDelivery - def create_subscription_with_exactly_once_delivery project_id:, topic_id:, subscription_id: - pubsub = Google::Cloud::Pubsub.new project_id: project_id - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id, enable_exactly_once_delivery: true - puts "Created subscription with exactly once delivery enabled: #{subscription_id}" - end - - def self.run - # TODO(developer): Replace these variables before running the sample. - project_id = "your-project-id" - topic_id = "your-topic-id" - subscription_id = "id-for-new-subcription" - pubsub_old_version_create_subscription_with_exactly_once_delivery = PubsubCreateSubscriptionWithExactlyOnceDelivery.new - pubsub_old_version_create_subscription_with_exactly_once_delivery.create_subscription_with_exactly_once_delivery( - project_id: project_id, - topic_id: topic_id, - subscription_id: subscription_id - ) - end -end - -if $PROGRAM_NAME == __FILE__ - PubsubCreateSubscriptionWithExactlyOnceDelivery.run -end -# [END pubsub_old_version_create_subscription_with_exactly_once_delivery] diff --git a/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_filter.rb b/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_filter.rb deleted file mode 100644 index c67290ff86e8..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_subscription_with_filter.rb +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START pubsub_old_version_create_subscription_with_filter] -require "google/cloud/pubsub" - -# Shows how to create a new subscription with filter for a given topic -class PubsubCreateSubscriptionWithFilter - def create_subscription_with_filter project_id:, topic_id:, subscription_id:, filter: - pubsub = Google::Cloud::Pubsub.new project_id: project_id - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id, filter: filter - puts "Created subscription with filtering enabled: #{subscription_id}" - end - - def self.run - # TODO(developer): Replace these variables before running the sample. - project_id = "your-project-id" - topic_id = "your-topic-id" - subscription_id = "id-for-new-subcription" - filter = "attributes.author=\"unknown\"" - PubsubCreateSubscriptionWithFilter.new.create_subscription_with_filter project_id: project_id, - topic_id: topic_id, - subscription_id: subscription_id, - filter: filter - end -end - -if $PROGRAM_NAME == __FILE__ - PubsubCreateSubscriptionWithFilter.run -end -# [END pubsub_old_version_create_subscription_with_filter] diff --git a/google-cloud-pubsub/v2samples/pubsub_create_topic.rb b/google-cloud-pubsub/v2samples/pubsub_create_topic.rb deleted file mode 100644 index 6d35784e09a8..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_topic.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_topic topic_id: - # [START pubsub_old_version_create_topic] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.create_topic topic_id - - puts "Topic #{topic.name} created." - # [END pubsub_old_version_create_topic] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_create_topic_with_schema.rb b/google-cloud-pubsub/v2samples/pubsub_create_topic_with_schema.rb deleted file mode 100644 index 1e06a2b341b3..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_create_topic_with_schema.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def create_topic_with_schema topic_id:, schema_id:, message_encoding: - # [START pubsub_old_version_create_topic_with_schema] - # topic_id = "your-topic-id" - # schema_id = "your-schema-id" - # Choose either BINARY or JSON as valid message encoding in this topic. - # message_encoding = :binary - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.create_topic topic_id, schema_name: schema_id, message_encoding: message_encoding - - puts "Topic #{topic.name} created." - # [END pubsub_old_version_create_topic_with_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_dead_letter_create_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_dead_letter_create_subscription.rb deleted file mode 100644 index 0a052fac49e0..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_dead_letter_create_subscription.rb +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def dead_letter_create_subscription topic_id:, subscription_id:, dead_letter_topic_id: - # [START pubsub_old_version_dead_letter_create_subscription] - # topic_id = "your-topic-id" - # subscription_id = "your-subscription-id" - # dead_letter_topic_id = "your-dead-letter-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - dead_letter_topic = pubsub.topic dead_letter_topic_id - subscription = topic.subscribe subscription_id, - dead_letter_topic: dead_letter_topic, - dead_letter_max_delivery_attempts: 10 - - puts "Created subscription #{subscription_id} with dead letter topic #{dead_letter_topic_id}." - puts "To process dead letter messages, remember to add a subscription to your dead letter topic." - # [END pubsub_old_version_dead_letter_create_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_dead_letter_delivery_attempt.rb b/google-cloud-pubsub/v2samples/pubsub_dead_letter_delivery_attempt.rb deleted file mode 100644 index 60c9490e7c0d..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_dead_letter_delivery_attempt.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def dead_letter_delivery_attempt subscription_id: - # [START pubsub_old_version_dead_letter_delivery_attempt] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.pull(immediate: false).each do |message| - puts "Received message: #{message.data}" - puts "Delivery Attempt: #{message.delivery_attempt}" - message.acknowledge! - end - # [END pubsub_old_version_dead_letter_delivery_attempt] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_dead_letter_remove.rb b/google-cloud-pubsub/v2samples/pubsub_dead_letter_remove.rb deleted file mode 100644 index 8f57e5eaf9ea..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_dead_letter_remove.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def dead_letter_remove subscription_id: - # [START pubsub_old_version_dead_letter_remove] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.remove_dead_letter_policy - puts "Removed dead letter topic from #{subscription_id} subscription." - # [END pubsub_old_version_dead_letter_remove] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_dead_letter_update_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_dead_letter_update_subscription.rb deleted file mode 100644 index 499234940949..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_dead_letter_update_subscription.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def dead_letter_update_subscription subscription_id: - # [START pubsub_old_version_dead_letter_update_subscription] - # subscription_id = "your-subscription-id" - # role = "roles/pubsub.publisher" - # service_account_email = "serviceAccount:account_name@project_name.iam.gserviceaccount.com" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.dead_letter_max_delivery_attempts = 20 - puts "Max delivery attempts is now #{subscription.dead_letter_max_delivery_attempts}." - # [END pubsub_old_version_dead_letter_update_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_delete_schema.rb b/google-cloud-pubsub/v2samples/pubsub_delete_schema.rb deleted file mode 100644 index bd53579a47bd..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_delete_schema.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def delete_schema schema_id: - # [START pubsub_old_version_delete_schema] - # schema_id = "your-schema-id" - - pubsub = Google::Cloud::Pubsub.new - - schema = pubsub.schema schema_id - schema.delete - - puts "Schema #{schema_id} deleted." - # [END pubsub_old_version_delete_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_delete_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_delete_subscription.rb deleted file mode 100644 index 28e750ce9130..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_delete_subscription.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def delete_subscription subscription_id: - # [START pubsub_old_version_delete_subscription] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.delete - - puts "Subscription #{subscription_id} deleted." - # [END pubsub_old_version_delete_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_delete_topic.rb b/google-cloud-pubsub/v2samples/pubsub_delete_topic.rb deleted file mode 100644 index d4c8cd361729..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_delete_topic.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def delete_topic topic_id: - # [START pubsub_old_version_delete_topic] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - topic.delete - - puts "Topic #{topic_id} deleted." - # [END pubsub_old_version_delete_topic] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_detach_subscription.rb b/google-cloud-pubsub/v2samples/pubsub_detach_subscription.rb deleted file mode 100644 index d1b561739d2a..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_detach_subscription.rb +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def detach_subscription subscription_id: - # [START pubsub_old_version_detach_subscription] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.detach - - sleep 120 - subscription.reload! - if subscription.detached? - puts "Subscription is detached." - else - puts "Subscription is NOT detached." - end - # [END pubsub_old_version_detach_subscription] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_enable_subscription_ordering.rb b/google-cloud-pubsub/v2samples/pubsub_enable_subscription_ordering.rb deleted file mode 100644 index d4acb9c1655a..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_enable_subscription_ordering.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def enable_subscription_ordering topic_id:, subscription_id: - # [START pubsub_old_version_enable_subscription_ordering] - # topic_id = "your-topic-id" - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - subscription = topic.subscribe subscription_id, - message_ordering: true - - puts "Pull subscription #{subscription_id} created with message ordering." - # [END pubsub_old_version_enable_subscription_ordering] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_get_schema.rb b/google-cloud-pubsub/v2samples/pubsub_get_schema.rb deleted file mode 100644 index 7af0361e8420..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_get_schema.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def get_schema schema_id: - # [START pubsub_old_version_get_schema] - # schema_id = "your-schema-id" - - pubsub = Google::Cloud::Pubsub.new - - schema = pubsub.schema schema_id - - puts "Schema #{schema.name} retrieved." - # [END pubsub_old_version_get_schema] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_get_subscription_policy.rb b/google-cloud-pubsub/v2samples/pubsub_get_subscription_policy.rb deleted file mode 100644 index c901313de840..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_get_subscription_policy.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def get_subscription_policy subscription_id: - # [START pubsub_old_version_get_subscription_policy] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - policy = subscription.policy - - puts "Subscription policy:" - puts policy.roles - # [END pubsub_old_version_get_subscription_policy] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_get_topic_policy.rb b/google-cloud-pubsub/v2samples/pubsub_get_topic_policy.rb deleted file mode 100644 index 3861fcbb88bf..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_get_topic_policy.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def get_topic_policy topic_id: - # [START pubsub_old_version_get_topic_policy] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - policy = topic.policy - - puts "Topic policy:" - puts policy.roles - # [END pubsub_old_version_get_topic_policy] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_list_schema_revisions.rb b/google-cloud-pubsub/v2samples/pubsub_list_schema_revisions.rb deleted file mode 100644 index ef34aff59a01..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_list_schema_revisions.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2025 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. - -require "google/cloud/pubsub" - -def list_schema_revisions schema_id: - # [START pubsub_old_version_list_schema_revisions] - # schema_id = "your-schema-id" - - pubsub = Google::Cloud::Pubsub.new - - schema = pubsub.schema schema_id - - response = schema.list_revisions - - puts "Listed revisions of schema #{schema_id}" - response.each do |revision_schema| - puts revision_schema.revision_id - end - # [END pubsub_old_version_list_schema_revisions] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_list_schemas.rb b/google-cloud-pubsub/v2samples/pubsub_list_schemas.rb deleted file mode 100644 index a156d420600f..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_list_schemas.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def list_schemas - # [START pubsub_old_version_list_schemas] - - pubsub = Google::Cloud::Pubsub.new - - schemas = pubsub.schemas - - puts "Schemas in project:" - schemas.each do |schema| - puts schema.name - end - # [END pubsub_old_version_list_schemas] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_list_subscriptions.rb b/google-cloud-pubsub/v2samples/pubsub_list_subscriptions.rb deleted file mode 100644 index bc9bd130cc82..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_list_subscriptions.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def list_subscriptions - # [START pubsub_old_version_list_subscriptions] - - pubsub = Google::Cloud::Pubsub.new - - subscriptions = pubsub.list_subscriptions - - puts "Subscriptions:" - subscriptions.each do |subscription| - puts subscription.name - end - # [END pubsub_old_version_list_subscriptions] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_list_topic_subscriptions.rb b/google-cloud-pubsub/v2samples/pubsub_list_topic_subscriptions.rb deleted file mode 100644 index 31ae3dae2322..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_list_topic_subscriptions.rb +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def list_topic_subscriptions topic_id: - # [START pubsub_old_version_list_topic_subscriptions] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - subscriptions = topic.subscriptions - - puts "Subscriptions in topic #{topic.name}:" - subscriptions.each do |subscription| - puts subscription.name - end - # [END pubsub_old_version_list_topic_subscriptions] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_list_topics.rb b/google-cloud-pubsub/v2samples/pubsub_list_topics.rb deleted file mode 100644 index 27a6531ec355..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_list_topics.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def list_topics - # [START pubsub_old_version_list_topics] - - pubsub = Google::Cloud::Pubsub.new - - topics = pubsub.topics - - puts "Topics in project:" - topics.each do |topic| - puts topic.name - end - # [END pubsub_old_version_list_topics] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish.rb b/google-cloud-pubsub/v2samples/pubsub_publish.rb deleted file mode 100644 index ae9321f74c8c..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_message_async topic_id: - # [START pubsub_old_version_publish] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - topic.publish_async "This is a test message." do |result| - raise "Failed to publish the message." unless result.succeeded? - puts "Message published asynchronously." - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - # [END pubsub_old_version_publish] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish_avro_records.rb b/google-cloud-pubsub/v2samples/pubsub_publish_avro_records.rb deleted file mode 100644 index 668721d16f84..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish_avro_records.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_avro_records topic_id:, avsc_file: - # [START pubsub_old_version_publish_avro_records] - # topic_id = "your-topic-id" - # avsc_file = "path/to/an/avro/schema/file/(.avsc)/formatted/in/json" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - - record = { "name" => "Alaska", "post_abbr" => "AK" } - - if topic.message_encoding_binary? - require "avro" - avro_schema = Avro::Schema.parse File.read(avsc_file) - writer = Avro::IO::DatumWriter.new avro_schema - buffer = StringIO.new - encoder = Avro::IO::BinaryEncoder.new buffer - writer.write record, encoder - topic.publish buffer - puts "Published binary-encoded AVRO message." - elsif topic.message_encoding_json? - require "json" - topic.publish record.to_json - puts "Published JSON-encoded AVRO message." - else - raise "No encoding specified in #{topic.name}." - end - # [END pubsub_old_version_publish_avro_records] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish_custom_attributes.rb b/google-cloud-pubsub/v2samples/pubsub_publish_custom_attributes.rb deleted file mode 100644 index 7b47ee5b2cfc..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish_custom_attributes.rb +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_message_async_with_custom_attributes topic_id: - # [START pubsub_old_version_publish_custom_attributes] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - # Add two attributes, origin and username, to the message - topic.publish_async "This is a test message.", - origin: "ruby-sample", - username: "gcp" do |result| - raise "Failed to publish the message." unless result.succeeded? - puts "Message with custom attributes published asynchronously." - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - # [END pubsub_old_version_publish_custom_attributes] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish_proto_messages.rb b/google-cloud-pubsub/v2samples/pubsub_publish_proto_messages.rb deleted file mode 100644 index e16b4d50816c..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish_proto_messages.rb +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" -require_relative "utilities/us-states_pb" - -def publish_proto_messages topic_id: - # [START pubsub_old_version_publish_proto_messages] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - - state = Utilities::StateProto.new name: "Alaska", post_abbr: "AK" - - if topic.message_encoding_binary? - topic.publish Utilities::StateProto.encode(state) - puts "Published binary-encoded protobuf message." - elsif topic.message_encoding_json? - topic.publish Utilities::StateProto.encode_json(state) - puts "Published JSON-encoded protobuf message." - else - raise "No encoding specified in #{topic.name}." - end - # [END pubsub_old_version_publish_proto_messages] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish_with_error_handler.rb b/google-cloud-pubsub/v2samples/pubsub_publish_with_error_handler.rb deleted file mode 100644 index cd244e9d88f7..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish_with_error_handler.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_with_error_handler topic_id: - # [START pubsub_old_version_publish_with_error_handler] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - - begin - topic.publish_async "This is a test message." do |result| - raise "Failed to publish the message." unless result.succeeded? - puts "Message published asynchronously." - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - rescue StandardError => e - puts "Received error while publishing: #{e.message}" - end - # [END pubsub_old_version_publish_with_error_handler] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publish_with_ordering_keys.rb b/google-cloud-pubsub/v2samples/pubsub_publish_with_ordering_keys.rb deleted file mode 100644 index ab24878db1b1..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publish_with_ordering_keys.rb +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_ordered_messages topic_id: - # [START pubsub_old_version_publish_with_ordering_keys] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new endpoint: "us-east1-pubsub.googleapis.com:443" - - # Start sending messages in one request once the size of all queued messages - # reaches 1 MB or the number of queued messages reaches 20 - topic = pubsub.topic topic_id, async: { - max_bytes: 1_000_000, - max_messages: 20 - } - topic.enable_message_ordering! - 10.times do |i| - topic.publish_async "This is message ##{i}.", - ordering_key: "ordering-key" - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop! - puts "Messages published with ordering key." - # [END pubsub_old_version_publish_with_ordering_keys] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publisher_batch_settings.rb b/google-cloud-pubsub/v2samples/pubsub_publisher_batch_settings.rb deleted file mode 100644 index 9e0fc32ed406..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publisher_batch_settings.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_messages_async_with_batch_settings topic_id: - # [START pubsub_old_version_publisher_batch_settings] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - # Start sending messages in one request once the size of all queued messages - # reaches 1 MB or the number of queued messages reaches 20 - topic = pubsub.topic topic_id, async: { - max_bytes: 1_000_000, - max_messages: 20 - } - 10.times do |i| - topic.publish_async "This is message ##{i}." - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - puts "Messages published asynchronously in batch." - # [END pubsub_old_version_publisher_batch_settings] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publisher_concurrency_control.rb b/google-cloud-pubsub/v2samples/pubsub_publisher_concurrency_control.rb deleted file mode 100644 index bb6bff72cd6a..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publisher_concurrency_control.rb +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_messages_async_with_concurrency_control topic_id: - # [START pubsub_old_version_publisher_concurrency_control] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id, async: { - threads: { - # Use exactly one thread for publishing message and exactly one thread - # for executing callbacks - publish: 1, - callback: 1 - } - } - topic.publish_async "This is a test message." do |result| - raise "Failed to publish the message." unless result.succeeded? - puts "Message published asynchronously." - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - # [END pubsub_old_version_publisher_concurrency_control] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publisher_flow_control.rb b/google-cloud-pubsub/v2samples/pubsub_publisher_flow_control.rb deleted file mode 100644 index 3ccfd6cbd2aa..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publisher_flow_control.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_messages_async_with_flow_control topic_id: - # [START pubsub_old_version_publisher_flow_control] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id, async: { - # Configure how many messages the publisher client can hold in memory - # and what to do when messages exceed the limit. - flow_control: { - message_limit: 100, - byte_limit: 10 * 1024 * 1024, # 10 MiB - # Block more messages from being published when the limit is reached. The - # other options are :ignore and :error. - limit_exceeded_behavior: :block - } - } - # Rapidly publishing 1000 messages in a loop may be constrained by flow control. - 1000.times do |i| - topic.publish_async "message #{i}" do |result| - raise "Failed to publish the message." unless result.succeeded? - end - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - puts "Published messages with flow control settings to #{topic_id}." - # [END pubsub_old_version_publisher_flow_control] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_publisher_with_compression.rb b/google-cloud-pubsub/v2samples/pubsub_publisher_with_compression.rb deleted file mode 100644 index 81fb3912a864..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_publisher_with_compression.rb +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2023 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. - -# [START pubsub_old_version_publisher_with_compression] -require "google/cloud/pubsub" - -## -# Shows how to create a BigQuery subscription where messages published -# to a topic populates a BigQuery table. -# -# @param project_id [String] -# Your Google Cloud project (e.g. "my-project") -# @param topic_id [String] -# Your topic name (e.g. "my-secret") -# -def pubsub_old_version_publisher_with_compression project_id:, topic_id: - pubsub = Google::Cloud::Pubsub.new project_id: project_id - - # Enable compression and configure the compression threshold to 10 bytes (default to 240 B). - # Publish requests of sizes > 10 B (excluding the request headers) will get compressed. - topic = pubsub.topic topic_id, async: { - compress: true, - compression_bytes_threshold: 10 - } - - begin - topic.publish_async "This is a test message." do |result| - raise "Failed to publish the message." unless result.succeeded? - puts "Published a compressed message of message ID: #{result.message_id}" - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop.wait! - rescue StandardError => e - puts "Received error while publishing: #{e.message}" - end -end -# [END pubsub_old_version_publisher_with_compression] diff --git a/google-cloud-pubsub/v2samples/pubsub_quickstart_publisher.rb b/google-cloud-pubsub/v2samples/pubsub_quickstart_publisher.rb deleted file mode 100644 index 98e9f9c6763f..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_quickstart_publisher.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_message topic_id: - # [START pubsub_old_version_quickstart_publisher] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - topic.publish "This is a test message." - - puts "Message published." - # [END pubsub_old_version_quickstart_publisher] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_resume_publish_with_ordering_keys.rb b/google-cloud-pubsub/v2samples/pubsub_resume_publish_with_ordering_keys.rb deleted file mode 100644 index 14985dbcf378..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_resume_publish_with_ordering_keys.rb +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def publish_resume_publish topic_id: - # [START pubsub_old_version_resume_publish_with_ordering_keys] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - # Start sending messages in one request once the size of all queued messages - # reaches 1 MB or the number of queued messages reaches 20 - topic = pubsub.topic topic_id, async: { - max_bytes: 1_000_000, - max_messages: 20 - } - topic.enable_message_ordering! - 10.times do |i| - topic.publish_async "This is message ##{i}.", - ordering_key: "ordering-key" do |result| - if result.succeeded? - puts "Message ##{i} successfully published." - else - puts "Message ##{i} failed to publish" - # Allow publishing to continue on "ordering-key" after processing the - # failure. - topic.resume_publish "ordering-key" - end - end - end - - # Stop the async_publisher to send all queued messages immediately. - topic.async_publisher.stop! - # [END pubsub_old_version_resume_publish_with_ordering_keys] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_set_subscription_policy.rb b/google-cloud-pubsub/v2samples/pubsub_set_subscription_policy.rb deleted file mode 100644 index f017fff8ecee..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_set_subscription_policy.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def set_subscription_policy subscription_id:, role:, service_account_email: - # [START pubsub_old_version_set_subscription_policy] - # subscription_id = "your-subscription-id" - # role = "roles/pubsub.publisher" - # service_account_email = "serviceAccount:account_name@project_name.iam.gserviceaccount.com" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.policy do |policy| - policy.add role, service_account_email - end - # [END pubsub_old_version_set_subscription_policy] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_set_topic_policy.rb b/google-cloud-pubsub/v2samples/pubsub_set_topic_policy.rb deleted file mode 100644 index 01402a1385e2..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_set_topic_policy.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def set_topic_policy topic_id:, role:, service_account_email: - # [START pubsub_old_version_set_topic_policy] - # topic_id = "your-topic-id" - # role = "roles/pubsub.publisher" - # service_account_email = "serviceAccount:account_name@project_name.iam.gserviceaccount.com" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - topic.policy do |policy| - policy.add role, service_account_email - end - # [END pubsub_old_version_set_topic_policy] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscribe_avro_records.rb b/google-cloud-pubsub/v2samples/pubsub_subscribe_avro_records.rb deleted file mode 100644 index 5a1a03c88ce0..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscribe_avro_records.rb +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def subscribe_avro_records subscription_id:, avsc_file: - # [START pubsub_old_version_subscribe_avro_records] - # subscription_id = "your-subscription-id" - # avsc_file = "path/to/an/avro/schema/file/(.avsc)/formatted/in/json" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - - subscriber = subscription.listen do |received_message| - encoding = received_message.attributes["googclient_schemaencoding"] - case encoding - when "BINARY" - require "avro" - avro_schema = Avro::Schema.parse File.read(avsc_file) - buffer = StringIO.new received_message.data - decoder = Avro::IO::BinaryDecoder.new buffer - reader = Avro::IO::DatumReader.new avro_schema - message_data = reader.read decoder - puts "Received a binary-encoded message:\n#{message_data}" - when "JSON" - require "json" - message_data = JSON.parse received_message.data - puts "Received a JSON-encoded message:\n#{message_data}" - else - "Received a message with no encoding:\n#{received_message.message_id}" - end - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscribe_avro_records] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscribe_proto_messages.rb b/google-cloud-pubsub/v2samples/pubsub_subscribe_proto_messages.rb deleted file mode 100644 index 09b1c8b9da87..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscribe_proto_messages.rb +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" -require_relative "utilities/us-states_pb" - -def subscribe_proto_messages subscription_id: - # [START pubsub_old_version_subscribe_proto_messages] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - - subscriber = subscription.listen do |received_message| - encoding = received_message.attributes["googclient_schemaencoding"] - case encoding - when "BINARY" - state = Utilities::StateProto.decode received_message.data - puts "Received a binary-encoded message:\n#{state}" - when "JSON" - require "json" - state = Utilities::StateProto.decode_json received_message.data - puts "Received a JSON-encoded message:\n#{state}" - else - "Received a message with no encoding:\n#{received_message.message_id}" - end - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscribe_proto_messages] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull.rb deleted file mode 100644 index 65b248c2472b..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def listen_for_messages subscription_id: - # [START pubsub_old_version_subscriber_async_pull] - # [START pubsub_old_version_quickstart_subscriber] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscriber = subscription.listen do |received_message| - puts "Received message: #{received_message.data}" - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscriber_async_pull] - # [END pubsub_old_version_quickstart_subscriber] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull_custom_attributes.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull_custom_attributes.rb deleted file mode 100644 index 8fc7e08bf43a..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_async_pull_custom_attributes.rb +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def listen_for_messages_with_custom_attributes subscription_id: - # [START pubsub_old_version_subscriber_async_pull_custom_attributes] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscriber = subscription.listen do |received_message| - puts "Received message: #{received_message.data}" - unless received_message.attributes.empty? - puts "Attributes:" - received_message.attributes.each do |key, value| - puts "#{key}: #{value}" - end - end - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscriber_async_pull_custom_attributes] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_concurrency_control.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_concurrency_control.rb deleted file mode 100644 index dec52e2a3db3..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_concurrency_control.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def listen_for_messages_with_concurrency_control subscription_id: - # [START pubsub_old_version_subscriber_concurrency_control] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - # Use 2 threads for streaming, 4 threads for executing callbacks and 2 threads - # for sending acknowledgements and/or delays - subscriber = subscription.listen streams: 2, threads: { - callback: 4, - push: 2 - } do |received_message| - puts "Received message: #{received_message.data}" - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscriber_concurrency_control] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_error_listener.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_error_listener.rb deleted file mode 100644 index bc8efeac4f0a..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_error_listener.rb +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def listen_for_messages_with_error_handler subscription_id: - # [START pubsub_old_version_subscriber_error_listener] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscriber = subscription.listen do |received_message| - puts "Received message: #{received_message.data}" - received_message.acknowledge! - end - # Propagate exception from child threads to the main thread as soon as it is - # raised. Exceptions happened in the callback thread are collected in the - # callback thread pool and do not propagate to the main thread - Thread.abort_on_exception = true - - begin - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - rescue StandardError => e - puts "Exception #{e.inspect}: #{e.message}" - raise "Stopped listening for messages." - end - # [END pubsub_old_version_subscriber_error_listener] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_exactly_once_delivery.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_exactly_once_delivery.rb deleted file mode 100644 index eb45cb4f5168..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_exactly_once_delivery.rb +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START pubsub_old_version_subscriber_exactly_once] -require "google/cloud/pubsub" - -# Shows how to register callback to acknowledge method and access the result passed in -class PubsubSubscriberExactlyOnceDelivery - def subscriber_exactly_once_delivery project_id:, topic_id:, subscription_id: - pubsub = Google::Cloud::Pubsub.new project_id: project_id - topic = pubsub.topic topic_id - subscription = pubsub.subscription subscription_id - subscriber = subscription.listen do |received_message| - puts "Received message: #{received_message.data}" - - # Pass in callback to access the acknowledge result. - # For subscription with Exactly once delivery disabled the result will be success always. - received_message.acknowledge! do |result| - puts "Acknowledge result's status: #{result.status}" - end - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - end - - def self.run - # TODO(developer): Replace these variables before running the sample. - project_id = "your-project-id" - topic_id = "your-topic-id" - subscription_id = "id-for-new-subcription" # subscription with exactly once delivery enabled - PubsubSubscriberExactlyOnceDelivery.new.subscriber_exactly_once_delivery project_id: project_id, - topic_id: topic_id, - subscription_id: subscription_id - end -end - -if $PROGRAM_NAME == __FILE__ - PubsubSubscriberExactlyOnceDelivery.run -end -# [END pubsub_old_version_subscriber_exactly_once] diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_flow_settings.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_flow_settings.rb deleted file mode 100644 index 059d5ed6c1db..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_flow_settings.rb +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def listen_for_messages_with_flow_control subscription_id: - # [START pubsub_old_version_subscriber_flow_settings] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscriber = subscription.listen inventory: 10 do |received_message| - puts "Received message: #{received_message.data}" - received_message.acknowledge! - end - - subscriber.start - # Let the main thread sleep for 60 seconds so the thread for listening - # messages does not quit - sleep 60 - subscriber.stop.wait! - # [END pubsub_old_version_subscriber_flow_settings] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull.rb deleted file mode 100644 index 17e84282fe24..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def pull_messages subscription_id: - # [START pubsub_old_version_subscriber_sync_pull] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.pull(immediate: false).each do |message| - puts "Message pulled: #{message.data}" - message.acknowledge! - end - # [END pubsub_old_version_subscriber_sync_pull] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull_with_lease.rb b/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull_with_lease.rb deleted file mode 100644 index d028ced85e00..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_subscriber_sync_pull_with_lease.rb +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def subscriber_sync_pull_with_lease subscription_id: - # [START pubsub_old_version_subscriber_sync_pull_with_lease] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - new_ack_deadline = 30 - processed = false - - # The subscriber pulls a specified number of messages. - received_messages = subscription.pull immediate: false, max: 1 - - # Obtain the first message. - message = received_messages.first - - # Send the message to a non-blocking worker that starts a long-running process, such as writing - # the message to a table, which may take longer than the default 10-sec acknowledge deadline. - Thread.new do - sleep 15 - processed = true - puts "Finished processing \"#{message.data}\"." - end - - loop do - sleep 1 - if processed - # If the message has been processed, acknowledge the message. - message.acknowledge! - puts "Done." - # Exit after the message is acknowledged. - break - else - # If the message has not yet been processed, reset its ack deadline. - message.modify_ack_deadline! new_ack_deadline - puts "Reset ack deadline for \"#{message.data}\" for #{new_ack_deadline} seconds." - end - end - # [END pubsub_old_version_subscriber_sync_pull_with_lease] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_test_subscription_permissions.rb b/google-cloud-pubsub/v2samples/pubsub_test_subscription_permissions.rb deleted file mode 100644 index 4e157b908d70..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_test_subscription_permissions.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def test_subscription_permissions subscription_id: - # [START pubsub_old_version_test_subscription_permissions] - # subscription_id = "your-subscription-id" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - permissions = subscription.test_permissions "pubsub.subscriptions.consume", - "pubsub.subscriptions.update" - - puts "Permission to consume" if permissions.include? "pubsub.subscriptions.consume" - puts "Permission to update" if permissions.include? "pubsub.subscriptions.update" - # [END pubsub_old_version_test_subscription_permissions] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_test_topic_permissions.rb b/google-cloud-pubsub/v2samples/pubsub_test_topic_permissions.rb deleted file mode 100644 index f95686ba89e6..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_test_topic_permissions.rb +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def test_topic_permissions topic_id: - # [START pubsub_old_version_test_topic_permissions] - # topic_id = "your-topic-id" - - pubsub = Google::Cloud::Pubsub.new - - topic = pubsub.topic topic_id - permissions = topic.test_permissions "pubsub.topics.attachSubscription", - "pubsub.topics.publish", "pubsub.topics.update" - - puts "Permission to attach subscription" if permissions.include? "pubsub.topics.attachSubscription" - puts "Permission to publish" if permissions.include? "pubsub.topics.publish" - puts "Permission to update" if permissions.include? "pubsub.topics.update" - # [END pubsub_old_version_test_topic_permissions] -end diff --git a/google-cloud-pubsub/v2samples/pubsub_update_push_configuration.rb b/google-cloud-pubsub/v2samples/pubsub_update_push_configuration.rb deleted file mode 100644 index ff4fcbcae3fe..000000000000 --- a/google-cloud-pubsub/v2samples/pubsub_update_push_configuration.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2023 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. - -require "google/cloud/pubsub" - -def update_push_configuration subscription_id:, new_endpoint: - # [START pubsub_old_version_update_push_configuration] - # subscription_id = "your-subscription-id" - # new_endpoint = "Endpoint where your app receives messages"" - - pubsub = Google::Cloud::Pubsub.new - - subscription = pubsub.subscription subscription_id - subscription.endpoint = new_endpoint - - puts "Push endpoint updated." - # [END pubsub_old_version_update_push_configuration] -end diff --git a/google-cloud-pubsub/v2samples/quickstart.rb b/google-cloud-pubsub/v2samples/quickstart.rb deleted file mode 100644 index b0ba3378cbd6..000000000000 --- a/google-cloud-pubsub/v2samples/quickstart.rb +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2021 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. - -def quickstart topic_id: - # [START pubsub_old_version_quickstart_create_topic] - # [START require_library] - # Imports the Google Cloud client library - require "google/cloud/pubsub" - # [END require_library] - - # Instantiates a client - pubsub = Google::Cloud::Pubsub.new - - # The name for the new topic - # topic_id = "your-topic-id" - - # Creates the new topic - topic = pubsub.create_topic topic_id - - puts "Topic #{topic.name} created." - # [END pubsub_old_version_quickstart_create_topic] -end - -quickstart topic_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-pubsub/v2samples/utilities/us-states_pb.rb b/google-cloud-pubsub/v2samples/utilities/us-states_pb.rb deleted file mode 100644 index 4208b93686c0..000000000000 --- a/google-cloud-pubsub/v2samples/utilities/us-states_pb.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: us-states.proto - -require 'google/protobuf' - - -descriptor_data = "\n\x0fus-states.proto\x12\tutilities\"-\n\nStateProto\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\tpost_abbr\x18\x02 \x01(\tb\x06proto3" - -pool = Google::Protobuf::DescriptorPool.generated_pool -pool.add_serialized_file(descriptor_data) - -module Utilities - StateProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("utilities.StateProto").msgclass -end