google-cloud-pubsub 2.15.5 → 3.3.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +12 -1
  3. data/CHANGELOG.md +129 -0
  4. data/OVERVIEW.md +189 -145
  5. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  6. data/lib/google/cloud/pubsub/async_publisher.rb +20 -19
  7. data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
  8. data/lib/google/cloud/pubsub/convert.rb +1 -1
  9. data/lib/google/cloud/pubsub/errors.rb +3 -3
  10. data/lib/google/cloud/pubsub/flow_controller.rb +0 -2
  11. data/lib/google/cloud/pubsub/internal_logger.rb +76 -0
  12. data/lib/google/cloud/pubsub/message.rb +10 -11
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  14. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +13 -10
  15. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  16. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +58 -17
  17. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +29 -9
  18. data/lib/google/cloud/pubsub/message_listener.rb +413 -0
  19. data/lib/google/cloud/pubsub/project.rb +108 -523
  20. data/lib/google/cloud/pubsub/publisher.rb +424 -0
  21. data/lib/google/cloud/pubsub/received_message.rb +50 -45
  22. data/lib/google/cloud/pubsub/service.rb +48 -349
  23. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  24. data/lib/google/cloud/pubsub/version.rb +1 -1
  25. data/lib/google/cloud/pubsub.rb +51 -30
  26. data/lib/google-cloud-pubsub.rb +30 -10
  27. metadata +19 -183
  28. data/lib/google/cloud/pubsub/policy.rb +0 -188
  29. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  30. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  31. data/lib/google/cloud/pubsub/schema.rb +0 -310
  32. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  33. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  34. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  35. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  36. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  37. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  38. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -16,10 +16,8 @@
16
16
  require "google/cloud/errors"
17
17
  require "google/cloud/pubsub/service"
18
18
  require "google/cloud/pubsub/credentials"
19
- require "google/cloud/pubsub/topic"
20
- require "google/cloud/pubsub/batch_publisher"
21
- require "google/cloud/pubsub/schema"
22
- require "google/cloud/pubsub/snapshot"
19
+ require "google/cloud/pubsub/publisher"
20
+ require "google/cloud/pubsub/subscriber"
23
21
 
24
22
  module Google
25
23
  module Cloud
@@ -31,10 +29,13 @@ module Google
31
29
  # # Project
32
30
  #
33
31
  # Represents the project that pubsub messages are pushed to and pulled
34
- # from. {Topic} is a named resource to which messages are sent by
35
- # publishers. {Subscription} is a named resource representing the stream
32
+ # from.
33
+ #
34
+ # {Google::Cloud::PubSub::V1::Topic} is a named resource to which
35
+ # messages are sent by using {Publisher}.
36
+ # {Google::Cloud::PubSub::V1::Subscription} is a named resource representing the stream
36
37
  # of messages from a single, specific topic, to be delivered to the
37
- # subscribing application. {Message} is a combination of data and
38
+ # subscribing application via {Subscriber}. {Message} is a combination of data and
38
39
  # attributes that a publisher sends to a topic and is eventually delivered
39
40
  # to subscribers.
40
41
  #
@@ -45,8 +46,8 @@ module Google
45
46
  #
46
47
  # pubsub = Google::Cloud::PubSub.new
47
48
  #
48
- # topic = pubsub.topic "my-topic"
49
- # topic.publish "task completed"
49
+ # publisher = pubsub.publisher "my-topic"
50
+ # publisher.publish "task completed"
50
51
  #
51
52
  class Project
52
53
  ##
@@ -77,570 +78,154 @@ module Google
77
78
  alias project project_id
78
79
 
79
80
  ##
