google-cloud-pubsub 1.4.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ba8847f393a5fc464ab63f9d6bca1a7e501c8457afa477486a9bd9c44e6d126
4
- data.tar.gz: '034684fa844d264673c7e79ea17deeea9edc329de16376863e736a5f0825c256'
3
+ metadata.gz: 25d3602668077c7dee90a868dcc01353710ac3001ece8ebe92b7acc6c7bc1bb3
4
+ data.tar.gz: 2119781ea548d6e87d201bdb759643c7ac78b7ffab0a4ee7505f731c3c812670
5
5
  SHA512:
6
- metadata.gz: 8a0e87a57f3fbb1522fd4cf5d93d1c0e03e10ecc5cd2c65b2f0ecfc8aabda230370f6118e9f52c9aadc4763ada09ff6bd0128539fa6469f68d22a327292f3403
7
- data.tar.gz: b18e4d310dbfa486b4b40ed4a6bd657c484c4416517b890bc65889644f928d523b8c447b9b0d3b15980cc80673a9fc2ec3927a6eaff9dd742038f999ac51cee0
6
+ metadata.gz: ed1de151bbd790feb886162024dbe20e75825c7313de7f0349468d8adbdf0400ce0616f53925315a1a2558b2683fd9ac8b478b842b2008dae67990676c163a4b
7
+ data.tar.gz: 2247b98b5f04c936bd908c7a517d396e03af0f07030e7939282f750d8d2b9f569f428961c793f929d5595da60445a55948fe17864a1f25f1ab7d1746b06be9c0
@@ -1,5 +1,48 @@
1
1
  # Release History
2
2
 
3
+ ### 1.7.1 / 2020-05-28
4
+
5
+ #### Documentation
6
+
7
+ * Fix a few broken links
8
+
9
+ ### 1.7.0 / 2020-05-21
10
+
11
+ #### Features
12
+
13
+ * Add Retry Policy support
14
+ * Add RetryPolicy
15
+ * Add retry_policy param to Topic#subscribe
16
+ * Add Subscription#retry_policy
17
+ * Add Subscription#retry_policy=
18
+ * Set client-scoped UUID in initial StreamingPullRequest#client_id
19
+
20
+ ### 1.6.1 / 2020-05-06
21
+
22
+ #### Documentation
23
+
24
+ * Fix example in Emulator documentation
25
+ * Remove experimental notice from ReceivedMessage#delivery_attempt
26
+ * Wrap example URLs in backticks
27
+
28
+ ### 1.6.0 / 2020-04-06
29
+
30
+ #### Features
31
+
32
+ * Add list_topic_snapshots and get_snapshot
33
+ * Add PublisherClient#list_topic_snapshots
34
+ * Add SubscriberClient#get_snapshot
35
+
36
+ #### Documentation
37
+
38
+ * Remove a spurious link in the low-level interface documentation.
39
+
40
+ ### 1.5.0 / 2020-03-25
41
+
42
+ #### Features
43
+
44
+ * Add max_duration_per_lease_extension to Subscription#listen and Subscriber
45
+
3
46
  ### 1.4.0 / 2020-03-11
4
47
 
5
48
  #### Features
@@ -17,7 +17,7 @@ require "google/cloud/pubsub"
17
17
  # Make Pub/Sub use the emulator
18
18
  ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
19
19
 
20
- pubsub = Google::Cloud::PubSub.new "emulator-project-id"
20
+ pubsub = Google::Cloud::PubSub.new project_id:"emulator-project-id"
21
21
 
22
22
  # Get a topic in the current project
23
23
  my_topic = pubsub.new_topic "my-topic"
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
24
24
 
25
25
  - [New issue][gh-ruby]
26
26
 
