google-cloud-pubsub 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +18 -0
  3. data/AUTHENTICATION.md +177 -0
  4. data/CHANGELOG.md +538 -0
  5. data/CODE_OF_CONDUCT.md +40 -0
  6. data/CONTRIBUTING.md +188 -0
  7. data/EMULATOR.md +37 -0
  8. data/LICENSE +201 -0
  9. data/LOGGING.md +32 -0
  10. data/OVERVIEW.md +557 -0
  11. data/TROUBLESHOOTING.md +31 -0
  12. data/lib/google-cloud-pubsub.rb +139 -0
  13. data/lib/google/cloud/pubsub.rb +173 -0
  14. data/lib/google/cloud/pubsub/async_publisher.rb +399 -0
  15. data/lib/google/cloud/pubsub/async_publisher/batch.rb +309 -0
  16. data/lib/google/cloud/pubsub/batch_publisher.rb +99 -0
  17. data/lib/google/cloud/pubsub/convert.rb +91 -0
  18. data/lib/google/cloud/pubsub/credentials.rb +47 -0
  19. data/lib/google/cloud/pubsub/errors.rb +85 -0
  20. data/lib/google/cloud/pubsub/message.rb +158 -0
  21. data/lib/google/cloud/pubsub/policy.rb +187 -0
  22. data/lib/google/cloud/pubsub/project.rb +393 -0
  23. data/lib/google/cloud/pubsub/publish_result.rb +103 -0
  24. data/lib/google/cloud/pubsub/received_message.rb +297 -0
  25. data/lib/google/cloud/pubsub/retry_policy.rb +90 -0
  26. data/lib/google/cloud/pubsub/service.rb +514 -0
  27. data/lib/google/cloud/pubsub/snapshot.rb +202 -0
  28. data/lib/google/cloud/pubsub/snapshot/list.rb +178 -0
  29. data/lib/google/cloud/pubsub/subscriber.rb +399 -0
  30. data/lib/google/cloud/pubsub/subscriber/enumerator_queue.rb +54 -0
  31. data/lib/google/cloud/pubsub/subscriber/inventory.rb +166 -0
  32. data/lib/google/cloud/pubsub/subscriber/sequencer.rb +115 -0
  33. data/lib/google/cloud/pubsub/subscriber/stream.rb +401 -0
  34. data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +231 -0
  35. data/lib/google/cloud/pubsub/subscription.rb +1279 -0
  36. data/lib/google/cloud/pubsub/subscription/list.rb +205 -0
  37. data/lib/google/cloud/pubsub/subscription/push_config.rb +244 -0
  38. data/lib/google/cloud/pubsub/topic.rb +934 -0
  39. data/lib/google/cloud/pubsub/topic/list.rb +171 -0
  40. data/lib/google/cloud/pubsub/v1.rb +17 -0
  41. data/lib/google/cloud/pubsub/v1/credentials.rb +41 -0
  42. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +21 -0
  43. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +21 -0
  44. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +21 -0
  45. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +91 -0
  46. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +29 -0
  47. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +222 -0
  48. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +113 -0
  49. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +833 -0
  50. data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +19 -0
  51. data/lib/google/cloud/pubsub/v1/publisher_client.rb +928 -0
  52. data/lib/google/cloud/pubsub/v1/publisher_client_config.json +120 -0
  53. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +1466 -0
  54. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +153 -0
  55. data/lib/google/cloud/pubsub/version.rb +24 -0
  56. data/lib/google/pubsub/v1/pubsub_pb.rb +269 -0
  57. data/lib/google/pubsub/v1/pubsub_services_pb.rb +215 -0
  58. metadata +337 -0