80
- # Retrieves topic by name.
81
- #
82
- # @param [String] topic_name Name of a topic. The value can be a simple
83
- # topic ID (relative name), in which case the current project ID will
84
- # be supplied, or a fully-qualified topic name in the form
85
- # `projects/{project_id}/topics/{topic_id}`.
86
- # @param [String] project If the topic belongs to a project other than
87
- # the one currently connected to, the alternate project ID can be
88
- # specified here. Optional. Not used if a fully-qualified topic name
89
- # is provided for `topic_name`.
90
- # @param [Boolean] skip_lookup Optionally create a {Topic} object
91
- # without verifying the topic resource exists on the Pub/Sub service.
92
- # Calls made on this object will raise errors if the topic resource
93
- # does not exist. Default is `false`. Optional.
94
- # @param [Hash] async A hash of values to configure the topic's
95
- # {AsyncPublisher} that is created when {Topic#publish_async}
96
- # is called. Optional.
81
+ # The universe domain the client is connected to
97
82
  #
98
- # Hash keys and values may include the following:
99
- #
100
- # * `:max_bytes` (Integer) The maximum size of messages to be collected before the batch is published. Default
101
- # is 1,000,000 (1MB).
102
- # * `:max_messages` (Integer) The maximum number of messages to be collected before the batch is published.
103
- # Default is 100.
104
- # * `:interval` (Numeric) The number of seconds to collect messages before the batch is published. Default is
105
- # 0.01.
106
- # * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
107
- # * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
108
- # * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
109
- # * `:compress` (Boolean) The flag that enables publisher compression. Default is false
110
- # * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
111
- # Default is 240.
112
- # * `:flow_control` (Hash) The client flow control settings for message publishing:
113
- # * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
114
- # `10 * max_messages`.
115
- # * `:byte_limit` (Integer) The maximum total size of messages allowed to wait to be published. Default is
116
- # `10 * max_bytes`.
117
- # * `:limit_exceeded_behavior` (Symbol) The action to take when publish flow control limits are exceeded.
118
- # Possible values include: `:ignore` - Flow control is disabled. `:error` - Calls to {Topic#publish_async}
119
- # will raise {FlowControlLimitError} when publish flow control limits are exceeded. `:block` - Calls to
120
- # {Topic#publish_async} will block until capacity is available when publish flow control limits are
121
- # exceeded. The default value is `:ignore`.
122
- #
123
- # @return [Google::Cloud::PubSub::Topic, nil] Returns `nil` if topic
124
- # does not exist.
125
- #
126
- # @example
127
- # require "google/cloud/pubsub"
128
- #
129
- # pubsub = Google::Cloud::PubSub.new
130
- # topic = pubsub.topic "existing-topic"
131
- #
132
- # @example By default `nil` will be returned if topic does not exist.
133
- # require "google/cloud/pubsub"
134
- #
135
- # pubsub = Google::Cloud::PubSub.new
136
- # topic = pubsub.topic "non-existing-topic" # nil
137
- #
138
- # @example Create topic in a different project with the `project` flag.
139
- # require "google/cloud/pubsub"
140
- #
141
- # pubsub = Google::Cloud::PubSub.new
142
- # topic = pubsub.topic "another-topic", project: "another-project"
143
- #
144
- # @example Skip the lookup against the service with `skip_lookup`:
145
- # require "google/cloud/pubsub"
83
+ # @return [String]
146
84
  #
147
- # pubsub = Google::Cloud::PubSub.new
148
- # topic = pubsub.topic "another-topic", skip_lookup: true
149
- #
150
- # @example Configuring AsyncPublisher to increase concurrent callbacks:
151
- # require "google/cloud/pubsub"
152
- #
153
- # pubsub = Google::Cloud::PubSub.new
154
- # topic = pubsub.topic "my-topic",
155
- # async: { threads: { callback: 16 } }
156
- #
157
- # topic.publish_async "task completed" do |result|
158
- # if result.succeeded?
159
- # log_publish_success result.data
160
- # else
161
- # log_publish_failure result.data, result.error
162
- # end
163
- # end
164
- #
165
- # topic.async_publisher.stop!
166
- #
167
- def topic topic_name, project: nil, skip_lookup: nil, async: nil
168
- ensure_service!
169
- options = { project: project, async: async }
170
- return Topic.from_name topic_name, service, options if skip_lookup
171
- grpc = service.get_topic topic_name, options
172
- Topic.from_grpc grpc, service, async: async
173
- rescue Google::Cloud::NotFoundError
174
- nil
85
+ def universe_domain
86
+ service.universe_domain
175
87
  end
