google-cloud-pubsub 2.3.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/CONTRIBUTING.md +4 -5
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +9 -6
- 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/batch_publisher.rb +31 -30
- 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 -1
- 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 +7 -2
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +6 -2
- data/lib/google/cloud/pubsub/subscriber/stream.rb +1 -1
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +6 -7
- data/lib/google/cloud/pubsub/subscription.rb +60 -38
- data/lib/google/cloud/pubsub/subscription/list.rb +2 -2
- data/lib/google/cloud/pubsub/topic.rb +114 -16
- data/lib/google/cloud/pubsub/topic/list.rb +2 -2
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +22 -6
@@ -130,12 +130,12 @@ module Google
|
|
130
130
|
# puts subscription.name
|
131
131
|
# end
|
132
132
|
#
|
133
|
-
def all request_limit: nil
|
133
|
+
def all request_limit: nil, &block
|
134
134
|
request_limit = request_limit.to_i if request_limit
|
135
135
|
return enum_for :all, request_limit: request_limit unless block_given?
|
136
136
|
results = self
|
137
137
|
loop do
|
138
|
-
results.each
|
138
|
+
results.each(&block)
|
139
139
|
if request_limit
|
140
140
|
request_limit -= 1
|
141
141
|
break if request_limit.negative?
|
@@ -85,10 +85,10 @@ module Google
|
|
85
85
|
end
|
86
86
|
|
87
87
|
##
|
88
|
-
# The name of the topic
|
89
|
-
# "/projects/project-identifier/topics/topic-name".
|
88
|
+
# The name of the topic.
|
90
89
|
#
|
91
|
-
# @return [String]
|
90
|
+
# @return [String] A fully-qualified topic name in the form
|
91
|
+
# `projects/{project_id}/topics/{topic_id}`.
|
92
92
|
#
|
93
93
|
def name
|
94
94
|
return @resource_name if reference?
|
@@ -233,6 +233,78 @@ module Google
|
|
233
233
|
@resource_name = nil
|
234
234
|
end
|
235
235
|
|
236
|
+
##
|
237
|
+
# The name of the schema that messages published should be validated against, if schema settings are configured
|
238
|
+
# for the topic. The value is a fully-qualified schema name in the form
|
239
|
+
# `projects/{project_id}/schemas/{schema_id}`. If present, {#message_encoding} should also be present. The value
|
240
|
+
# of this field will be `_deleted-schema_` if the schema has been deleted.
|
241
|
+
#
|
242
|
+
# Makes an API call to retrieve the schema settings when called on a reference object. See {#reference?}.
|
243
|
+
#
|
244
|
+
# @return [String, nil] The schema name, or `nil` if schema settings are not configured for the topic.
|
245
|
+
#
|
246
|
+
# @example
|
247
|
+
# require "google/cloud/pubsub"
|
248
|
+
#
|
249
|
+
# pubsub = Google::Cloud::PubSub.new
|
250
|
+
#
|
251
|
+
# topic = pubsub.topic "my-topic"
|
252
|
+
#
|
253
|
+
# topic.schema_name #=> "projects/my-project/schemas/my-schema"
|
254
|
+
#
|
255
|
+
def schema_name
|
256
|
+
ensure_grpc!
|
257
|
+
@grpc.schema_settings&.schema
|
258
|
+
end
|
259
|
+
|
260
|
+
##
|
261
|
+
# The encoding of messages validated against the schema identified by {#schema_name}. If present, {#schema_name}
|
262
|
+
# should also be present. Values include:
|
263
|
+
#
|
264
|
+
# * `JSON` - JSON encoding.
|
265
|
+
# * `BINARY` - Binary encoding, as defined by the schema type. For some schema types, binary encoding may not be
|
266
|
+
# available.
|
267
|
+
#
|
268
|
+
# Makes an API call to retrieve the schema settings when called on a reference object. See {#reference?}.
|
269
|
+
#
|
270
|
+
# @return [Symbol, nil] The schema encoding, or `nil` if schema settings are not configured for the topic.
|
271
|
+
#
|
272
|
+
# @example
|
273
|
+
# require "google/cloud/pubsub"
|
274
|
+
#
|
275
|
+
# pubsub = Google::Cloud::PubSub.new
|
276
|
+
#
|
277
|
+
# topic = pubsub.topic "my-topic"
|
278
|
+
#
|
279
|
+
# topic.message_encoding #=> :JSON
|
280
|
+
#
|
281
|
+
def message_encoding
|
282
|
+
ensure_grpc!
|
283
|
+
@grpc.schema_settings&.encoding
|
284
|
+
end
|
285
|
+
|
286
|
+
##
|
287
|
+
# Checks if the encoding of messages in the schema settings is `BINARY`. See {#message_encoding}.
|
288
|
+
#
|
289
|
+
# Makes an API call to retrieve the schema settings when called on a reference object. See {#reference?}.
|
290
|
+
#
|
291
|
+
# @return [Boolean] `true` when `BINARY`, `false` if not `BINARY` or schema settings is not set.
|
292
|
+
#
|
293
|
+
def message_encoding_binary?
|
294
|
+
message_encoding.to_s.upcase == "BINARY"
|
295
|
+
end
|
296
|
+
|
297
|
+
##
|
298
|
+
# Checks if the encoding of messages in the schema settings is `JSON`. See {#message_encoding}.
|
299
|
+
#
|
300
|
+
# Makes an API call to retrieve the schema settings when called on a reference object. See {#reference?}.
|
301
|
+
#
|
302
|
+
# @return [Boolean] `true` when `JSON`, `false` if not `JSON` or schema settings is not set.
|
303
|
+
#
|
304
|
+
def message_encoding_json?
|
305
|
+
message_encoding.to_s.upcase == "JSON"
|
306
|
+
end
|
307
|
+
|
236
308
|
##
|
237
309
|
# Permanently deletes the topic.
|
238
310
|
#
|
@@ -255,11 +327,17 @@ module Google
|
|
255
327
|
##
|
256
328
|
# Creates a new {Subscription} object on the current Topic.
|
257
329
|
#
|
258
|
-
# @param [String] subscription_name Name of the new subscription.
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
330
|
+
# @param [String] subscription_name Name of the new subscription. Required.
|
331
|
+
# The value can be a simple subscription ID (relative name), in which
|
332
|
+
# case the current project ID will be supplied, or a fully-qualified
|
333
|
+
# subscription name in the form
|
334
|
+
# `projects/{project_id}/subscriptions/{subscription_id}`.
|
335
|
+
#
|
336
|
+
# The subscription ID (relative name) must start with a letter, and
|
337
|
+
# contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
|
338
|
+
# underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
|
339
|
+
# signs (`%`). It must be between 3 and 255 characters in length, and
|
340
|
+
# it must not start with `goog`.
|
263
341
|
# @param [Integer] deadline The maximum number of seconds after a
|
264
342
|
# subscriber receives a message before the subscriber should
|
265
343
|
# acknowledge the message.
|
@@ -415,7 +493,11 @@ module Google
|
|
415
493
|
##
|
416
494
|
# Retrieves subscription by name.
|
417
495
|
#
|
418
|
-
# @param [String] subscription_name Name of a subscription.
|
496
|
+
# @param [String] subscription_name Name of a subscription. The value
|
497
|
+
# can be a simple subscription ID (relative name), in which case the
|
498
|
+
# current project ID will be supplied, or a fully-qualified
|
499
|
+
# subscription name in the form
|
500
|
+
# `projects/{project_id}/subscriptions/{subscription_id}`.
|
419
501
|
# @param [Boolean] skip_lookup Optionally create a {Subscription} object
|
420
502
|
# without verifying the subscription resource exists on the Pub/Sub
|
421
503
|
# service. Calls made on this object will raise errors if the service
|
@@ -506,6 +588,8 @@ module Google
|
|
506
588
|
# @param [String, File] data The message payload. This will be converted
|
507
589
|
# to bytes encoded as ASCII-8BIT.
|
508
590
|
# @param [Hash] attributes Optional attributes for the message.
|
591
|
+
# @param [String] ordering_key Identifies related messages for which
|
592
|
+
# publish order should be respected.
|
509
593
|
# @yield [batch] a block for publishing multiple messages in one
|
510
594
|
# request
|
511
595
|
# @yieldparam [BatchPublisher] batch the topic batch publisher
|
@@ -554,10 +638,24 @@ module Google
|
|
554
638
|
# t.publish "task 3 completed", foo: :bif
|
555
639
|
# end
|
556
640
|
#
|
557
|
-
|
641
|
+
# @example Ordered messages are supported using ordering_key:
|
642
|
+
# require "google/cloud/pubsub"
|
643
|
+
#
|
644
|
+
# pubsub = Google::Cloud::PubSub.new
|
645
|
+
#
|
646
|
+
# topic = pubsub.topic "my-ordered-topic"
|
647
|
+
#
|
648
|
+
# # Ensure that message ordering is enabled.
|
649
|
+
# topic.enable_message_ordering!
|
650
|
+
#
|
651
|
+
# # Publish an ordered message with an ordering key.
|
652
|
+
# topic.publish "task completed",
|
653
|
+
# ordering_key: "task-key"
|
654
|
+
#
|
655
|
+
def publish data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &block
|
558
656
|
ensure_service!
|
559
|
-
batch = BatchPublisher.new data, attributes
|
560
|
-
|
657
|
+
batch = BatchPublisher.new data, attributes, ordering_key, extra_attrs
|
658
|
+
block&.call batch
|
561
659
|
return nil if batch.messages.count.zero?
|
562
660
|
publish_batch_messages batch
|
563
661
|
end
|
@@ -667,7 +765,7 @@ module Google
|
|
667
765
|
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
|
668
766
|
ensure_service!
|
669
767
|
|
670
|
-
@async_publisher ||= AsyncPublisher.new name, service,
|
768
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
671
769
|
@async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
|
672
770
|
end
|
673
771
|
|
@@ -683,7 +781,7 @@ module Google
|
|
683
781
|
# {Subscription#listen}, and {Message#ordering_key}.
|
684
782
|
#
|
685
783
|
def enable_message_ordering!
|
686
|
-
@async_publisher ||= AsyncPublisher.new name, service,
|
784
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
687
785
|
@async_publisher.enable_message_ordering!
|
688
786
|
end
|
689
787
|
|
@@ -699,7 +797,7 @@ module Google
|
|
699
797
|
# @return [Boolean]
|
700
798
|
#
|
701
799
|
def message_ordering?
|
702
|
-
@async_publisher ||= AsyncPublisher.new name, service,
|
800
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
703
801
|
@async_publisher.message_ordering?
|
704
802
|
end
|
705
803
|
|
@@ -712,7 +810,7 @@ module Google
|
|
712
810
|
# @return [boolean] `true` when resumed, `false` otherwise.
|
713
811
|
#
|
714
812
|
def resume_publish ordering_key
|
715
|
-
@async_publisher ||= AsyncPublisher.new name, service,
|
813
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
716
814
|
@async_publisher.resume_publish ordering_key
|
717
815
|
end
|
718
816
|
|
@@ -124,12 +124,12 @@ module Google
|
|
124
124
|
# puts topic.name
|
125
125
|
# end
|
126
126
|
#
|
127
|
-
def all request_limit: nil
|
127
|
+
def all request_limit: nil, &block
|
128
128
|
request_limit = request_limit.to_i if request_limit
|
129
129
|
return enum_for :all, request_limit: request_limit unless block_given?
|
130
130
|
results = self
|
131
131
|
loop do
|
132
|
-
results.each
|
132
|
+
results.each(&block)
|
133
133
|
if request_limit
|
134
134
|
request_limit -= 1
|
135
135
|
break if request_limit.negative?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -67,20 +67,34 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: avro
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.10'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.10'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: google-style
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
88
|
- - "~>"
|
75
89
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.
|
90
|
+
version: 1.25.1
|
77
91
|
type: :development
|
78
92
|
prerelease: false
|
79
93
|
version_requirements: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
95
|
- - "~>"
|
82
96
|
- !ruby/object:Gem::Version
|
83
|
-
version: 1.
|
97
|
+
version: 1.25.1
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: minitest
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,6 +239,8 @@ files:
|
|
225
239
|
- lib/google/cloud/pubsub/publish_result.rb
|
226
240
|
- lib/google/cloud/pubsub/received_message.rb
|
227
241
|
- lib/google/cloud/pubsub/retry_policy.rb
|
242
|
+
- lib/google/cloud/pubsub/schema.rb
|
243
|
+
- lib/google/cloud/pubsub/schema/list.rb
|
228
244
|
- lib/google/cloud/pubsub/service.rb
|
229
245
|
- lib/google/cloud/pubsub/snapshot.rb
|
230
246
|
- lib/google/cloud/pubsub/snapshot/list.rb
|
@@ -252,14 +268,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
252
268
|
requirements:
|
253
269
|
- - ">="
|
254
270
|
- !ruby/object:Gem::Version
|
255
|
-
version: '2.
|
271
|
+
version: '2.5'
|
256
272
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
273
|
requirements:
|
258
274
|
- - ">="
|
259
275
|
- !ruby/object:Gem::Version
|
260
276
|
version: '0'
|
261
277
|
requirements: []
|
262
|
-
rubygems_version: 3.
|
278
|
+
rubygems_version: 3.2.13
|
263
279
|
signing_key:
|
264
280
|
specification_version: 4
|
265
281
|
summary: API Client library for Google Cloud Pub/Sub
|