@@ -0,0 +1,19 @@
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Type
18
+ end
19
+ end
@@ -0,0 +1,928 @@
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/pubsub/v1/pubsub.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+
22
+
23
+ require "json"
24
+ require "pathname"
25
+
26
+ require "google/gax"
27
+
28
+ require "google/iam/v1/iam_policy_pb"
29
+ require "google/pubsub/v1/pubsub_pb"
30
+ require "google/cloud/pubsub/v1/credentials"
31
+ require "google/cloud/pubsub/version"
32
+
33
+ module Google
34
+ module Cloud
35
+ module PubSub
36
+ module V1
37
+ # The service that an application uses to manipulate topics, and to send
38
+ # messages to a topic.
39
+ #
40
+ # @!attribute [r] iam_policy_stub
41
+ # @return [Google::Iam::V1::IAMPolicy::Stub]
42
+ # @!attribute [r] publisher_stub
43
+ # @return [Google::Cloud::PubSub::V1::Publisher::Stub]
44
+ class PublisherClient
45
+ # @private
46
+ attr_reader :iam_policy_stub, :publisher_stub
47
+
48
+ # The default address of the service.
49
+ SERVICE_ADDRESS = "pubsub.googleapis.com".freeze
50
+
51
+ # The default port of the service.
52
+ DEFAULT_SERVICE_PORT = 443
53
+
54
+ # The default set of gRPC interceptors.
55
+ GRPC_INTERCEPTORS = []
56
+
57
+ DEFAULT_TIMEOUT = 30
58
+
59
+ PAGE_DESCRIPTORS = {
60
+ "list_topics" => Google::Gax::PageDescriptor.new(
61
+ "page_token",
62
+ "next_page_token",
63
+ "topics"),
64
+ "list_topic_subscriptions" => Google::Gax::PageDescriptor.new(
65
+ "page_token",
66
+ "next_page_token",
67
+ "subscriptions"),
68
+ "list_topic_snapshots" => Google::Gax::PageDescriptor.new(
69
+ "page_token",
70
+ "next_page_token",
71
+ "snapshots")
72
+ }.freeze
73
+
74
+ private_constant :PAGE_DESCRIPTORS
75
+
76
+ BUNDLE_DESCRIPTORS = {
77
+ "publish" => Google::Gax::BundleDescriptor.new(
78
+ "messages",
79
+ [
80
+ "topic"
81
+ ],
82
+ subresponse_field: "message_ids")
83
+ }.freeze
84
+
85
+ private_constant :BUNDLE_DESCRIPTORS
86
+
87
+ # The scopes needed to make gRPC calls to all of the methods defined in
88
+ # this service.
89
+ ALL_SCOPES = [
90
+ "https://www.googleapis.com/auth/cloud-platform",
91
+ "https://www.googleapis.com/auth/pubsub"
92
+ ].freeze
93
+
94
+
95
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
96
+ "projects/{project}"
97
+ )
98
+
99
+ private_constant :PROJECT_PATH_TEMPLATE
100
+
101
+ SUBSCRIPTION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
102
+ "projects/{project}/subscriptions/{subscription}"
103
+ )
104
+
105
+ private_constant :SUBSCRIPTION_PATH_TEMPLATE
106
+
107
+ TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
108
+ "projects/{project}/topics/{topic}"
109
+ )
110
+
111
+ private_constant :TOPIC_PATH_TEMPLATE
112
+
113
+ # Returns a fully-qualified project resource name string.
114
+ # @param project [String]
115
+ # @return [String]
116
+ def self.project_path project
117
+ PROJECT_PATH_TEMPLATE.render(
118
+ :"project" => project
119
+ )
120
+ end
121
+
122
+ # Returns a fully-qualified subscription resource name string.
123
+ # @param project [String]
124
+ # @param subscription [String]
125
+ # @return [String]
126
+ def self.subscription_path project, subscription
127
+ SUBSCRIPTION_PATH_TEMPLATE.render(
128
+ :"project" => project,
129
+ :"subscription" => subscription
130
+ )
131
+ end
132
+
133
+ # Returns a fully-qualified topic resource name string.
134
+ # @param project [String]
135
+ # @param topic [String]
136
+ # @return [String]
137
+ def self.topic_path project, topic
138
+ TOPIC_PATH_TEMPLATE.render(
139
+ :"project" => project,
140
+ :"topic" => topic
141
+ )
142
+ end
143
+
144
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
145
+ # Provides the means for authenticating requests made by the client. This parameter can
146
+ # be many types.
147
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
148
+ # authenticating requests made by this client.
149
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
150
+ # credentials for this client.
151
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
152
+ # credentials for this client.
153
+ # A `GRPC::Core::Channel` will be used to make calls through.
154
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
155
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
156
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
157
+ # metadata for requests, generally, to give OAuth credentials.
158
+ # @param scopes [Array<String>]
159
+ # The OAuth scopes for this service. This parameter is ignored if
160
+ # an updater_proc is supplied.
161
+ # @param client_config [Hash]
162
+ # A Hash for call options for each method. See
163
+ # Google::Gax#construct_settings for the structure of
164
+ # this data. Falls back to the default config if not specified
165
+ # or the specified config is missing data points.
166
+ # @param timeout [Numeric]
167
+ # The default timeout, in seconds, for calls made through this client.
168
+ # @param metadata [Hash]
169
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
170
+ # @param service_address [String]
171
+ # Override for the service hostname, or `nil` to leave as the default.
172
+ # @param service_port [Integer]
173
+ # Override for the service port, or `nil` to leave as the default.
174
+ # @param exception_transformer [Proc]
175
+ # An optional proc that intercepts any exceptions raised during an API call to inject
176
+ # custom error handling.
177
+ def initialize \
178
+ credentials: nil,
179
+ scopes: ALL_SCOPES,
180
+ client_config: {},
181
+ timeout: DEFAULT_TIMEOUT,
182
+ metadata: nil,
183
+ service_address: nil,
184
+ service_port: nil,
185
+ exception_transformer: nil,
186
+ lib_name: nil,
187
+ lib_version: ""
188
+ # These require statements are intentionally placed here to initialize
189
+ # the gRPC module only when it's required.
190
+ # See https://github.com/googleapis/toolkit/issues/446
191
+ require "google/gax/grpc"
192
+ require "google/iam/v1/iam_policy_services_pb"
193
+ require "google/pubsub/v1/pubsub_services_pb"
194
+
195
+ credentials ||= Google::Cloud::PubSub::V1::Credentials.default
196
+
197
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
198
+ updater_proc = Google::Cloud::PubSub::V1::Credentials.new(credentials).updater_proc
199
+ end
200
+ if credentials.is_a?(GRPC::Core::Channel)
201
+ channel = credentials
202
+ end
203
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
204
+ chan_creds = credentials
205
+ end
206
+ if credentials.is_a?(Proc)
207
+ updater_proc = credentials
208
+ end
209
+ if credentials.is_a?(Google::Auth::Credentials)
210
+ updater_proc = credentials.updater_proc
211
+ end
212
+
213
+ package_version = Google::Cloud::PubSub::VERSION
214
+
215
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
216
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
217
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
218
+ google_api_client << " grpc/#{GRPC::VERSION}"
219
+ google_api_client.freeze
220
+
221
+ headers = { :"x-goog-api-client" => google_api_client }
222
+ if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
223
+ headers[:"x-goog-user-project"] = credentials.quota_project_id
224
+ end
225
+ headers.merge!(metadata) unless metadata.nil?
226
+ client_config_file = Pathname.new(__dir__).join(
227
+ "publisher_client_config.json"
228
+ )
229
+ defaults = client_config_file.open do |f|
230
+ Google::Gax.construct_settings(
231
+ "google.pubsub.v1.Publisher",
232
+ JSON.parse(f.read),
233
+ client_config,
234
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
235
+ timeout,
236
+ bundle_descriptors: BUNDLE_DESCRIPTORS,
237
+ page_descriptors: PAGE_DESCRIPTORS,
238
+ errors: Google::Gax::Grpc::API_ERRORS,
239
+ metadata: headers
240
+ )
241
+ end
242
+
243
+ # Allow overriding the service path/port in subclasses.
244
+ service_path = service_address || self.class::SERVICE_ADDRESS
245
+ port = service_port || self.class::DEFAULT_SERVICE_PORT
246
+ interceptors = self.class::GRPC_INTERCEPTORS
247
+ @iam_policy_stub = Google::Gax::Grpc.create_stub(
248
+ service_path,
249
+ port,
250
+ chan_creds: chan_creds,
251
+ channel: channel,
252
+ updater_proc: updater_proc,
253
+ scopes: scopes,
254
+ interceptors: interceptors,
255
+ &Google::Iam::V1::IAMPolicy::Stub.method(:new)
256
+ )
257
+ @publisher_stub = Google::Gax::Grpc.create_stub(
258
+ service_path,
259
+ port,
260
+ chan_creds: chan_creds,
261
+ channel: channel,
262
+ updater_proc: updater_proc,
263
+ scopes: scopes,
264
+ interceptors: interceptors,
265
+ &Google::Cloud::PubSub::V1::Publisher::Stub.method(:new)
266
+ )
267
+
268
+ @create_topic = Google::Gax.create_api_call(
269
+ @publisher_stub.method(:create_topic),
270
+ defaults["create_topic"],
271
+ exception_transformer: exception_transformer,
272
+ params_extractor: proc do |request|
273
+ {'name' => request.name}
274
+ end
275
+ )
276
+ @update_topic = Google::Gax.create_api_call(
277
+ @publisher_stub.method(:update_topic),
278
+ defaults["update_topic"],
279
+ exception_transformer: exception_transformer,
280
+ params_extractor: proc do |request|
281
+ {'topic.name' => request.topic.name}
282
+ end
283
+ )
284
+ @publish = Google::Gax.create_api_call(
285
+ @publisher_stub.method(:publish),
286
+ defaults["publish"],
287
+ exception_transformer: exception_transformer,
288
+ params_extractor: proc do |request|
289
+ {'topic' => request.topic}
290
+ end
291
+ )
292
+ @get_topic = Google::Gax.create_api_call(
293
+ @publisher_stub.method(:get_topic),
294
+ defaults["get_topic"],
295
+ exception_transformer: exception_transformer,
296
+ params_extractor: proc do |request|
297
+ {'topic' => request.topic}
298
+ end
299
+ )
300
+ @list_topics = Google::Gax.create_api_call(
301
+ @publisher_stub.method(:list_topics),
302
+ defaults["list_topics"],
303
+ exception_transformer: exception_transformer,
304
+ params_extractor: proc do |request|
305
+ {'project' => request.project}
306
+ end
307
+ )
308
+ @list_topic_subscriptions = Google::Gax.create_api_call(
309
+ @publisher_stub.method(:list_topic_subscriptions),
310
+ defaults["list_topic_subscriptions"],
311
+ exception_transformer: exception_transformer,
312
+ params_extractor: proc do |request|
313
+ {'topic' => request.topic}
314
+ end
315
+ )
316
+ @list_topic_snapshots = Google::Gax.create_api_call(
317
+ @publisher_stub.method(:list_topic_snapshots),
318
+ defaults["list_topic_snapshots"],
319
+ exception_transformer: exception_transformer,
320
+ params_extractor: proc do |request|
321
+ {'topic' => request.topic}
322
+ end
323
+ )
324
+ @delete_topic = Google::Gax.create_api_call(
325
+ @publisher_stub.method(:delete_topic),
326
+ defaults["delete_topic"],
327
+ exception_transformer: exception_transformer,
328
+ params_extractor: proc do |request|
329
+ {'topic' => request.topic}
330
+ end
331
+ )
332
+ @set_iam_policy = Google::Gax.create_api_call(
333
+ @iam_policy_stub.method(:set_iam_policy),
334
+ defaults["set_iam_policy"],
335
+ exception_transformer: exception_transformer,
336
+ params_extractor: proc do |request|
337
+ {'resource' => request.resource}
338
+ end
339
+ )
340
+ @get_iam_policy = Google::Gax.create_api_call(
341
+ @iam_policy_stub.method(:get_iam_policy),
342
+ defaults["get_iam_policy"],
343
+ exception_transformer: exception_transformer,
344
+ params_extractor: proc do |request|
345
+ {'resource' => request.resource}
346
+ end
347
+ )
348
+ @test_iam_permissions = Google::Gax.create_api_call(
349
+ @iam_policy_stub.method(:test_iam_permissions),
350
+ defaults["test_iam_permissions"],
351
+ exception_transformer: exception_transformer,
352
+ params_extractor: proc do |request|
353
+ {'resource' => request.resource}
354
+ end
355
+ )
356
+ @detach_subscription = Google::Gax.create_api_call(
357
+ @publisher_stub.method(:detach_subscription),
358
+ defaults["detach_subscription"],
359
+ exception_transformer: exception_transformer,
360
+ params_extractor: proc do |request|
361
+ {'subscription' => request.subscription}
362
+ end
363
+ )
364
+ end
365
+
366
+ # Service calls
367
+
368
+ # Creates the given topic with the given name. See the
369
+ # <a href="https://cloud.google.com/pubsub/docs/admin#resource_names">
370
+ # resource name rules</a>.
371
+ #
372
+ # @param name [String]
373
+ # Required. The name of the topic. It must have the format
374
+ # `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter,
375
+ # and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
376
+ # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
377
+ # signs (`%`). It must be between 3 and 255 characters in length, and it
378
+ # must not start with `"goog"`.
379
+ # @param labels [Hash{String => String}]
380
+ # See <a href="https://cloud.google.com/pubsub/docs/labels"> Creating and
381
+ # managing labels</a>.
382
+ # @param message_storage_policy [Google::Cloud::PubSub::V1::MessageStoragePolicy | Hash]
383
+ # Policy constraining the set of Google Cloud Platform regions where messages
384
+ # published to the topic may be stored. If not present, then no constraints
385
+ # are in effect.
386
+ # A hash of the same form as `Google::Cloud::PubSub::V1::MessageStoragePolicy`
387
+ # can also be provided.
388
+ # @param kms_key_name [String]
389
+ # The resource name of the Cloud KMS CryptoKey to be used to protect access
390
+ # to messages published on this topic.
391
+ #
392
+ # The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`.
393
+ # @param options [Google::Gax::CallOptions]
394
+ # Overrides the default settings for this call, e.g, timeout,
395
+ # retries, etc.
396
+ # @yield [result, operation] Access the result along with the RPC operation
397
+ # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
398
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
399
+ # @return [Google::Cloud::PubSub::V1::Topic]
400
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
401
+ # @example
402
+ # require "google/cloud/pubsub"
403
+ #
404
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
405
+ # formatted_name = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
406
+ # response = publisher_client.create_topic(formatted_name)
407
+
408
+ def create_topic \
409
+ name,
410
+ labels: nil,
411
+ message_storage_policy: nil,
412
+ kms_key_name: nil,
413
+ options: nil,
414
+ &block
415
+ req = {
416
+ name: name,
417
+ labels: labels,
418
+ message_storage_policy: message_storage_policy,
419
+ kms_key_name: kms_key_name
420
+ }.delete_if { |_, v| v.nil? }
421
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::Topic)
422
+ @create_topic.call(req, options, &block)
423
+ end
424
+
425
+ # Updates an existing topic. Note that certain properties of a
426
+ # topic are not modifiable.
427
+ #
428
+ # @param topic [Google::Cloud::PubSub::V1::Topic | Hash]
429
+ # Required. The updated topic object.
430
+ # A hash of the same form as `Google::Cloud::PubSub::V1::Topic`
431
+ # can also be provided.
432
+ # @param update_mask [Google::Protobuf::FieldMask | Hash]
433
+ # Required. Indicates which fields in the provided topic to update. Must be
434
+ # specified and non-empty. Note that if `update_mask` contains
435
+ # "message_storage_policy" but the `message_storage_policy` is not set in
436
+ # the `topic` provided above, then the updated value is determined by the
437
+ # policy configured at the project or organization level.
438
+ # A hash of the same form as `Google::Protobuf::FieldMask`
439
+ # can also be provided.
440
+ # @param options [Google::Gax::CallOptions]
441
+ # Overrides the default settings for this call, e.g, timeout,
442
+ # retries, etc.
443
+ # @yield [result, operation] Access the result along with the RPC operation
444
+ # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
445
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
446
+ # @return [Google::Cloud::PubSub::V1::Topic]
447
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
448
+ # @example
449
+ # require "google/cloud/pubsub"
450
+ #
451
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
452
+ #
453
+ # # TODO: Initialize `topic`:
454
+ # topic = {}
455
+ #
456
+ # # TODO: Initialize `update_mask`:
457
+ # update_mask = {}
458
+ # response = publisher_client.update_topic(topic, update_mask)
459
+
460
+ def update_topic \
461
+ topic,
462
+ update_mask,
463
+ options: nil,
464
+ &block
465
+ req = {
466
+ topic: topic,
467
+ update_mask: update_mask
468
+ }.delete_if { |_, v| v.nil? }
469
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::UpdateTopicRequest)
470
+ @update_topic.call(req, options, &block)
471
+ end
472
+
473
+ # Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
474
+ # does not exist.
475
+ #
476
+ # @param topic [String]
477
+ # Required. The messages in the request will be published on this topic.
478
+ # Format is `projects/{project}/topics/{topic}`.
479
+ # @param messages [Array<Google::Cloud::PubSub::V1::PubsubMessage | Hash>]
480
+ # Required. The messages to publish.
481
+ # A hash of the same form as `Google::Cloud::PubSub::V1::PubsubMessage`
482
+ # can also be provided.
483
+ # @param options [Google::Gax::CallOptions]
484
+ # Overrides the default settings for this call, e.g, timeout,
485
+ # retries, etc.
486
+ # @yield [result, operation] Access the result along with the RPC operation
487
+ # @yieldparam result [Google::Cloud::PubSub::V1::PublishResponse]
488
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
489
+ # @return [Google::Cloud::PubSub::V1::PublishResponse]
490
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
491
+ # @example
492
+ # require "google/cloud/pubsub"
493
+ #
494
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
495
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
496
+ # data = ''
497
+ # messages_element = { data: data }
498
+ # messages = [messages_element]
499
+ # response = publisher_client.publish(formatted_topic, messages)
500
+
501
+ def publish \
502
+ topic,
503
+ messages,
504
+ options: nil,
505
+ &block
506
+ req = {
507
+ topic: topic,
508
+ messages: messages
509
+ }.delete_if { |_, v| v.nil? }
510
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::PublishRequest)
511
+ @publish.call(req, options, &block)
512
+ end
513
+
514
+ # Gets the configuration of a topic.
515
+ #
516
+ # @param topic [String]
517
+ # Required. The name of the topic to get.
518
+ # Format is `projects/{project}/topics/{topic}`.
519
+ # @param options [Google::Gax::CallOptions]
520
+ # Overrides the default settings for this call, e.g, timeout,
521
+ # retries, etc.
522
+ # @yield [result, operation] Access the result along with the RPC operation
523
+ # @yieldparam result [Google::Cloud::PubSub::V1::Topic]
524
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
525
+ # @return [Google::Cloud::PubSub::V1::Topic]
526
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
527
+ # @example
528
+ # require "google/cloud/pubsub"
529
+ #
530
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
531
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
532
+ # response = publisher_client.get_topic(formatted_topic)
533
+
534
+ def get_topic \
535
+ topic,
536
+ options: nil,
537
+ &block
538
+ req = {
539
+ topic: topic
540
+ }.delete_if { |_, v| v.nil? }
541
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::GetTopicRequest)
542
+ @get_topic.call(req, options, &block)
543
+ end
544
+
545
+ # Lists matching topics.
546
+ #
547
+ # @param project [String]
548
+ # Required. The name of the project in which to list topics.
549
+ # Format is `projects/{project-id}`.
550
+ # @param page_size [Integer]
551
+ # The maximum number of resources contained in the underlying API
552
+ # response. If page streaming is performed per-resource, this
553
+ # parameter does not affect the return value. If page streaming is
554
+ # performed per-page, this determines the maximum number of
555
+ # resources in a page.
556
+ # @param options [Google::Gax::CallOptions]
557
+ # Overrides the default settings for this call, e.g, timeout,
558
+ # retries, etc.
559
+ # @yield [result, operation] Access the result along with the RPC operation
560
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::PubSub::V1::Topic>]
561
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
562
+ # @return [Google::Gax::PagedEnumerable<Google::Cloud::PubSub::V1::Topic>]
563
+ # An enumerable of Google::Cloud::PubSub::V1::Topic instances.
564
+ # See Google::Gax::PagedEnumerable documentation for other
565
+ # operations such as per-page iteration or access to the response
566
+ # object.
567
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
568
+ # @example
569
+ # require "google/cloud/pubsub"
570
+ #
571
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
572
+ # formatted_project = Google::Cloud::PubSub::V1::PublisherClient.project_path("[PROJECT]")
573
+ #
574
+ # # Iterate over all results.
575
+ # publisher_client.list_topics(formatted_project).each do |element|
576
+ # # Process element.
577
+ # end
578
+ #
579
+ # # Or iterate over results one page at a time.
580
+ # publisher_client.list_topics(formatted_project).each_page do |page|
581
+ # # Process each page at a time.
582
+ # page.each do |element|
583
+ # # Process element.
584
+ # end
585
+ # end
586
+
587
+ def list_topics \
588
+ project,
589
+ page_size: nil,
590
+ options: nil,
591
+ &block
592
+ req = {
593
+ project: project,
594
+ page_size: page_size
595
+ }.delete_if { |_, v| v.nil? }
596
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicsRequest)
597
+ @list_topics.call(req, options, &block)
598
+ end
599
+
600
+ # Lists the names of the attached subscriptions on this topic.
601
+ #
602
+ # @param topic [String]
603
+ # Required. The name of the topic that subscriptions are attached to.
604
+ # Format is `projects/{project}/topics/{topic}`.
605
+ # @param page_size [Integer]
606
+ # The maximum number of resources contained in the underlying API
607
+ # response. If page streaming is performed per-resource, this
608
+ # parameter does not affect the return value. If page streaming is
609
+ # performed per-page, this determines the maximum number of
610
+ # resources in a page.
611
+ # @param options [Google::Gax::CallOptions]
612
+ # Overrides the default settings for this call, e.g, timeout,
613
+ # retries, etc.
614
+ # @yield [result, operation] Access the result along with the RPC operation
615
+ # @yieldparam result [Google::Gax::PagedEnumerable<String>]
616
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
617
+ # @return [Google::Gax::PagedEnumerable<String>]
618
+ # An enumerable of String instances.
619
+ # See Google::Gax::PagedEnumerable documentation for other
620
+ # operations such as per-page iteration or access to the response
621
+ # object.
622
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
623
+ # @example
624
+ # require "google/cloud/pubsub"
625
+ #
626
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
627
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
628
+ #
629
+ # # Iterate over all results.
630
+ # publisher_client.list_topic_subscriptions(formatted_topic).each do |element|
631
+ # # Process element.
632
+ # end
633
+ #
634
+ # # Or iterate over results one page at a time.
635
+ # publisher_client.list_topic_subscriptions(formatted_topic).each_page do |page|
636
+ # # Process each page at a time.
637
+ # page.each do |element|
638
+ # # Process element.
639
+ # end
640
+ # end
641
+
642
+ def list_topic_subscriptions \
643
+ topic,
644
+ page_size: nil,
645
+ options: nil,
646
+ &block
647
+ req = {
648
+ topic: topic,
649
+ page_size: page_size
650
+ }.delete_if { |_, v| v.nil? }
651
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicSubscriptionsRequest)
652
+ @list_topic_subscriptions.call(req, options, &block)
653
+ end
654
+
655
+ # Lists the names of the snapshots on this topic. Snapshots are used in
656
+ # <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
657
+ # operations, which allow
658
+ # you to manage message acknowledgments in bulk. That is, you can set the
659
+ # acknowledgment state of messages in an existing subscription to the state
660
+ # captured by a snapshot.
661
+ #
662
+ # @param topic [String]
663
+ # Required. The name of the topic that snapshots are attached to.
664
+ # Format is `projects/{project}/topics/{topic}`.
665
+ # @param page_size [Integer]
666
+ # The maximum number of resources contained in the underlying API
667
+ # response. If page streaming is performed per-resource, this
668
+ # parameter does not affect the return value. If page streaming is
669
+ # performed per-page, this determines the maximum number of
670
+ # resources in a page.
671
+ # @param options [Google::Gax::CallOptions]
672
+ # Overrides the default settings for this call, e.g, timeout,
673
+ # retries, etc.
674
+ # @yield [result, operation] Access the result along with the RPC operation
675
+ # @yieldparam result [Google::Gax::PagedEnumerable<String>]
676
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
677
+ # @return [Google::Gax::PagedEnumerable<String>]
678
+ # An enumerable of String instances.
679
+ # See Google::Gax::PagedEnumerable documentation for other
680
+ # operations such as per-page iteration or access to the response
681
+ # object.
682
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
683
+ # @example
684
+ # require "google/cloud/pubsub"
685
+ #
686
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
687
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
688
+ #
689
+ # # Iterate over all results.
690
+ # publisher_client.list_topic_snapshots(formatted_topic).each do |element|
691
+ # # Process element.
692
+ # end
693
+ #
694
+ # # Or iterate over results one page at a time.
695
+ # publisher_client.list_topic_snapshots(formatted_topic).each_page do |page|
696
+ # # Process each page at a time.
697
+ # page.each do |element|
698
+ # # Process element.
699
+ # end
700
+ # end
701
+
702
+ def list_topic_snapshots \
703
+ topic,
704
+ page_size: nil,
705
+ options: nil,
706
+ &block
707
+ req = {
708
+ topic: topic,
709
+ page_size: page_size
710
+ }.delete_if { |_, v| v.nil? }
711
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicSnapshotsRequest)
712
+ @list_topic_snapshots.call(req, options, &block)
713
+ end
714
+
715
+ # Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
716
+ # does not exist. After a topic is deleted, a new topic may be created with
717
+ # the same name; this is an entirely new topic with none of the old
718
+ # configuration or subscriptions. Existing subscriptions to this topic are
719
+ # not deleted, but their `topic` field is set to `_deleted-topic_`.
720
+ #
721
+ # @param topic [String]
722
+ # Required. Name of the topic to delete.
723
+ # Format is `projects/{project}/topics/{topic}`.
724
+ # @param options [Google::Gax::CallOptions]
725
+ # Overrides the default settings for this call, e.g, timeout,
726
+ # retries, etc.
727
+ # @yield [result, operation] Access the result along with the RPC operation
728
+ # @yieldparam result []
729
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
730
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
731
+ # @example
732
+ # require "google/cloud/pubsub"
733
+ #
734
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
735
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
736
+ # publisher_client.delete_topic(formatted_topic)
737
+
738
+ def delete_topic \
739
+ topic,
740
+ options: nil,
741
+ &block
742
+ req = {
743
+ topic: topic
744
+ }.delete_if { |_, v| v.nil? }
745
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::DeleteTopicRequest)
746
+ @delete_topic.call(req, options, &block)
747
+ nil
748
+ end
749
+
750
+ # Sets the access control policy on the specified resource. Replaces
751
+ # any existing policy.
752
+ #
753
+ # Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
754
+ # errors.
755
+ #
756
+ # @param resource [String]
757
+ # REQUIRED: The resource for which the policy is being specified.
758
+ # See the operation documentation for the appropriate value for this field.
759
+ # @param policy [Google::Iam::V1::Policy | Hash]
760
+ # REQUIRED: The complete policy to be applied to the `resource`. The size of
761
+ # the policy is limited to a few 10s of KB. An empty policy is a
762
+ # valid policy but certain Cloud Platform services (such as Projects)
763
+ # might reject them.
764
+ # A hash of the same form as `Google::Iam::V1::Policy`
765
+ # can also be provided.
766
+ # @param options [Google::Gax::CallOptions]
767
+ # Overrides the default settings for this call, e.g, timeout,
768
+ # retries, etc.
769
+ # @yield [result, operation] Access the result along with the RPC operation
770
+ # @yieldparam result [Google::Iam::V1::Policy]
771
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
772
+ # @return [Google::Iam::V1::Policy]
773
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
774
+ # @example
775
+ # require "google/cloud/pubsub"
776
+ #
777
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
778
+ #
779
+ # # TODO: Initialize `resource`:
780
+ # resource = ''
781
+ #
782
+ # # TODO: Initialize `policy`:
783
+ # policy = {}
784
+ # response = publisher_client.set_iam_policy(resource, policy)
785
+
786
+ def set_iam_policy \
787
+ resource,
788
+ policy,
789
+ options: nil,
790
+ &block
791
+ req = {
792
+ resource: resource,
793
+ policy: policy
794
+ }.delete_if { |_, v| v.nil? }
795
+ req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest)
796
+ @set_iam_policy.call(req, options, &block)
797
+ end
798
+
799
+ # Gets the access control policy for a resource. Returns an empty policy
800
+ # if the resource exists and does not have a policy set.
801
+ #
802
+ # @param resource [String]
803
+ # REQUIRED: The resource for which the policy is being requested.
804
+ # See the operation documentation for the appropriate value for this field.
805
+ # @param options_ [Google::Iam::V1::GetPolicyOptions | Hash]
806
+ # OPTIONAL: A `GetPolicyOptions` object for specifying options to
807
+ # `GetIamPolicy`. This field is only used by Cloud IAM.
808
+ # A hash of the same form as `Google::Iam::V1::GetPolicyOptions`
809
+ # can also be provided.
810
+ # @param options [Google::Gax::CallOptions]
811
+ # Overrides the default settings for this call, e.g, timeout,
812
+ # retries, etc.
813
+ # @yield [result, operation] Access the result along with the RPC operation
814
+ # @yieldparam result [Google::Iam::V1::Policy]
815
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
816
+ # @return [Google::Iam::V1::Policy]
817
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
818
+ # @example
819
+ # require "google/cloud/pubsub"
820
+ #
821
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
822
+ #
823
+ # # TODO: Initialize `resource`:
824
+ # resource = ''
825
+ # response = publisher_client.get_iam_policy(resource)
826
+
827
+ def get_iam_policy \
828
+ resource,
829
+ options_: nil,
830
+ options: nil,
831
+ &block
832
+ req = {
833
+ resource: resource,
834
+ options: options_
835
+ }.delete_if { |_, v| v.nil? }
836
+ req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest)
837
+ @get_iam_policy.call(req, options, &block)
838
+ end
839
+
840
+ # Returns permissions that a caller has on the specified resource. If the
841
+ # resource does not exist, this will return an empty set of
842
+ # permissions, not a `NOT_FOUND` error.
843
+ #
844
+ # Note: This operation is designed to be used for building
845
+ # permission-aware UIs and command-line tools, not for authorization
846
+ # checking. This operation may "fail open" without warning.
847
+ #
848
+ # @param resource [String]
849
+ # REQUIRED: The resource for which the policy detail is being requested.
850
+ # See the operation documentation for the appropriate value for this field.
851
+ # @param permissions [Array<String>]
852
+ # The set of permissions to check for the `resource`. Permissions with
853
+ # wildcards (such as '*' or 'storage.*') are not allowed. For more
854
+ # information see
855
+ # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
856
+ # @param options [Google::Gax::CallOptions]
857
+ # Overrides the default settings for this call, e.g, timeout,
858
+ # retries, etc.
859
+ # @yield [result, operation] Access the result along with the RPC operation
860
+ # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse]
861
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
862
+ # @return [Google::Iam::V1::TestIamPermissionsResponse]
863
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
864
+ # @example
865
+ # require "google/cloud/pubsub"
866
+ #
867
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
868
+ #
869
+ # # TODO: Initialize `resource`:
870
+ # resource = ''
871
+ #
872
+ # # TODO: Initialize `permissions`:
873
+ # permissions = []
874
+ # response = publisher_client.test_iam_permissions(resource, permissions)
875
+
876
+ def test_iam_permissions \
877
+ resource,
878
+ permissions,
879
+ options: nil,
880
+ &block
881
+ req = {
882
+ resource: resource,
883
+ permissions: permissions
884
+ }.delete_if { |_, v| v.nil? }
885
+ req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
886
+ @test_iam_permissions.call(req, options, &block)
887
+ end
888
+
889
+ # Detaches a subscription from this topic. All messages retained in the
890
+ # subscription are dropped. Subsequent `Pull` and `StreamingPull` requests
891
+ # will return FAILED_PRECONDITION. If the subscription is a push
892
+ # subscription, pushes to the endpoint will stop.
893
+ #
894
+ # @param subscription [String]
895
+ # Required. The subscription to detach.
896
+ # Format is `projects/{project}/subscriptions/{subscription}`.
897
+ # @param options [Google::Gax::CallOptions]
898
+ # Overrides the default settings for this call, e.g, timeout,
899
+ # retries, etc.
900
+ # @yield [result, operation] Access the result along with the RPC operation
901
+ # @yieldparam result [Google::Cloud::PubSub::V1::DetachSubscriptionResponse]
902
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
903
+ # @return [Google::Cloud::PubSub::V1::DetachSubscriptionResponse]
904
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
905
+ # @example
906
+ # require "google/cloud/pubsub"
907
+ #
908
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
909
+ # formatted_subscription = Google::Cloud::PubSub::V1::PublisherClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
910
+ # response = publisher_client.detach_subscription(formatted_subscription)
911
+
912
+ def detach_subscription \
913
+ subscription,
914
+ options: nil,
915
+ &block
916
+ req = {
917
+ subscription: subscription
918
+ }.delete_if { |_, v| v.nil? }
919
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::DetachSubscriptionRequest)
920
+ @detach_subscription.call(req, options, &block)
921
+ end
922
+ end
923
+ end
924
+ end
925
+
926
+ Pubsub = PubSub unless const_defined? :Pubsub
927
+ end
928
+ end