176
- alias get_topic topic
177
- alias find_topic topic
178
88
 
179
89
  ##
180
- # Creates a new topic.
181
- #
182
- # @param [String] topic_name Name of a topic. Required.
183
- # The value can be a simple topic ID (relative name), in which
184
- # case the current project ID will be supplied, or a fully-qualified
185
- # topic name in the form `projects/{project_id}/topics/{topic_id}`.
186
- #
187
- # The topic ID (relative name) must start with a letter, and
188
- # contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
189
- # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
190
- # signs (`%`). It must be between 3 and 255 characters in length, and
191
- # it must not start with `goog`.
192
- # @param [Hash] labels A hash of user-provided labels associated with
193
- # the topic. You can use these to organize and group your topics.
194
- # Label keys and values can be no longer than 63 characters, can only
195
- # contain lowercase letters, numeric characters, underscores and
196
- # dashes. International characters are allowed. Label values are
197
- # optional. Label keys must start with a letter and each label in the
198
- # list must have a different key. See [Creating and Managing
199
- # Labels](https://cloud.google.com/pubsub/docs/labels).
200
- # @param [String] kms_key The Cloud KMS encryption key that will be used
201
- # to protect access to messages published on this topic. Optional.
202
- # For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
203
- # @param [Array<String>] persistence_regions The list of GCP region IDs
204
- # where messages that are published to the topic may be persisted in
205
- # storage. Optional.
206
- # @param [Hash] async A hash of values to configure the topic's
207
- # {AsyncPublisher} that is created when {Topic#publish_async}
208
- # is called. Optional.
209
- #
210
- # Hash keys and values may include the following:
211
- #
212
- # * `:max_bytes` (Integer) The maximum size of messages to be collected
213
- # before the batch is published. Default is 1,000,000 (1MB).
214
- # * `:max_messages` (Integer) The maximum number of messages to be
215
- # collected before the batch is published. Default is 100.
216
- # * `:interval` (Numeric) The number of seconds to collect messages before
217
- # the batch is published. Default is 0.01.
218
- # * `:threads` (Hash) The number of threads to create to handle concurrent
219
- # calls by the publisher:
220
- # * `:publish` (Integer) The number of threads used to publish messages.
221
- # Default is 2.
222
- # * `:callback` (Integer) The number of threads to handle the published
223
- # messages' callbacks. Default is 4.
224
- # * `:compress` (Boolean) The flag that enables publisher compression. Default is false
225
- # * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
226
- # Default is 240.
227
- # * `:flow_control` (Hash) The client flow control settings for message publishing:
228
- # * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
229
- # `10 * max_messages`.
230
- # * `:byte_limit` (Integer) The maximum total size of messages allowed to wait to be published. Default is
231
- # `10 * max_bytes`.
232
- # * `:limit_exceeded_behavior` (Symbol) The action to take when publish flow control limits are exceeded.
233
- # Possible values include: `:ignore` - Flow control is disabled. `:error` - Calls to {Topic#publish_async}
234
- # will raise {FlowControlLimitError} when publish flow control limits are exceeded. `:block` - Calls to
235
- # {Topic#publish_async} will block until capacity is available when publish flow control limits are
236
- # exceeded. The default value is `:ignore`.
237
- # @param [String] schema_name The name of the schema that messages
238
- # published should be validated against. Optional. The value can be a
239
- # simple schema ID (relative name), in which case the current project
240
- # ID will be supplied, or a fully-qualified schema name in the form
241
- # `projects/{project_id}/schemas/{schema_id}`. If provided,
242
- # `message_encoding` must also be provided.
243
- # @param [String, Symbol] message_encoding The encoding of messages validated
244
- # against the schema identified by `schema_name`. Optional. Values include:
245
- #
246
- # * `JSON` - JSON encoding.
247
- # * `BINARY` - Binary encoding, as defined by the schema type. For some
248
- # schema types, binary encoding may not be available.
249
- # @param [Numeric] retention Indicates the minimum number of seconds to retain a message
250
- # after it is published to the topic. If this field is set, messages published
251
- # to the topic within the `retention` number of seconds are always available to
252
- # subscribers. For instance, it allows any attached subscription to [seek to a
253
- # timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time)
254
- # that is up to `retention` number of seconds in the past. If this field is
255
- # not set, message retention is controlled by settings on individual
256
- # subscriptions. Cannot be less than 600 (10 minutes) or more than 604,800 (7 days).
257
- #
258
- # @return [Google::Cloud::PubSub::Topic]
259
- #
260
- # @example
261
- # require "google/cloud/pubsub"
90
+ # Retrieve a client for managing subscriptions.
262
91
  #