27
- Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
- can use the "ruby" channel for general Ruby questions, or use the
29
- "google-cloud-ruby" channel if you have questions about this gem in particular.
30
-
31
27
  [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+pubsub
32
28
 
33
- [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+pubsub%22
34
-
35
- [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
29
+ [gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+pubsub%22
36
30
 
37
- [slack-ruby]: https://gcp-slack.appspot.com/
31
+ [gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
@@ -78,11 +78,6 @@ module Google
78
78
  # The first delivery of a given message will have this value as `1`. The value is calculated at best effort and
79
79
  # is approximate.
80
80
  #
81
- # EXPERIMENTAL: This feature is part of a closed alpha release and is available only to whitelisted partners.
82
- # This method will return `nil` if a dead letter policy is not set on the subscription. This API might be
83
- # changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA
84
- # or deprecation policy.
85
- #
86
81
  # @return [Integer, nil] A delivery attempt value of `1` or greater, or `nil` if a dead letter policy is not set
87
82
  # on the subscription.
88
83
  #
@@ -0,0 +1,90 @@
1
+ # Copyright 2016 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
+ require "google/cloud/errors"
17
+
18
+ module Google
19
+ module Cloud
20
+ module PubSub
21
+ ##
22
+ # # RetryPolicy
23
+ #
24
+ # An immutable Retry Policy value object that specifies how Cloud Pub/Sub retries message delivery.
25
+ #
26
+ # Retry delay will be exponential based on provided minimum and maximum backoffs. (See [Exponential
27
+ # backoff](https://en.wikipedia.org/wiki/Exponential_backoff).)
28
+ #
29
+ # Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events for a given message.
30
+ #
31
+ # Retry Policy is implemented on a best effort basis. At times, the delay between consecutive deliveries may not
32
+ # match the configuration. That is, delay can be more or less than configured backoff.
33
+ #
34
+ # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for production
35
+ # use. It is not subject to any SLA or deprecation policy.
36
+ #
37
+ # @attr [Numeric] minimum_backoff The minimum delay between consecutive deliveries of a given message. Value
38
+ # should be between 0 and 600 seconds. The default value is 10 seconds.
39
+ # @attr [Numeric] maximum_backoff The maximum delay between consecutive deliveries of a given message. Value
40
+ # should be between 0 and 600 seconds. The default value is 600 seconds.
41
+ #
42
+ # @example
43
+ # require "google/cloud/pubsub"
44
+ #
45
+ # pubsub = Google::Cloud::PubSub.new
46
+ #
47
+ # sub = pubsub.subscription "my-topic-sub"
48
+ #
49
+ # sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
50
+ #
51
+ # sub.retry_policy.minimum_backoff #=> 5
52
+ # sub.retry_policy.maximum_backoff #=> 300
53
+ #
54
+ class RetryPolicy
55
+ attr_reader :minimum_backoff, :maximum_backoff
56
+
57
+ ##
58
+ # Creates a new, immutable RetryPolicy value object.
59
+ #
60
+ # @attr [Numeric, nil] minimum_backoff The minimum delay between consecutive deliveries of a given message.
61
+ # Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 10 seconds.
62
+ # @attr [Numeric, nil] maximum_backoff The maximum delay between consecutive deliveries of a given message.
63
+ # Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 600 seconds.
64
+ #
65
+ def initialize minimum_backoff: nil, maximum_backoff: nil
66
+ @minimum_backoff = minimum_backoff
67
+ @maximum_backoff = maximum_backoff
68
+ end
69
+
70
+ ##
71
+ # @private Convert the RetryPolicy to a Google::Cloud::PubSub::V1::RetryPolicy object.
72
+ def to_grpc
73
+ Google::Cloud::PubSub::V1::RetryPolicy.new(
74
+ minimum_backoff: Convert.number_to_duration(minimum_backoff),
75
+ maximum_backoff: Convert.number_to_duration(maximum_backoff)
76
+ )
77
+ end
78
+
79
+ ##
80
+ # @private New RetryPolicy from a Google::Cloud::PubSub::V1::RetryPolicy object.
81
+ def self.from_grpc grpc
82
+ new(
83
+ minimum_backoff: Convert.duration_to_number(grpc.minimum_backoff),
84
+ maximum_backoff: Convert.duration_to_number(grpc.maximum_backoff)
85
+ )
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -19,6 +19,7 @@ require "google/cloud/pubsub/convert"
19
19
  require "google/cloud/pubsub/version"
20
20
  require "google/cloud/pubsub/v1"
21
21
  require "google/gax/errors"
22
+ require "securerandom"
22
23
 
23
24
  module Google
24
25
  module Cloud
@@ -28,6 +29,12 @@ module Google
28
29
  # methods.
29
30
  class Service
30
31
  attr_accessor :project, :credentials, :host, :timeout, :client_config
32
+ ###
33
+ # The same client_id is used across all streaming pull connections that are created by this client. This is
34
+ # intentional, as it indicates to the server that any guarantees, such as message ordering, made for a stream
35
+ # that is disconnected will be made for the stream that is created to replace it. The attr_accessor allows the
36
+ # value to be replaced for unit testing.
37
+ attr_accessor :client_id
31
38
 
32
39
  ##
33
40
  # Creates a new Service instance.
@@ -38,6 +45,7 @@ module Google
38
45
  @host = host || V1::PublisherClient::SERVICE_ADDRESS
39
46
  @timeout = timeout
40
47
  @client_config = client_config || {}
48
+ @client_id = SecureRandom.uuid.freeze
41
49
  end
42
50
 
43
51
  def channel
@@ -248,6 +256,7 @@ module Google
248
256
  labels: labels,
249
257
  enable_message_ordering: message_ordering,
250
258
  dead_letter_policy: dead_letter_policy(options),
259
+ retry_policy: options[:retry_policy],
251
260
  options: default_options
252
261
  end
253
262
  end
@@ -104,6 +104,7 @@ module Google
104
104
  # received messages.
105
105
  #
106
106
  # @return [Subscriber] returns self so calls can be chained.
107
+ #
107
108
  def start
108
109
  start_pool = synchronize do
109
110
  @started = true
@@ -129,6 +130,7 @@ module Google
129
130
  # received messages have been processed or released.
130
131
  #
131
132
  # @return [Subscriber] returns self so calls can be chained.
133
+ #
132
134
  def stop
133
135
  stop_pool = synchronize do
134
136
  @started = false
@@ -158,6 +160,7 @@ module Google
158
160
  # subscriber is fully stopped. Default will block indefinitely.
159
161
  #
160
162
  # @return [Subscriber] returns self so calls can be chained.
163
+ #
161
164
  def wait! timeout = nil
162
165
  wait_pool = synchronize do
163
166
  @stream_pool.map do |stream|
@@ -190,6 +193,7 @@ module Google
190
193
  # Whether the subscriber has been started.
191
194
  #
192
195
  # @return [boolean] `true` when started, `false` otherwise.
196
+ #
193
197
  def started?
194
198
  synchronize { @started }
195
199
  end
@@ -198,6 +202,7 @@ module Google
198
202
  # Whether the subscriber has been stopped.
199
203
  #
200
204
  # @return [boolean] `true` when stopped, `false` otherwise.
205
+ #
201
206
  def stopped?
202
207
  synchronize { @stopped }
203
208
  end
@@ -279,6 +284,9 @@ module Google
279
284
 
280
285
  ##
281
286
  # The number of received messages to be collected by subscriber. Default is 1,000.
287
+ #
288
+ # @return [Integer] The maximum number of messages.
289
+ #
282
290
  def max_outstanding_messages
283
291
  @inventory[:max_outstanding_messages]
284
292
  end
@@ -289,6 +297,9 @@ module Google
289
297
 
290
298
  ##
291
299
  # The total byte size of received messages to be collected by subscriber. Default is 100,000,000 (100MB).
300
+ #
301
+ # @return [Integer] The maximum number of bytes.
302
+ #
292
303
  def max_outstanding_bytes
293
304
  @inventory[:max_outstanding_bytes]
294
305
  end
@@ -297,19 +308,33 @@ module Google
297
308
 
298
309
  ##
299
310
  # The number of seconds that received messages can be held awaiting processing. Default is 3,600 (1 hour).
311
+ #
312
+ # @return [Integer] The maximum number of seconds.
313
+ #
300
314
  def max_total_lease_duration
301
315
  @inventory[:max_total_lease_duration]
302
316
  end
303
317
  # @deprecated Use {#max_total_lease_duration}.
304
318
  alias inventory_extension max_total_lease_duration
305
319
 
320
+ ##
321
+ # The maximum amount of time in seconds for a single lease extension attempt. Bounds the delay before a message
322
+ # redelivery if the subscriber fails to extend the deadline. Default is 0 (disabled).
323
+ #
324
+ # @return [Integer] The maximum number of seconds.
325
+ #
326
+ def max_duration_per_lease_extension
327
+ @inventory[:max_duration_per_lease_extension]
328
+ end
329
+
306
330
  ##
307
331
  # @private
308
332
  def stream_inventory
309
333
  {
310
- limit: @inventory[:max_outstanding_messages].fdiv(@streams).ceil,
311
- bytesize: @inventory[:max_outstanding_bytes].fdiv(@streams).ceil,
312
- extension: @inventory[:max_total_lease_duration]
334
+ limit: @inventory[:max_outstanding_messages].fdiv(@streams).ceil,
335
+ bytesize: @inventory[:max_outstanding_bytes].fdiv(@streams).ceil,
336
+ extension: @inventory[:max_total_lease_duration],
337
+ max_duration_per_lease_extension: @inventory[:max_duration_per_lease_extension]
313
338
  }
314
339
  end
315
340
 
@@ -351,6 +376,7 @@ module Google
351
376
  @inventory[:max_outstanding_messages] = Integer(@inventory[:max_outstanding_messages] || 1000)
352
377
  @inventory[:max_outstanding_bytes] = Integer(@inventory[:max_outstanding_bytes] || 100_000_000)
353
378
  @inventory[:max_total_lease_duration] = Integer(@inventory[:max_total_lease_duration] || 3600)
379
+ @inventory[:max_duration_per_lease_extension] = Integer(@inventory[:max_duration_per_lease_extension] || 0)
354
380
  end
355
381
 
356
382
  def default_error_callbacks
@@ -30,14 +30,15 @@ module Google
30
30
 
31
31
  include MonitorMixin
32
32
 
33
- attr_reader :stream, :limit, :bytesize, :extension
33
+ attr_reader :stream, :limit, :bytesize, :extension, :max_duration_per_lease_extension
34
34
 
35
- def initialize stream, limit:, bytesize:, extension:
35
+ def initialize stream, limit:, bytesize:, extension:, max_duration_per_lease_extension:
36
36
  super()
37
37
  @stream = stream
38
38
  @limit = limit
39
39
  @bytesize = bytesize
40
40
  @extension = extension
41
+ @max_duration_per_lease_extension = max_duration_per_lease_extension
41
42
  @inventory = {}
42
43
  @wait_cond = new_cond
43
44
  end
@@ -152,7 +153,9 @@ module Google
152
153
  end
153
154
 
154
155
  def calc_delay
155
- (stream.subscriber.deadline - 3) * rand(0.8..0.9)
156
+ delay = (stream.subscriber.deadline - 3) * rand(0.8..0.9)
157
+ delay = [delay, max_duration_per_lease_extension].min if max_duration_per_lease_extension.positive?
158
+ delay
156
159
  end
157
160
  end
158
161
  end
@@ -363,6 +363,7 @@ module Google
363
363
  req.stream_ack_deadline_seconds = @subscriber.deadline
364
364
  req.modify_deadline_ack_ids += @inventory.ack_ids
365
365
  req.modify_deadline_seconds += @inventory.ack_ids.map { @subscriber.deadline }
366
+ req.client_id = @subscriber.service.client_id
366
367
  end
367
368
  end
368
369
 
@@ -18,6 +18,7 @@ require "google/cloud/errors"
18
18
  require "google/cloud/pubsub/subscription/list"
19
19
  require "google/cloud/pubsub/subscription/push_config"
20
20
  require "google/cloud/pubsub/received_message"
21
+ require "google/cloud/pubsub/retry_policy"
21
22
  require "google/cloud/pubsub/snapshot"
22
23
  require "google/cloud/pubsub/subscriber"
23
24
  require "google/cloud/pubsub/v1"
@@ -188,7 +189,7 @@ module Google
188
189
  ##
189
190
  # Returns the URL locating the endpoint to which messages should be
190
191
  # pushed. For example, a Webhook endpoint might use
191
- # "https://example.com/push".
192
+ # `https://example.com/push`.
192
193
  #
193
194
  # Makes an API call to retrieve the endpoint value when called on a
194
195
  # reference object. See {#reference?}.
@@ -202,7 +203,7 @@ module Google
202
203
 
203
204
  ##
204
205
  # Sets the URL locating the endpoint to which messages should be pushed.
205
- # For example, a Webhook endpoint might use "https://example.com/push".
206
+ # For example, a Webhook endpoint might use `https://example.com/push`.
206
207
  #
207
208
  # @param [String] new_endpoint The new endpoint value.
208
209
  #
@@ -483,6 +484,65 @@ module Google
483
484
  @resource_name = nil
484
485
  end
485
486
 
487
+ ##
488
+ # A policy that specifies how Cloud Pub/Sub retries message delivery for this subscription. If `nil`, the
489
+ # default retry policy is applied. This generally implies that messages will be retried as soon as possible
490
+ # for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
491
+ # for a given message.
492
+ #
493
+ # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
494
+ # production use. It is not subject to any SLA or deprecation policy.
495
+ #
496
+ # @return [RetryPolicy, nil] The retry policy for the subscription, or `nil`.
497
+ #
498
+ # @example
499
+ # require "google/cloud/pubsub"
500
+ #
501
+ # pubsub = Google::Cloud::PubSub.new
502
+ #
503
+ # sub = pubsub.subscription "my-topic-sub"
504
+ #
505
+ # sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
506
+ #
507
+ # sub.retry_policy.minimum_backoff #=> 5
508
+ # sub.retry_policy.maximum_backoff #=> 300
509
+ #
510
+ def retry_policy
511
+ ensure_grpc!
512
+ return nil unless @grpc.retry_policy
513
+ RetryPolicy.from_grpc @grpc.retry_policy
514
+ end
515
+
516
+ ##
517
+ # Sets a policy that specifies how Cloud Pub/Sub retries message delivery for this subscription. If `nil`, the
518
+ # default retry policy is applied. This generally implies that messages will be retried as soon as possible
519
+ # for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
520
+ # for a given message.
521
+ #
522
+ # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
523
+ # production use. It is not subject to any SLA or deprecation policy.
524
+ #
525
+ # @param [RetryPolicy, nil] new_retry_policy A new retry policy for the subscription, or `nil`.
526
+ #
527
+ # @example
528
+ # require "google/cloud/pubsub"
529
+ #
530
+ # pubsub = Google::Cloud::PubSub.new
531
+ #
532
+ # sub = pubsub.subscription "my-topic-sub"
533
+ #
534
+ # sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
535
+ #
536
+ # sub.retry_policy.minimum_backoff #=> 5
537
+ # sub.retry_policy.maximum_backoff #=> 300
538
+ #
539
+ def retry_policy= new_retry_policy
540
+ ensure_grpc!
541
+ new_retry_policy = new_retry_policy.to_grpc if new_retry_policy
542
+ update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, retry_policy: new_retry_policy
543
+ @grpc = service.update_subscription update_grpc, :retry_policy
544
+ end
545
+
486
546
  ##
487
547
  # Whether message ordering has been enabled. When enabled, messages
488
548
  # published with the same `ordering_key` will be delivered in the order
@@ -699,6 +759,9 @@ module Google
699
759
  # subscriber. Default is 100,000,000 (100MB). (Note: replaces `:bytesize`, which is deprecated.)
700
760
  # * `:max_total_lease_duration` [Integer] The number of seconds that received messages can be held awaiting
701
761
  # processing. Default is 3,600 (1 hour). (Note: replaces `:extension`, which is deprecated.)
762
+ # * `:max_duration_per_lease_extension` [Integer] The maximum amount of time in seconds for a single lease
763
+ # extension attempt. Bounds the delay before a message redelivery if the subscriber fails to extend the
764
+ # deadline. Default is 0 (disabled).
702
765
  # @param [Hash] threads The number of threads to create to handle
703
766
  # concurrent calls by each stream opened by the subscriber. Optional.
704
767
  #
@@ -774,6 +837,25 @@ module Google
774
837
  # # Shut down the subscriber when ready to stop receiving messages.
775
838
  # subscriber.stop.wait!
776
839
  #
840
+ # @example Set the maximum amount of time before redelivery if the subscriber fails to extend the deadline:
841
+ # require "google/cloud/pubsub"
842
+ #
843
+ # pubsub = Google::Cloud::PubSub.new
844
+ #
845
+ # sub = pubsub.subscription "my-topic-sub"
846
+ #
847
+ # subscriber = sub.listen inventory: { max_duration_per_lease_extension: 20 } do |received_message|
848
+ # # Process message very slowly with possibility of failure.
849
+ # process rec_message.data # takes minutes
850
+ # rec_message.acknowledge!
851
+ # end
852
+ #
853
+ # # Start background threads that will call block passed to listen.
854
+ # subscriber.start
855
+ #
856
+ # # Shut down the subscriber when ready to stop receiving messages.
857
+ # subscriber.stop.wait!
858
+ #
777
859
  def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block
778
860
  ensure_service!
779
861
  deadline ||= self.deadline