google-cloud-pubsub 2.2.0 → 2.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/CONTRIBUTING.md +2 -2
- data/LOGGING.md +1 -1
- data/lib/google/cloud/pubsub/async_publisher.rb +9 -5
- data/lib/google/cloud/pubsub/async_publisher/batch.rb +2 -1
- data/lib/google/cloud/pubsub/credentials.rb +1 -1
- data/lib/google/cloud/pubsub/policy.rb +3 -2
- data/lib/google/cloud/pubsub/project.rb +252 -18
- data/lib/google/cloud/pubsub/retry_policy.rb +2 -4
- data/lib/google/cloud/pubsub/schema.rb +310 -0
- data/lib/google/cloud/pubsub/schema/list.rb +180 -0
- data/lib/google/cloud/pubsub/service.rb +147 -32
- data/lib/google/cloud/pubsub/snapshot.rb +5 -2
- data/lib/google/cloud/pubsub/snapshot/list.rb +2 -2
- data/lib/google/cloud/pubsub/subscriber.rb +21 -3
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +10 -3
- data/lib/google/cloud/pubsub/subscriber/stream.rb +3 -3
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +6 -7
- data/lib/google/cloud/pubsub/subscription.rb +35 -18
- data/lib/google/cloud/pubsub/subscription/list.rb +2 -2
- data/lib/google/cloud/pubsub/topic.rb +95 -16
- data/lib/google/cloud/pubsub/topic/list.rb +2 -2
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a75b823e392ec6afe50d693ae28a42833c2b40f06e8fa8311dff1cbafcc2df
|
4
|
+
data.tar.gz: d1caf14295648c05ac0f067832f1c7c8c51ee8638da47c49d3d5af6ad26ce23f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82745cfef6ebc3a5dae4bb44168660c6525ea2a2cac5d16f0087b8791d472a2d3eff5961627bf0ae7701a7f731715a21049b2da80ab551516c8e8da98aa31e6c
|
7
|
+
data.tar.gz: e9e2671fcf438f9cc5e7a5baa7cba1a1bb44fa5955bcad7a8ebaaffa111391457ea4d218a173c8f67b6a327e5f622406c20bd223c4799a5720008a5a99eda3c6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,54 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.5.0 / 2021-04-01
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Add Schema support
|
8
|
+
* Add Schema
|
9
|
+
* Add Project#create_schema
|
10
|
+
* Add Project#schema
|
11
|
+
* Add Project#schemas (Schema::List)
|
12
|
+
* Add Project#valid_schema?
|
13
|
+
* Add schema options to Project#create_topic
|
14
|
+
* Add Topic#schema_name
|
15
|
+
* Add Topic#message_encoding
|
16
|
+
* Add Topic#message_encoding_binary?
|
17
|
+
* Add Topic#message_encoding_json?
|
18
|
+
|
19
|
+
### 2.4.0 / 2021-03-10
|
20
|
+
|
21
|
+
#### Features
|
22
|
+
|
23
|
+
* Drop support for Ruby 2.4 and add support for Ruby 3.0
|
24
|
+
|
25
|
+
### 2.3.2 / 2021-02-08
|
26
|
+
|
27
|
+
#### Bug Fixes
|
28
|
+
|
29
|
+
* Fix project option in Project#topic and Project#subscription
|
30
|
+
* Ensure that project option is used when skip_lookup is false.
|
31
|
+
* Improve documentation of topic_name, subscription_name and snapshot_name.
|
32
|
+
|
33
|
+
### 2.3.1 / 2021-01-13
|
34
|
+
|
35
|
+
#### Bug Fixes
|
36
|
+
|
37
|
+
* Update Subscription#retry_policy=
|
38
|
+
* Remove conditional RPC to fetch full resource before update.
|
39
|
+
|
40
|
+
### 2.3.0 / 2020-11-18
|
41
|
+
|
42
|
+
#### Features
|
43
|
+
|
44
|
+
* Add inventory.use_legacy_flow_control to listen options
|
45
|
+
* Add inventory.use_legacy_flow_control to Subscription#listen options
|
46
|
+
* Add Subscriber#use_legacy_flow_control?
|
47
|
+
|
48
|
+
#### Documentation
|
49
|
+
|
50
|
+
* Remove EXPERIMENTAL label from RetryPolicy docs
|
51
|
+
|
3
52
|
### 2.2.0 / 2020-11-11
|
4
53
|
|
5
54
|
#### Features
|
data/CONTRIBUTING.md
CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
|
|
24
24
|
In order to use the google-cloud-pubsub console and run the project's tests,
|
25
25
|
there is a small amount of setup:
|
26
26
|
|
27
|
-
1. Install Ruby. google-cloud-pubsub requires Ruby 2.
|
27
|
+
1. Install Ruby. google-cloud-pubsub requires Ruby 2.5+. You may choose to
|
28
28
|
manage your Ruby and gem installations with [RVM](https://rvm.io/),
|
29
29
|
[rbenv](https://github.com/rbenv/rbenv), or
|
30
30
|
[chruby](https://github.com/postmodern/chruby).
|
@@ -45,7 +45,7 @@ there is a small amount of setup:
|
|
45
45
|
|
46
46
|
```sh
|
47
47
|
$ cd google-cloud-pubsub/
|
48
|
-
$ bundle
|
48
|
+
$ bundle install
|
49
49
|
```
|
50
50
|
|
51
51
|
## Console
|
data/LOGGING.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
To enable logging for this library, set the logger for the underlying
|
4
4
|
[gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
|
5
5
|
that you set may be a Ruby stdlib
|
6
|
-
[`Logger`](https://ruby-doc.org/stdlib
|
6
|
+
[`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
|
7
7
|
shown below, or a
|
8
8
|
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
9
9
|
that will write logs to [Stackdriver
|
@@ -44,8 +44,8 @@ module Google
|
|
44
44
|
#
|
45
45
|
# topic.async_publisher.stop!
|
46
46
|
#
|
47
|
-
# @attr_reader [String] topic_name The name of the topic the messages are published to.
|
48
|
-
#
|
47
|
+
# @attr_reader [String] topic_name The name of the topic the messages are published to. The value is a
|
48
|
+
# fully-qualified topic name in the form `projects/{project_id}/topics/{topic_id}`.
|
49
49
|
# @attr_reader [Integer] max_bytes The maximum size of messages to be collected before the batch is published.
|
50
50
|
# Default is 1,000,000 (1MB).
|
51
51
|
# @attr_reader [Integer] max_messages The maximum number of messages to be collected before the batch is
|
@@ -59,8 +59,12 @@ module Google
|
|
59
59
|
class AsyncPublisher
|
60
60
|
include MonitorMixin
|
61
61
|
|
62
|
-
attr_reader :topic_name
|
63
|
-
|
62
|
+
attr_reader :topic_name
|
63
|
+
attr_reader :max_bytes
|
64
|
+
attr_reader :max_messages
|
65
|
+
attr_reader :interval
|
66
|
+
attr_reader :publish_threads
|
67
|
+
attr_reader :callback_threads
|
64
68
|
##
|
65
69
|
# @private Implementation accessors
|
66
70
|
attr_reader :service, :batch, :publish_thread_pool,
|
@@ -303,7 +307,7 @@ module Google
|
|
303
307
|
|
304
308
|
def publish_batches! stop: nil
|
305
309
|
@batches.reject! { |_ordering_key, batch| batch.empty? }
|
306
|
-
@batches.
|
310
|
+
@batches.each_value do |batch|
|
307
311
|
ready = batch.publish! stop: stop
|
308
312
|
publish_batch_async @topic_name, batch if ready
|
309
313
|
end
|
@@ -68,7 +68,8 @@ module Google
|
|
68
68
|
# end
|
69
69
|
#
|
70
70
|
class Policy
|
71
|
-
attr_reader :etag
|
71
|
+
attr_reader :etag
|
72
|
+
attr_reader :roles
|
72
73
|
|
73
74
|
##
|
74
75
|
# @private Creates a Policy object.
|
@@ -167,7 +168,7 @@ module Google
|
|
167
168
|
role: role_name,
|
168
169
|
members: roles[role_name]
|
169
170
|
)
|
170
|
-
end
|
171
|
+
end.compact
|
171
172
|
)
|
172
173
|
end
|
173
174
|
|
@@ -18,6 +18,7 @@ require "google/cloud/pubsub/service"
|
|
18
18
|
require "google/cloud/pubsub/credentials"
|
19
19
|
require "google/cloud/pubsub/topic"
|
20
20
|
require "google/cloud/pubsub/batch_publisher"
|
21
|
+
require "google/cloud/pubsub/schema"
|
21
22
|
require "google/cloud/pubsub/snapshot"
|
22
23
|
|
23
24
|
module Google
|
@@ -75,10 +76,14 @@ module Google
|
|
75
76
|
##
|
76
77
|
# Retrieves topic by name.
|
77
78
|
#
|
78
|
-
# @param [String] topic_name Name of a topic.
|
79
|
+
# @param [String] topic_name Name of a topic. The value can be a simple
|
80
|
+
# topic ID (relative name), in which case the current project ID will
|
81
|
+
# be supplied, or a fully-qualified topic name in the form
|
82
|
+
# `projects/{project_id}/topics/{topic_id}`.
|
79
83
|
# @param [String] project If the topic belongs to a project other than
|
80
84
|
# the one currently connected to, the alternate project ID can be
|
81
|
-
# specified here. Optional.
|
85
|
+
# specified here. Optional. Not used if a fully-qualified topic name
|
86
|
+
# is provided for `topic_name`.
|
82
87
|
# @param [Boolean] skip_lookup Optionally create a {Topic} object
|
83
88
|
# without verifying the topic resource exists on the Pub/Sub service.
|
84
89
|
# Calls made on this object will raise errors if the topic resource
|
@@ -147,7 +152,7 @@ module Google
|
|
147
152
|
ensure_service!
|
148
153
|
options = { project: project }
|
149
154
|
return Topic.from_name topic_name, service, options if skip_lookup
|
150
|
-
grpc = service.get_topic topic_name
|
155
|
+
grpc = service.get_topic topic_name, options
|
151
156
|
Topic.from_grpc grpc, service, async: async
|
152
157
|
rescue Google::Cloud::NotFoundError
|
153
158
|
nil
|
@@ -158,7 +163,16 @@ module Google
|
|
158
163
|
##
|
159
164
|
# Creates a new topic.
|
160
165
|
#
|
161
|
-
# @param [String] topic_name Name of a topic.
|
166
|
+
# @param [String] topic_name Name of a topic. Required.
|
167
|
+
# The value can be a simple topic ID (relative name), in which
|
168
|
+
# case the current project ID will be supplied, or a fully-qualified
|
169
|
+
# topic name in the form `projects/{project_id}/topics/{topic_id}`.
|
170
|
+
#
|
171
|
+
# The topic ID (relative name) must start with a letter, and
|
172
|
+
# contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
|
173
|
+
# underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
|
174
|
+
# signs (`%`). It must be between 3 and 255 characters in length, and
|
175
|
+
# it must not start with `goog`.
|
162
176
|
# @param [Hash] labels A hash of user-provided labels associated with
|
163
177
|
# the topic. You can use these to organize and group your topics.
|
164
178
|
# Label keys and values can be no longer than 63 characters, can only
|
@@ -179,15 +193,31 @@ module Google
|
|
179
193
|
#
|
180
194
|
# Hash keys and values may include the following:
|
181
195
|
#
|
182
|
-
# * `:max_bytes` (Integer) The maximum size of messages to be collected
|
183
|
-
# is 1,000,000 (1MB).
|
184
|
-
# * `:max_messages` (Integer) The maximum number of messages to be
|
185
|
-
# Default is 100.
|
186
|
-
# * `:interval` (Numeric) The number of seconds to collect messages before
|
187
|
-
# 0.01.
|
188
|
-
# * `:threads` (Hash) The number of threads to create to handle concurrent
|
189
|
-
#
|
190
|
-
#
|
196
|
+
# * `:max_bytes` (Integer) The maximum size of messages to be collected
|
197
|
+
# before the batch is published. Default is 1,000,000 (1MB).
|
198
|
+
# * `:max_messages` (Integer) The maximum number of messages to be
|
199
|
+
# collected before the batch is published. Default is 100.
|
200
|
+
# * `:interval` (Numeric) The number of seconds to collect messages before
|
201
|
+
# the batch is published. Default is 0.01.
|
202
|
+
# * `:threads` (Hash) The number of threads to create to handle concurrent
|
203
|
+
# calls by the publisher:
|
204
|
+
#
|
205
|
+
# * `:publish` (Integer) The number of threads used to publish messages.
|
206
|
+
# Default is 2.
|
207
|
+
# * `:callback` (Integer) The number of threads to handle the published
|
208
|
+
# messages' callbacks. Default is 4.
|
209
|
+
# @param [String] schema_name The name of the schema that messages
|
210
|
+
# published should be validated against. Optional. The value can be a
|
211
|
+
# simple schema ID (relative name), in which case the current project
|
212
|
+
# ID will be supplied, or a fully-qualified schema name in the form
|
213
|
+
# `projects/{project_id}/schemas/{schema_id}`. If provided,
|
214
|
+
# `message_encoding` must also be provided.
|
215
|
+
# @param [String, Symbol] message_encoding The encoding of messages validated
|
216
|
+
# against the schema identified by `schema_name`. Optional. Values include:
|
217
|
+
#
|
218
|
+
# * `JSON` - JSON encoding.
|
219
|
+
# * `BINARY` - Binary encoding, as defined by the schema type. For some
|
220
|
+
# schema types, binary encoding may not be available.
|
191
221
|
#
|
192
222
|
# @return [Google::Cloud::PubSub::Topic]
|
193
223
|
#
|
@@ -197,12 +227,20 @@ module Google
|
|
197
227
|
# pubsub = Google::Cloud::PubSub.new
|
198
228
|
# topic = pubsub.create_topic "my-topic"
|
199
229
|
#
|
200
|
-
def create_topic topic_name,
|
230
|
+
def create_topic topic_name,
|
231
|
+
labels: nil,
|
232
|
+
kms_key: nil,
|
233
|
+
persistence_regions: nil,
|
234
|
+
async: nil,
|
235
|
+
schema_name: nil,
|
236
|
+
message_encoding: nil
|
201
237
|
ensure_service!
|
202
238
|
grpc = service.create_topic topic_name,
|
203
239
|
labels: labels,
|
204
240
|
kms_key_name: kms_key,
|
205
|
-
persistence_regions: persistence_regions
|
241
|
+
persistence_regions: persistence_regions,
|
242
|
+
schema_name: schema_name,
|
243
|
+
message_encoding: message_encoding
|
206
244
|
Topic.from_grpc grpc, service, async: async
|
207
245
|
end
|
208
246
|
alias new_topic create_topic
|
@@ -250,10 +288,14 @@ module Google
|
|
250
288
|
##
|
251
289
|
# Retrieves subscription by name.
|
252
290
|
#
|
253
|
-
# @param [String] subscription_name Name of a subscription.
|
291
|
+
# @param [String] subscription_name Name of a subscription. The value can
|
292
|
+
# be a simple subscription ID, in which case the current project ID
|
293
|
+
# will be supplied, or a fully-qualified subscription name in the form
|
294
|
+
# `projects/{project_id}/subscriptions/{subscription_id}`.
|
254
295
|
# @param [String] project If the subscription belongs to a project other
|
255
296
|
# than the one currently connected to, the alternate project ID can be
|
256
|
-
# specified here.
|
297
|
+
# specified here. Not used if a fully-qualified subscription name is
|
298
|
+
# provided for `subscription_name`.
|
257
299
|
# @param [Boolean] skip_lookup Optionally create a {Subscription} object
|
258
300
|
# without verifying the subscription resource exists on the Pub/Sub
|
259
301
|
# service. Calls made on this object will raise errors if the service
|
@@ -283,7 +325,7 @@ module Google
|
|
283
325
|
ensure_service!
|
284
326
|
options = { project: project }
|
285
327
|
return Subscription.from_name subscription_name, service, options if skip_lookup
|
286
|
-
grpc = service.get_subscription subscription_name
|
328
|
+
grpc = service.get_subscription subscription_name, options
|
287
329
|
Subscription.from_grpc grpc, service
|
288
330
|
rescue Google::Cloud::NotFoundError
|
289
331
|
nil
|
@@ -370,6 +412,198 @@ module Google
|
|
370
412
|
alias find_snapshots snapshots
|
371
413
|
alias list_snapshots snapshots
|
372
414
|
|
415
|
+
##
|
416
|
+
# Retrieves schema by name.
|
417
|
+
#
|
418
|
+
# @param [String] schema_name Name of a schema. The value can
|
419
|
+
# be a simple schema ID, in which case the current project ID
|
420
|
+
# will be supplied, or a fully-qualified schema name in the form
|
421
|
+
# `projects/{project_id}/schemas/{schema_id}`.
|
422
|
+
# @param view [Symbol, String, nil] Possible values:
|
423
|
+
# * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
|
424
|
+
# * `FULL` - Include all Schema object fields.
|
425
|
+
#
|
426
|
+
# The default value is `BASIC`.
|
427
|
+
# @param [String] project If the schema belongs to a project other
|
428
|
+
# than the one currently connected to, the alternate project ID can be
|
429
|
+
# specified here. Not used if a fully-qualified schema name is
|
430
|
+
# provided for `schema_name`.
|
431
|
+
# @param [Boolean] skip_lookup Optionally create a {Schema} object
|
432
|
+
# without verifying the schema resource exists on the Pub/Sub
|
433
|
+
# service. Calls made on this object will raise errors if the service
|
434
|
+
# resource does not exist. Default is `false`.
|
435
|
+
#
|
436
|
+
# @return [Google::Cloud::PubSub::Schema, nil] Returns `nil` if
|
437
|
+
# the schema does not exist.
|
438
|
+
#
|
439
|
+
# @example
|
440
|
+
# require "google/cloud/pubsub"
|
441
|
+
#
|
442
|
+
# pubsub = Google::Cloud::PubSub.new
|
443
|
+
#
|
444
|
+
# schema = pubsub.schema "my-schema"
|
445
|
+
# schema.name #=> "projects/my-project/schemas/my-schema"
|
446
|
+
# schema.type #=> :PROTOCOL_BUFFER
|
447
|
+
# # schema.definition # nil - Use view: :full to load complete resource.
|
448
|
+
#
|
449
|
+
# @example Skip the lookup against the service with `skip_lookup`:
|
450
|
+
# require "google/cloud/pubsub"
|
451
|
+
#
|
452
|
+
# pubsub = Google::Cloud::PubSub.new
|
453
|
+
#
|
454
|
+
# # No API call is made to retrieve the schema information.
|
455
|
+
# # The default project is used in the name.
|
456
|
+
# schema = pubsub.schema "my-schema", skip_lookup: true
|
457
|
+
# schema.name #=> "projects/my-project/schemas/my-schema"
|
458
|
+
# schema.type #=> nil
|
459
|
+
# schema.definition #=> nil
|
460
|
+
#
|
461
|
+
# @example Get the schema definition with `view: :full`:
|
462
|
+
# require "google/cloud/pubsub"
|
463
|
+
#
|
464
|
+
# pubsub = Google::Cloud::PubSub.new
|
465
|
+
#
|
466
|
+
# schema = pubsub.schema "my-schema", view: :full
|
467
|
+
# schema.name #=> "projects/my-project/schemas/my-schema"
|
468
|
+
# schema.type #=> :PROTOCOL_BUFFER
|
469
|
+
# schema.definition # The schema definition
|
470
|
+
#
|
471
|
+
def schema schema_name, view: nil, project: nil, skip_lookup: nil
|
472
|
+
ensure_service!
|
473
|
+
options = { project: project }
|
474
|
+
return Schema.from_name schema_name, view, service, options if skip_lookup
|
475
|
+
view ||= :BASIC
|
476
|
+
grpc = service.get_schema schema_name, view, options
|
477
|
+
Schema.from_grpc grpc, service
|
478
|
+
rescue Google::Cloud::NotFoundError
|
479
|
+
nil
|
480
|
+
end
|
481
|
+
alias get_schema schema
|
482
|
+
alias find_schema schema
|
483
|
+
|
484
|
+
##
|
485
|
+
# Creates a new schema.
|
486
|
+
#
|
487
|
+
# @param [String] schema_id The ID to use for the schema, which will
|
488
|
+
# become the final component of the schema's resource name. Required.
|
489
|
+
#
|
490
|
+
# The schema ID (relative name) must start with a letter, and
|
491
|
+
# contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
|
492
|
+
# underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
|
493
|
+
# signs (`%`). It must be between 3 and 255 characters in length, and
|
494
|
+
# it must not start with `goog`.
|
495
|
+
# @param [String, Symbol] type The type of the schema. Required. Possible
|
496
|
+
# values are case-insensitive and include:
|
497
|
+
#
|
498
|
+
# * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
|
499
|
+
# * `AVRO` - An Avro schema definition.
|
500
|
+
# @param [String] definition The definition of the schema. Required. This
|
501
|
+
# should be a string representing the full definition of the schema that
|
502
|
+
# is a valid schema definition of the type specified in `type`.
|
503
|
+
# @param [String] project If the schema belongs to a project other
|
504
|
+
# than the one currently connected to, the alternate project ID can be
|
505
|
+
# specified here. Optional.
|
506
|
+
#
|
507
|
+
# @return [Google::Cloud::PubSub::Schema]
|
508
|
+
#
|
509
|
+
# @example
|
510
|
+
# require "google/cloud/pubsub"
|
511
|
+
#
|
512
|
+
# pubsub = Google::Cloud::PubSub.new
|
513
|
+
#
|
514
|
+
# definition = "..."
|
515
|
+
# schema = pubsub.create_schema "my-schema", :avro, definition
|
516
|
+
# schema.name #=> "projects/my-project/schemas/my-schema"
|
517
|
+
#
|
518
|
+
def create_schema schema_id, type, definition, project: nil
|
519
|
+
ensure_service!
|
520
|
+
type = type.to_s.upcase
|
521
|
+
grpc = service.create_schema schema_id, type, definition, project: project
|
522
|
+
Schema.from_grpc grpc, service
|
523
|
+
end
|
524
|
+
alias new_schema create_schema
|
525
|
+
|
526
|
+
##
|
527
|
+
# Retrieves a list of schemas for the given project.
|
528
|
+
#
|
529
|
+
# @param view [String, Symbol, nil] The set of fields to return in the response. Possible values:
|
530
|
+
#
|
531
|
+
# * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
|
532
|
+
# * `FULL` - Include all Schema object fields.
|
533
|
+
#
|
534
|
+
# The default value is `BASIC`.
|
535
|
+
# @param [String] token A previously-returned page token representing
|
536
|
+
# part of the larger set of results to view.
|
537
|
+
# @param [Integer] max Maximum number of schemas to return.
|
538
|
+
#
|
539
|
+
# @return [Array<Google::Cloud::PubSub::Schema>] (See
|
540
|
+
# {Google::Cloud::PubSub::Schema::List})
|
541
|
+
#
|
542
|
+
# @example
|
543
|
+
# require "google/cloud/pubsub"
|
544
|
+
#
|
545
|
+
# pubsub = Google::Cloud::PubSub.new
|
546
|
+
#
|
547
|
+
# schemas = pubsub.schemas
|
548
|
+
# schemas.each do |schema|
|
549
|
+
# puts schema.name
|
550
|
+
# end
|
551
|
+
#
|
552
|
+
# @example Retrieve all schemas: (See {Schema::List#all})
|
553
|
+
# require "google/cloud/pubsub"
|
554
|
+
#
|
555
|
+
# pubsub = Google::Cloud::PubSub.new
|
556
|
+
#
|
557
|
+
# schemas = pubsub.schemas
|
558
|
+
# schemas.all do |schema|
|
559
|
+
# puts schema.name
|
560
|
+
# end
|
561
|
+
#
|
562
|
+
def schemas view: nil, token: nil, max: nil
|
563
|
+
ensure_service!
|
564
|
+
view ||= :BASIC
|
565
|
+
options = { token: token, max: max }
|
566
|
+
grpc = service.list_schemas view, options
|
567
|
+
Schema::List.from_grpc grpc, service, view, max
|
568
|
+
end
|
569
|
+
alias find_schemas schemas
|
570
|
+
alias list_schemas schemas
|
571
|
+
|
572
|
+
##
|
573
|
+
# Validates a schema type and definition.
|
574
|
+
#
|
575
|
+
# @param [String, Symbol] type The type of the schema. Required. Possible
|
576
|
+
# values are case-insensitive and include:
|
577
|
+
#
|
578
|
+
# * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
|
579
|
+
# * `AVRO` - An Avro schema definition.
|
580
|
+
# @param [String] definition The definition of the schema. Required. This
|
581
|
+
# should be a string representing the full definition of the schema that
|
582
|
+
# is a valid schema definition of the type specified in `type`.
|
583
|
+
# @param [String] project If the schema belongs to a project other
|
584
|
+
# than the one currently connected to, the alternate project ID can be
|
585
|
+
# specified here. Optional.
|
586
|
+
#
|
587
|
+
# @return [Boolean] `true` if the schema is valid, `false` otherwise.
|
588
|
+
#
|
589
|
+
# @example
|
590
|
+
# require "google/cloud/pubsub"
|
591
|
+
#
|
592
|
+
# pubsub = Google::Cloud::PubSub.new
|
593
|
+
#
|
594
|
+
# definition = "..."
|
595
|
+
# pubsub.validate_schema :avro, definition #=> true
|
596
|
+
#
|
597
|
+
def valid_schema? type, definition, project: nil
|
598
|
+
ensure_service!
|
599
|
+
type = type.to_s.upcase
|
600
|
+
service.validate_schema type, definition, project: project # return type is empty
|
601
|
+
true
|
602
|
+
rescue Google::Cloud::InvalidArgumentError
|
603
|
+
false
|
604
|
+
end
|
605
|
+
alias validate_schema valid_schema?
|
606
|
+
|
373
607
|
protected
|
374
608
|
|
375
609
|
##
|