263
- # pubsub = Google::Cloud::PubSub.new
264
- # topic = pubsub.create_topic "my-topic"
92
+ # @return [Google::Cloud::PubSub::SubscriptionAdmin::Client]
265
93
  #
266
- def create_topic topic_name,
267
- labels: nil,
268
- kms_key: nil,
269
- persistence_regions: nil,
270
- async: nil,
271
- schema_name: nil,
272
- message_encoding: nil,
273
- retention: nil
274
- ensure_service!
275
- grpc = service.create_topic topic_name,
276
- labels: labels,
277
- kms_key_name: kms_key,
278
- persistence_regions: persistence_regions,
279
- schema_name: schema_name,
280
- message_encoding: message_encoding,
281
- retention: retention
282
- Topic.from_grpc grpc, service, async: async
94
+ def subscription_admin
95
+ service.subscription_admin
283
96
  end
284
- alias new_topic create_topic
285
97
 
286
98
  ##
287
- # Retrieves a list of topics for the given project.
288
- #
289
- # @param [String] token The `token` value returned by the last call to
290
- # `topics`; indicates that this is a continuation of a call, and that
291
- # the system should return the next page of data.
292
- # @param [Integer] max Maximum number of topics to return.
293
- #
294
- # @return [Array<Google::Cloud::PubSub::Topic>] (See
295
- # {Google::Cloud::PubSub::Topic::List})
296
- #
297
- # @example
298
- # require "google/cloud/pubsub"
299
- #
300
- # pubsub = Google::Cloud::PubSub.new
99
+ # Retrieve a client for managing topics.
301
100
  #
302
- # topics = pubsub.topics
303
- # topics.each do |topic|
304
- # puts topic.name
305
- # end
306
- #
307
- # @example Retrieve all topics: (See {Topic::List#all})
308
- # require "google/cloud/pubsub"
101
+ # @return [Google::Cloud::PubSub::TopicAdmin::Client]
309
102
  #
310
- # pubsub = Google::Cloud::PubSub.new
311
- #
312
- # topics = pubsub.topics
313
- # topics.all do |topic|
314
- # puts topic.name
315
- # end
316
- #
317
- def topics token: nil, max: nil
318
- ensure_service!
319
- options = { token: token, max: max }
320
- grpc = service.list_topics options
321
- Topic::List.from_grpc grpc, service, max
103
+ def topic_admin
104
+ service.topic_admin
322
105
  end
323
- alias find_topics topics
324
- alias list_topics topics
325
106
 
326
107
  ##
327
- # Retrieves subscription by name.
108
+ # Retrieve a client for managing schemas.
328
109
  #
329
- # @param [String] subscription_name Name of a subscription. The value can
330
- # be a simple subscription ID, in which case the current project ID
331
- # will be supplied, or a fully-qualified subscription name in the form
332
- # `projects/{project_id}/subscriptions/{subscription_id}`.
333
- # @param [String] project If the subscription belongs to a project other
334
- # than the one currently connected to, the alternate project ID can be
335
- # specified here. Not used if a fully-qualified subscription name is
336
- # provided for `subscription_name`.
337
- # @param [Boolean] skip_lookup Optionally create a {Subscription} object
338
- # without verifying the subscription resource exists on the Pub/Sub
339
- # service. Calls made on this object will raise errors if the service
340
- # resource does not exist. Default is `false`.
341
- #
342
- # @return [Google::Cloud::PubSub::Subscription, nil] Returns `nil` if
343
- # the subscription does not exist
110
+ # @return [Google::Cloud::PubSub::V1::SchemaService::Client]
344
111
  #
