google-cloud-pubsub 1.6.1 → 1.7.0

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: 65b27ec5d2bc4fe8948301c5a6d56adb62e436bb0d5da35997cc77bb05e2af59
4
- data.tar.gz: 9f7eba965695f834c77cb50f229b2a84ae9d0039528f203b5a0e9db6758e0ae9
3
+ metadata.gz: 176ccfcca66573d1d858c76096cf3e2cbb437163aeaf0993df5e394594158a4d
4
+ data.tar.gz: 02c9e180e88ef9a5d87e68677fe40814b26a903fb65aa994ae50473080f2d27c
5
5
  SHA512:
6
- metadata.gz: 4cb430ff1c904e6ca3248f024e8b9f82aafc5c28ca90fd45f5265a86df70fc7e48cf68d93e0b71ef4d1946beb2319e898aa6c3c8ca4f78085490b330899f9991
7
- data.tar.gz: 8b0af8b3bb8eed0dc11c5e30a61bfb0502758340f5f7062c5f040b371231f58c057bc2d154cdb5a572e81bb674f12c27ed2f734f267a3006f06cd53b2ee6bee8
6
+ metadata.gz: 2a1b5a6de847eb054cf72ec388eca205cf5e3a03dc00b0125ef9a9a0eb2bcd94fb21389f3cef3b56983e59e9f2a11672d02f5a2b7005be7e2658a60633798896
7
+ data.tar.gz: 1c81891756ab4f80a54ed12663a9a339b0e1ba57f821e3ee7f5f0a545a60b6cec4b5c94828bc888bc5b51cf4ab947a642ce3895b8103bc4824ce3026fac56d49
@@ -1,5 +1,16 @@
1
1
  # Release History
2
2
 
3
+ ### 1.7.0 / 2020-05-21
4
+
5
+ #### Features
6
+
7
+ * Add Retry Policy support
8
+ * Add RetryPolicy
9
+ * Add retry_policy param to Topic#subscribe
10
+ * Add Subscription#retry_policy
11
+ * Add Subscription#retry_policy=
12
+ * Set client-scoped UUID in initial StreamingPullRequest#client_id
13
+
3
14
  ### 1.6.1 / 2020-05-06
4
15
 
5
16
  #### Documentation
@@ -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
@@ -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"
@@ -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
@@ -19,6 +19,7 @@ require "google/cloud/pubsub/async_publisher"
19
19
  require "google/cloud/pubsub/batch_publisher"
20
20
  require "google/cloud/pubsub/subscription"
21
21
  require "google/cloud/pubsub/policy"
22
+ require "google/cloud/pubsub/retry_policy"
22
23
 
23
24
  module Google
24
25
  module Cloud
@@ -297,6 +298,13 @@ module Google
297
298
  # the subscription's dead letter policy. Dead lettering is done on a best effort basis. The same message might
298
299
  # be dead lettered multiple times. The value must be between 5 and 100. If this parameter is 0, a default
299
300
  # value of 5 is used. The `dead_letter_topic` must also be set.
301
+ # @param [RetryPolicy] retry_policy A policy that specifies how Cloud Pub/Sub retries message delivery for
302
+ # this subscription. If not set, the default retry policy is applied. This generally implies that messages
303
+ # will be retried as soon as possible for healthy subscribers. Retry Policy will be triggered on NACKs or
304
+ # acknowledgement deadline exceeded events for a given message.
305
+ #
306
+ # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
307
+ # production use. It is not subject to any SLA or deprecation policy.
300
308
  #
301
309
  # @return [Google::Cloud::PubSub::Subscription]
302
310
  #
@@ -340,8 +348,19 @@ module Google
340
348
  # dead_letter_topic: dead_letter_topic,
341
349
  # dead_letter_max_delivery_attempts: 10
342
350
  #
351
+ # @example Configure a Retry Policy:
352
+ # require "google/cloud/pubsub"
353
+ #
354
+ # pubsub = Google::Cloud::PubSub.new
355
+ #
356
+ # topic = pubsub.topic "my-topic"
357
+ #
358
+ # retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
359
+ # sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
360
+ #
343
361
  def subscribe subscription_name, deadline: nil, retain_acked: false, retention: nil, endpoint: nil, labels: nil,
344
- message_ordering: nil, dead_letter_topic: nil, dead_letter_max_delivery_attempts: nil
362
+ message_ordering: nil, dead_letter_topic: nil, dead_letter_max_delivery_attempts: nil,
363
+ retry_policy: nil
345
364
  ensure_service!
346
365
  options = { deadline: deadline, retain_acked: retain_acked, retention: retention, endpoint: endpoint,
347
366
  labels: labels, message_ordering: message_ordering,
@@ -351,6 +370,7 @@ module Google
351
370
  # Service error message "3:Invalid resource name given (name=)." does not identify param.
352
371
  raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
353
372
  end
373
+ options[:retry_policy] = retry_policy.to_grpc if retry_policy
354
374
  grpc = service.create_subscription name, subscription_name, options
355
375
  Subscription.from_grpc grpc, service
356
376
  end
@@ -455,8 +455,11 @@ module Google
455
455
  # The message.
456
456
  # @!attribute [rw] delivery_attempt
457
457
  # @return [Integer]
458
- # Delivery attempt counter is 1 + (the sum of number of NACKs and number of
459
- # ack_deadline exceeds) for this message.
458
+ # The approximate number of times that Cloud Pub/Sub has attempted to deliver
459
+ # the associated message to a subscriber.
460
+ #
461
+ # More precisely, this is 1 + (number of NACKs) +
462
+ # (number of ack_deadline exceeds) for this message.
460
463
  #
461
464
  # A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline
462
465
  # exceeds event is whenever a message is not acknowledged within
@@ -464,13 +467,10 @@ module Google
464
467
  # Subscription.ackDeadlineSeconds, but may get extended automatically by
465
468
  # the client library.
466
469
  #
467
- # The first delivery of a given message will have this value as 1. The value
468
- # is calculated at best effort and is approximate.
470
+ # Upon the first delivery of a given message, `delivery_attempt` will have a
471
+ # value of 1. The value is calculated at best effort and is approximate.
469
472
  #
470
473
  # If a DeadLetterPolicy is not set on the subscription, this will be 0.
471
- # <b>EXPERIMENTAL:</b> This feature is part of a closed alpha release. This
472
- # API might be changed in backward-incompatible ways and is not recommended
473
- # for production use. It is not subject to any SLA or deprecation policy.
474
474
  class ReceivedMessage; end
475
475
 
476
476
  # Request for the GetSubscription method.
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "1.6.1".freeze
19
+ VERSION = "1.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: 1.6.1
4
+ version: 1.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: 2020-05-06 00:00:00.000000000 Z
12
+ date: 2020-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -278,6 +278,7 @@ files:
278
278
  - lib/google/cloud/pubsub/project.rb
279
279
  - lib/google/cloud/pubsub/publish_result.rb
280
280
  - lib/google/cloud/pubsub/received_message.rb
281
+ - lib/google/cloud/pubsub/retry_policy.rb
281
282
  - lib/google/cloud/pubsub/service.rb
282
283
  - lib/google/cloud/pubsub/snapshot.rb
283
284
  - lib/google/cloud/pubsub/snapshot/list.rb