google-cloud-pubsub 2.3.2 → 2.7.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.
@@ -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 { |r| yield r }
138
+ results.each(&block)
139
139
  if request_limit
140
140
  request_limit -= 1
141
141
  break if request_limit.negative?
@@ -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
  #
@@ -516,6 +588,8 @@ module Google
516
588
  # @param [String, File] data The message payload. This will be converted
517
589
  # to bytes encoded as ASCII-8BIT.
518
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.
519
593
  # @yield [batch] a block for publishing multiple messages in one
520
594
  # request
521
595
  # @yieldparam [BatchPublisher] batch the topic batch publisher
@@ -564,10 +638,24 @@ module Google
564
638
  # t.publish "task 3 completed", foo: :bif
565
639
  # end
566
640
  #
567
- def publish data = nil, attributes = {}
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
568
656
  ensure_service!
569
- batch = BatchPublisher.new data, attributes
570
- yield batch if block_given?
657
+ batch = BatchPublisher.new data, attributes, ordering_key, extra_attrs
658
+ block&.call batch
571
659
  return nil if batch.messages.count.zero?
572
660
  publish_batch_messages batch
573
661
  end
@@ -596,6 +684,11 @@ module Google
596
684
  # @note At the time of this release, ordering keys are not yet publicly
597
685
  # enabled and requires special project enablements.
598
686
  #
687
+ # Publisher flow control limits the number of outstanding messages that
688
+ # are allowed to wait to be published. See the `flow_control` key in the
689
+ # `async` parameter in {Project#topic} for more information about publisher
690
+ # flow control settings.
691
+ #
599
692
  # @param [String, File] data The message payload. This will be converted
600
693
  # to bytes encoded as ASCII-8BIT.
601
694
  # @param [Hash] attributes Optional attributes for the message.
@@ -615,6 +708,13 @@ module Google
615
708
  # message with an `ordering_key` that has already failed when
616
709
  # publishing. Use {#resume_publish} to allow this `ordering_key` to be
617
710
  # published again.
711
+ # @raise [Google::Cloud::PubSub::FlowControlLimitError] when publish flow
712
+ # control limits are exceeded, and the `async` parameter key
713
+ # `flow_control.limit_exceeded_behavior` is set to `:error` or `:block`.
714
+ # If `flow_control.limit_exceeded_behavior` is set to `:block`, this error
715
+ # will be raised only when a limit would be exceeded by a single message.
716
+ # See the `async` parameter in {Project#topic} for more information about
717
+ # `flow_control` settings.
618
718
  #
619
719
  # @example
620
720
  # require "google/cloud/pubsub"
@@ -677,7 +777,7 @@ module Google
677
777
  def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
678
778
  ensure_service!
679
779
 
680
- @async_publisher ||= AsyncPublisher.new name, service, @async_opts
780
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
681
781
  @async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
682
782
  end
683
783
 
@@ -693,7 +793,7 @@ module Google
693
793
  # {Subscription#listen}, and {Message#ordering_key}.
694
794
  #
695
795
  def enable_message_ordering!
696
- @async_publisher ||= AsyncPublisher.new name, service, @async_opts
796
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
697
797
  @async_publisher.enable_message_ordering!
698
798
  end
699
799
 
@@ -709,7 +809,7 @@ module Google
709
809
  # @return [Boolean]
710
810
  #
711
811
  def message_ordering?
712
- @async_publisher ||= AsyncPublisher.new name, service, @async_opts
812
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
713
813
  @async_publisher.message_ordering?
714
814
  end
715
815
 
@@ -722,7 +822,7 @@ module Google
722
822
  # @return [boolean] `true` when resumed, `false` otherwise.
723
823
  #
724
824
  def resume_publish ordering_key
725
- @async_publisher ||= AsyncPublisher.new name, service, @async_opts
825
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
726
826
  @async_publisher.resume_publish ordering_key
727
827
  end
728
828
 
@@ -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 { |r| yield r }
132
+ results.each(&block)
133
133
  if request_limit
134
134
  request_limit -= 1
135
135
  break if request_limit.negative?
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.3.2".freeze
19
+ VERSION = "2.7.0".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
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.3.2
4
+ version: 2.7.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: 2021-02-10 00:00:00.000000000 Z
12
+ date: 2021-06-15 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.24.0
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.24.0
97
+ version: 1.25.1
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: minitest
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -219,12 +233,15 @@ files:
219
233
  - lib/google/cloud/pubsub/convert.rb
220
234
  - lib/google/cloud/pubsub/credentials.rb
221
235
  - lib/google/cloud/pubsub/errors.rb
236
+ - lib/google/cloud/pubsub/flow_controller.rb
222
237
  - lib/google/cloud/pubsub/message.rb
223
238
  - lib/google/cloud/pubsub/policy.rb
224
239
  - lib/google/cloud/pubsub/project.rb
225
240
  - lib/google/cloud/pubsub/publish_result.rb
226
241
  - lib/google/cloud/pubsub/received_message.rb
227
242
  - lib/google/cloud/pubsub/retry_policy.rb
243
+ - lib/google/cloud/pubsub/schema.rb
244
+ - lib/google/cloud/pubsub/schema/list.rb
228
245
  - lib/google/cloud/pubsub/service.rb
229
246
  - lib/google/cloud/pubsub/snapshot.rb
230
247
  - lib/google/cloud/pubsub/snapshot/list.rb
@@ -252,14 +269,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
269
  requirements:
253
270
  - - ">="
254
271
  - !ruby/object:Gem::Version
255
- version: '2.4'
272
+ version: '2.5'
256
273
  required_rubygems_version: !ruby/object:Gem::Requirement
257
274
  requirements:
258
275
  - - ">="
259
276
  - !ruby/object:Gem::Version
260
277
  version: '0'
261
278
  requirements: []
262
- rubygems_version: 3.2.6
279
+ rubygems_version: 3.2.17
263
280
  signing_key:
264
281
  specification_version: 4
265
282
  summary: API Client library for Google Cloud Pub/Sub