345
- # @example
346
- # require "google/cloud/pubsub"
347
- #
348
- # pubsub = Google::Cloud::PubSub.new
349
- #
350
- # sub = pubsub.subscription "my-sub"
351
- # sub.name #=> "projects/my-project/subscriptions/my-sub"
352
- #
353
- # @example Skip the lookup against the service with `skip_lookup`:
354
- # require "google/cloud/pubsub"
355
- #
356
- # pubsub = Google::Cloud::PubSub.new
357
- #
358
- # # No API call is made to retrieve the subscription information.
359
- # sub = pubsub.subscription "my-sub", skip_lookup: true
360
- # sub.name #=> "projects/my-project/subscriptions/my-sub"
361
- #
362
- def subscription subscription_name, project: nil, skip_lookup: nil
363
- ensure_service!
364
- options = { project: project }
365
- return Subscription.from_name subscription_name, service, options if skip_lookup
366
- grpc = service.get_subscription subscription_name, options
367
- Subscription.from_grpc grpc, service
368
- rescue Google::Cloud::NotFoundError
369
- nil
112
+ def schemas
113
+ service.schemas
370
114
  end
371
- alias get_subscription subscription
372
- alias find_subscription subscription
373
115
 
374
116
  ##
375
- # Retrieves a list of subscriptions for the given project.
376
- #
377
- # @param [String] token A previously-returned page token representing
378
- # part of the larger set of results to view.
379
- # @param [Integer] max Maximum number of subscriptions to return.
380
- #
381
- # @return [Array<Google::Cloud::PubSub::Subscription>] (See
382
- # {Google::Cloud::PubSub::Subscription::List})
383
- #
384
- # @example
385
- # require "google/cloud/pubsub"
386
- #
387
- # pubsub = Google::Cloud::PubSub.new
388
- #
389
- # subs = pubsub.subscriptions
390
- # subs.each do |sub|
391
- # puts sub.name
392
- # end
393
- #
394
- # @example Retrieve all subscriptions: (See {Subscription::List#all})
395
- # require "google/cloud/pubsub"
117
+ # Retrieve a client specific for Iam Policy related functions.
396
118
  #
397
- # pubsub = Google::Cloud::PubSub.new
119
+ # @return [Google::Iam::V1::IAMPolicy::Client]
398
120
  #
399
- # subs = pubsub.subscriptions
400
- # subs.all do |sub|
401
- # puts sub.name
402
- # end
403
- #
404
- def subscriptions token: nil, max: nil
405
- ensure_service!
406
- options = { token: token, max: max }
407
- grpc = service.list_subscriptions options
408
- Subscription::List.from_grpc grpc, service, max
121
+ def iam
122
+ service.iam
409
123
  end
410
- alias find_subscriptions subscriptions
411
- alias list_subscriptions subscriptions
412
-
413
124
 
414
125
  ##
415
- # Retrieves a list of snapshots for the given project.
416
- #
417
- # @param [String] token A previously-returned page token representing
418
- # part of the larger set of results to view.
419
- # @param [Integer] max Maximum number of snapshots to return.
420
- #
421
- # @return [Array<Google::Cloud::PubSub::Snapshot>] (See
422
- # {Google::Cloud::PubSub::Snapshot::List})
423
- #
424
- # @example
425
- # require "google/cloud/pubsub"
426
- #
427
- # pubsub = Google::Cloud::PubSub.new
428
- #
429
- # snapshots = pubsub.snapshots
430
- # snapshots.each do |snapshot|
431
- # puts snapshot.name
432
- # end
126
+ # Retrieves a Publisher by topic name or full project path.
433
127
  #
434
- # @example Retrieve all snapshots: (See {Snapshot::List#all})
435
- # require "google/cloud/pubsub"
436
- #
437
- # pubsub = Google::Cloud::PubSub.new
128
+ # @param [String] topic_name Name of a topic. The value can be a simple
129
+ # topic ID (relative name) or a fully-qualified topic name.
130
+ # @param [String] project The alternate project ID can be specified here.
131
+ # Optional. Not used if a fully-qualified topic name is provided
132
+ # for `topic_name`.
133
+ # @param [Hash] async A hash of values to configure the topic's
134
+ # {AsyncPublisher} that is created when {Publisher#publish_async}
135
+ # is called. Optional.
136
+ # @param [Boolean] skip_lookup Optionally create a {Publisher} object
137
+ # without verifying the topic resource exists on the Pub/Sub
138
+ # service. Calls made on this object will raise errors if the service
139
+ # resource does not exist. Default is `false`.
438
140
  #
439
- # snapshots = pubsub.snapshots
440
- # snapshots.all do |snapshot|
441
- # puts snapshot.name
442
- # end
141
+ # @return [Google::Cloud::PubSub::Publisher]
443
142
  #
444
- def snapshots token: nil, max: nil
143
+ def publisher topic_name, project: nil, async: nil, skip_lookup: nil
445
144
  ensure_service!
446
- options = { token: token, max: max }
447
- grpc = service.list_snapshots options
448
- Snapshot::List.from_grpc grpc, service, max
145
+ options = { project: project, async: async }
146
+ return Publisher.from_name topic_name, service, options if skip_lookup
147
+ grpc = topic_admin.get_topic topic: service.topic_path(topic_name, options)
148
+ Publisher.from_grpc grpc, service, async: async
449
149
  end
450
- alias find_snapshots snapshots
451
- alias list_snapshots snapshots
452
150
 
453
151
  ##
454
- # Retrieves schema by name.
455
- #
456
- # @param [String] schema_name Name of a schema. The value can
457
- # be a simple schema ID, in which case the current project ID
458
- # will be supplied, or a fully-qualified schema name in the form
459
- # `projects/{project_id}/schemas/{schema_id}`.
460
- # @param view [Symbol, String, nil] Possible values:
461
- # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
462
- # * `FULL` - Include all Schema object fields.
152
+ # Retrieves a Subscriber by subscription name or full project path.
463
153
  #
464
- # The default value is `FULL`.
465
- # @param [String] project If the schema belongs to a project other
466
- # than the one currently connected to, the alternate project ID can be
467
- # specified here. Not used if a fully-qualified schema name is
468
- # provided for `schema_name`.
469
- # @param [Boolean] skip_lookup Optionally create a {Schema} object
470
- # without verifying the schema resource exists on the Pub/Sub
154
+ # @param [String] subscription_name Name of a subscription. The value can
155
+ # be a simple subscription ID (relative name) or a fully-qualified
156
+ # subscription name.
157
+ # @param [String] project The alternate project ID can be specified here.
158
+ # Optional. Not used if a fully-qualified topic name is provided
159
+ # for `topic_name`.
160
+ # @param [Boolean] skip_lookup Optionally create a {Google::Cloud::PubSub::V1::Subscription}
161
+ # object without verifying the subscription resource exists on the Pub/Sub
471
162
  # service. Calls made on this object will raise errors if the service
472
163
  # resource does not exist. Default is `false`.
473
164
  #
474
- # @return [Google::Cloud::PubSub::Schema, nil] Returns `nil` if
475
- # the schema does not exist.
476
- #
477
- # @example
478
- # require "google/cloud/pubsub"
479
- #
480
- # pubsub = Google::Cloud::PubSub.new
481
- #
482
- # schema = pubsub.schema "my-schema"
483
- # schema.name #=> "projects/my-project/schemas/my-schema"
484
- # schema.type #=> :PROTOCOL_BUFFER
485
- # schema.definition # The schema definition
486
- #
487
- # @example Skip the lookup against the service with `skip_lookup`:
488
- # require "google/cloud/pubsub"
489
- #
490
- # pubsub = Google::Cloud::PubSub.new
165
+ # @return [Google::Cloud::PubSub::Subscriber, nil] Returns `nil` if
166
+ # the subscription does not exist.
491
167
  #
492
- # # No API call is made to retrieve the schema information.
493
- # # The default project is used in the name.
494
- # schema = pubsub.schema "my-schema", skip_lookup: true
495
- # schema.name #=> "projects/my-project/schemas/my-schema"
496
- # schema.type #=> nil
497
- # schema.definition #=> nil
498
- #
499
- # @example Omit the schema definition with `view: :basic`:
500
- # require "google/cloud/pubsub"
501
- #
502
- # pubsub = Google::Cloud::PubSub.new
503
- #
504
- # schema = pubsub.schema "my-schema", view: :basic
505
- # schema.name #=> "projects/my-project/schemas/my-schema"
506
- # schema.type #=> :PROTOCOL_BUFFER
507
- # schema.definition #=> nil
508
- #
509
- def schema schema_name, view: nil, project: nil, skip_lookup: nil
168
+ def subscriber subscription_name, project: nil, skip_lookup: nil
510
169
  ensure_service!
511
170
  options = { project: project }
512
- return Schema.from_name schema_name, view, service, options if skip_lookup
513
- view ||= :FULL
514
- grpc = service.get_schema schema_name, view, options
515
- Schema.from_grpc grpc, service
516
- rescue Google::Cloud::NotFoundError
517
- nil
171
+ return Subscriber.from_name subscription_name, service, options if skip_lookup
172
+ grpc = subscription_admin.get_subscription subscription: service.subscription_path(subscription_name, options)
173
+ Subscriber.from_grpc grpc, service
518
174
  end
519
- alias get_schema schema
520
- alias find_schema schema
521
175
 
522
176
  ##
523
- # Creates a new schema.
524
- #
525
- # @param [String] schema_id The ID to use for the schema, which will
526
- # become the final component of the schema's resource name. Required.
527
- #
528
- # The schema ID (relative name) must start with a letter, and
529
- # contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
530
- # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
531
- # signs (`%`). It must be between 3 and 255 characters in length, and
532
- # it must not start with `goog`.
533
- # @param [String, Symbol] type The type of the schema. Required. Possible
534
- # values are case-insensitive and include:
535
- #
536
- # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
537
- # * `AVRO` - An Avro schema definition.
538
- # @param [String] definition The definition of the schema. Required. This
539
- # should be a string representing the full definition of the schema that
540
- # is a valid schema definition of the type specified in `type`.
541
- # @param [String] project If the schema belongs to a project other
542
- # than the one currently connected to, the alternate project ID can be
543
- # specified here. Optional.
544
- #
545
- # @return [Google::Cloud::PubSub::Schema]
177
+ # Returns a fully-qualified project path in the form of
178
+ # `projects/{project_id}`
179
+ # @param [String] project_name A project name. Optional.
180
+ # If provided, this will be used in place of the default `project_id`.
546
181
  #
547
- # @example
548
- # require "google/cloud/pubsub"
549
- #
550
- # pubsub = Google::Cloud::PubSub.new
551
- #
552
- # definition = "..."
553
- # schema = pubsub.create_schema "my-schema", :avro, definition
554
- # schema.name #=> "projects/my-project/schemas/my-schema"
555
- #
556
- def create_schema schema_id, type, definition, project: nil
557
- ensure_service!
558
- type = type.to_s.upcase
559
- grpc = service.create_schema schema_id, type, definition, project: project
560
- Schema.from_grpc grpc, service
182
+ def project_path project_name: nil
183
+ service.project_path options: { "project" => project_name }.compact
561
184
  end
562
- alias new_schema create_schema
563
185
 
564
186
  ##
565
- # Retrieves a list of schemas for the given project.
566
- #
567
- # @param view [String, Symbol, nil] The set of fields to return in the response. Possible values:
568
- #
569
- # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
570
- # * `FULL` - Include all Schema object fields.
571
- #
572
- # The default value is `FULL`.
573
- # @param [String] token A previously-returned page token representing
574
- # part of the larger set of results to view.
575
- # @param [Integer] max Maximum number of schemas to return.
576
- #
577
- # @return [Array<Google::Cloud::PubSub::Schema>] (See
578
- # {Google::Cloud::PubSub::Schema::List})
579
- #
580
- # @example
581
- # require "google/cloud/pubsub"
582
- #
583
- # pubsub = Google::Cloud::PubSub.new
584
- #
585
- # schemas = pubsub.schemas
586
- # schemas.each do |schema|
587
- # puts schema.name
588
- # end
589
- #
590
- # @example Retrieve all schemas: (See {Schema::List#all})
591
- # require "google/cloud/pubsub"
592
- #
593
- # pubsub = Google::Cloud::PubSub.new
594
- #
595
- # schemas = pubsub.schemas
596
- # schemas.all do |schema|
597
- # puts schema.name
598
- # end
599
- #
600
- def schemas view: nil, token: nil, max: nil
601
- ensure_service!
602
- view ||= :FULL
603
- options = { token: token, max: max }
604
- grpc = service.list_schemas view, options
605
- Schema::List.from_grpc grpc, service, view, max
187
+ # Returns a fully-qualified topic path in the form of
188
+ # `projects/{project_id}/topics/{topic_name}`
189
+ # @param [String] topic_name A topic name.
190
+ # @param [String] project_name A project name. Optional.
191
+ # If provided, this will be used in place of the default `project_id`.
192
+ #
193
+ def topic_path topic_name, project_name: nil
194
+ service.topic_path topic_name, options: { "project" => project_name }.compact
606
195
  end
607
- alias find_schemas schemas
608
- alias list_schemas schemas
609
196
 
610
197
  ##
611
- # Validates a schema type and definition.
612
- #
613
- # @param [String, Symbol] type The type of the schema. Required. Possible
614
- # values are case-insensitive and include:
615
- #
616
- # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
617
- # * `AVRO` - An Avro schema definition.
618
- # @param [String] definition The definition of the schema. Required. This
619
- # should be a string representing the full definition of the schema that
620
- # is a valid schema definition of the type specified in `type`.
621
- # @param [String] project If the schema belongs to a project other
622
- # than the one currently connected to, the alternate project ID can be
623
- # specified here. Optional.
624
- #
625
- # @return [Boolean] `true` if the schema is valid, `false` otherwise.
626
- #
627
- # @example
628
- # require "google/cloud/pubsub"
629
- #
630
- # pubsub = Google::Cloud::PubSub.new
631
- #
632
- # definition = "..."
633
- # pubsub.validate_schema :avro, definition #=> true
634
- #
635
- def valid_schema? type, definition, project: nil
636
- ensure_service!
637
- type = type.to_s.upcase
638
- service.validate_schema type, definition, project: project # return type is empty
639
- true
640
- rescue Google::Cloud::InvalidArgumentError
641
- false
198
+ # Returns a fully-qualified subscription path in the form of
199
+ # `projects/{project_id}/subscriptions/{subscription_name}`
200
+ # @param [String] subscription_name A subscription name.
201
+ # @param [String] project_name A project name. Optional.
202
+ # If provided, this will be used in place of the default `project_id`.
203
+ #
204
+ def subscription_path subscription_name, project_name: nil
205
+ service.subscription_path subscription_name, options: { "project" => project_name }.compact
206
+ end
207
+
208
+ ##
209
+ # Returns a fully-qualified snapshot path in the form of
210
+ # `projects/{project_id}/snapshots/{snapshot_name}`
211
+ # @param [String] snapshot_name A snapshot name.
212
+ # @param [String] project_name A project name. Optional.
213
+ # If provided, this will be used in place of the default `project_id`.
214
+ #
215
+ def snapshot_path snapshot_name, project_name: nil
216
+ service.snapshot_path snapshot_name, options: { "project" => project_name }.compact
217
+ end
218
+
219
+ ##
220
+ # Returns a fully-qualified schema path in the form of
221
+ # `projects/{project_id}/schemas/{schema_name}`
222
+ # @param [String] schema_name A schema name.
223
+ # @param [String] project_name A project name. Optional.
224
+ # If provided, this will be used in place of the default `project_id`.
225
+ #
226
+ def schema_path schema_name, project_name: nil
227
+ service.schema_path schema_name, options: { "project" => project_name }.compact
642
228
  end
643
- alias validate_schema valid_schema?
644
229
 
645
230
  protected
646
231