google-cloud-pubsub 1.1.3 → 2.0.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/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +145 -0
- data/EMULATOR.md +1 -1
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google/cloud/pubsub/async_publisher.rb +16 -21
- data/lib/google/cloud/pubsub/credentials.rb +2 -2
- data/lib/google/cloud/pubsub/project.rb +18 -26
- data/lib/google/cloud/pubsub/received_message.rb +38 -0
- data/lib/google/cloud/pubsub/retry_policy.rb +90 -0
- data/lib/google/cloud/pubsub/service.rb +125 -252
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +43 -15
- data/lib/google/cloud/pubsub/subscriber/stream.rb +8 -10
- data/lib/google/cloud/pubsub/subscriber.rb +86 -15
- data/lib/google/cloud/pubsub/subscription/push_config.rb +2 -2
- data/lib/google/cloud/pubsub/subscription.rb +297 -7
- data/lib/google/cloud/pubsub/topic.rb +65 -2
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/cloud/pubsub.rb +15 -18
- data/lib/google-cloud-pubsub.rb +13 -13
- metadata +11 -81
- data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -744
- data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -786
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -105
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1385
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -144
- data/lib/google/cloud/pubsub/v1.rb +0 -17
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -249
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -211
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5faee5de29df83057422ad7029a047eb10e8408a9b4e87599d301bc1c907a06
|
4
|
+
data.tar.gz: bc9d9b75232d66b09b5d45310875fbbd734663cf226575e43656da47aa955204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59bc075932f2a592276a8e0472371a18a8cc6e835ccb6c36ece17f277528bf92813d978e06393cf384c54c282c8a04fa6ba1d2fcfab08214e3cb3a55d2724ac
|
7
|
+
data.tar.gz: 8a6fffc01ab630eaf960c3c87858f942fe6a0241cfdf024875d379f2a915be724ea209bcfdc07c7ab12a1299949785456c27f0725d6d4b4cac519749cbc6f1fc
|
data/AUTHENTICATION.md
CHANGED
@@ -76,7 +76,8 @@ The environment variables that google-cloud-pubsub checks for project ID are:
|
|
76
76
|
1. `PUBSUB_PROJECT`
|
77
77
|
2. `GOOGLE_CLOUD_PROJECT`
|
78
78
|
|
79
|
-
The environment variables that google-cloud-pubsub checks for credentials
|
79
|
+
The environment variables that google-cloud-pubsub checks for credentials
|
80
|
+
are configured on {Google::Cloud::PubSub::Credentials}:
|
80
81
|
|
81
82
|
1. `PUBSUB_CREDENTIALS` - Path to JSON file, or JSON contents
|
82
83
|
2. `PUBSUB_KEYFILE` - Path to JSON file, or JSON contents
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,150 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.0.0 / 2020-08-06
|
4
|
+
|
5
|
+
This is a major update that removes the "low-level" client interface code, and
|
6
|
+
instead adds the new `google-cloud-pubsub-v1` gem as a dependency.
|
7
|
+
The new dependency is a rewritten low-level client, produced by a next-
|
8
|
+
generation client code generator, with improved performance and stability.
|
9
|
+
|
10
|
+
This change should have no effect on the high-level interface that most users
|
11
|
+
will use. The one exception is that the (mostly undocumented) `client_config`
|
12
|
+
argument, for adjusting low-level parameters such as RPC retry settings on
|
13
|
+
client objects, has been removed. If you need to adjust these parameters, use
|
14
|
+
the configuration interface in `google-cloud-pubsub-v1`.
|
15
|
+
|
16
|
+
Substantial changes have been made in the low-level interfaces, however. If you
|
17
|
+
are using the low-level classes under the `Google::Cloud::PubSub::V1` module,
|
18
|
+
please review the docs for the new `google-cloud-pubsub-v1` gem. In
|
19
|
+
particular:
|
20
|
+
|
21
|
+
* Some classes have been renamed, notably the client classes themselves.
|
22
|
+
* The client constructor takes a configuration block instead of configuration
|
23
|
+
keyword arguments.
|
24
|
+
* All RPC method arguments are now keyword arguments.
|
25
|
+
|
26
|
+
### 1.10.0 / 2020-07-23
|
27
|
+
|
28
|
+
#### Features
|
29
|
+
|
30
|
+
* Add Subscription#detach and #detached?
|
31
|
+
|
32
|
+
### 1.9.0 / 2020-07-21
|
33
|
+
|
34
|
+
#### Features
|
35
|
+
|
36
|
+
* Add support for server-side flow control
|
37
|
+
|
38
|
+
### 1.8.0 / 2020-06-29
|
39
|
+
|
40
|
+
#### Features
|
41
|
+
|
42
|
+
* Add Subscription#filter
|
43
|
+
|
44
|
+
### 1.7.1 / 2020-05-28
|
45
|
+
|
46
|
+
#### Documentation
|
47
|
+
|
48
|
+
* Fix a few broken links
|
49
|
+
|
50
|
+
### 1.7.0 / 2020-05-21
|
51
|
+
|
52
|
+
#### Features
|
53
|
+
|
54
|
+
* Add Retry Policy support
|
55
|
+
* Add RetryPolicy
|
56
|
+
* Add retry_policy param to Topic#subscribe
|
57
|
+
* Add Subscription#retry_policy
|
58
|
+
* Add Subscription#retry_policy=
|
59
|
+
* Set client-scoped UUID in initial StreamingPullRequest#client_id
|
60
|
+
|
61
|
+
### 1.6.1 / 2020-05-06
|
62
|
+
|
63
|
+
#### Documentation
|
64
|
+
|
65
|
+
* Fix example in Emulator documentation
|
66
|
+
* Remove experimental notice from ReceivedMessage#delivery_attempt
|
67
|
+
* Wrap example URLs in backticks
|
68
|
+
|
69
|
+
### 1.6.0 / 2020-04-06
|
70
|
+
|
71
|
+
#### Features
|
72
|
+
|
73
|
+
* Add list_topic_snapshots and get_snapshot
|
74
|
+
* Add PublisherClient#list_topic_snapshots
|
75
|
+
* Add SubscriberClient#get_snapshot
|
76
|
+
|
77
|
+
#### Documentation
|
78
|
+
|
79
|
+
* Remove a spurious link in the low-level interface documentation.
|
80
|
+
|
81
|
+
### 1.5.0 / 2020-03-25
|
82
|
+
|
83
|
+
#### Features
|
84
|
+
|
85
|
+
* Add max_duration_per_lease_extension to Subscription#listen and Subscriber
|
86
|
+
|
87
|
+
### 1.4.0 / 2020-03-11
|
88
|
+
|
89
|
+
#### Features
|
90
|
+
|
91
|
+
* Rename Subscriber inventory methods and params
|
92
|
+
* Rename Subscriber#inventory_limit to #max_outstanding_messages
|
93
|
+
* Rename Subscriber#bytesize to #max_outstanding_bytes
|
94
|
+
* Rename Subscriber#extension to #max_total_lease_duration
|
95
|
+
* Add deprecated aliases for the original methods
|
96
|
+
* Support separate project setting for quota/billing
|
97
|
+
|
98
|
+
#### Documentation
|
99
|
+
|
100
|
+
* Update documentation in the lower-level client
|
101
|
+
|
102
|
+
### 1.3.1 / 2020-02-18
|
103
|
+
|
104
|
+
#### Bug Fixes
|
105
|
+
|
106
|
+
* Move Thread.new to end of AsyncPublisher#initialize
|
107
|
+
|
108
|
+
### 1.3.0 / 2020-02-10
|
109
|
+
|
110
|
+
#### Features
|
111
|
+
|
112
|
+
* Add support for Dead Letter Topics
|
113
|
+
* Add `dead_letter_topic` and `dead_letter_max_delivery_attempts` to `Topic#subscribe`
|
114
|
+
* Add `Subscription#dead_letter_topic` and `Subscription#dead_letter_topic=`
|
115
|
+
* Add `Subscription#dead_letter_max_delivery_attempts` and `Subscription#dead_letter_max_delivery_attempts=`
|
116
|
+
* Add `ReceivedMessage#delivery_attempt`
|
117
|
+
|
118
|
+
### 1.2.2 / 2020-02-04
|
119
|
+
|
120
|
+
#### Performance Improvements
|
121
|
+
|
122
|
+
* Add StreamingPullRequest#client_id to the lower-level API
|
123
|
+
|
124
|
+
### 1.2.1 / 2020-01-23
|
125
|
+
|
126
|
+
#### Documentation
|
127
|
+
|
128
|
+
* Update copyright year
|
129
|
+
|
130
|
+
### 1.2.0 / 2020-01-09
|
131
|
+
|
132
|
+
#### Features
|
133
|
+
|
134
|
+
* Add Subscriber inventory settings
|
135
|
+
* Add the following settings to Subscriber:
|
136
|
+
* Subscriber#inventory_limit
|
137
|
+
* Subscriber#inventory_bytesize
|
138
|
+
* Subscriber#extension
|
139
|
+
* Allow Subscription#listen inventory argument to be a hash.
|
140
|
+
* Update AsyncPublisher configuration defaults
|
141
|
+
* Update AsyncPublisher defaults to the following:
|
142
|
+
* max_bytes to 1MB, was 10MB.
|
143
|
+
* max_messages to 100, was 1,000.
|
144
|
+
* interval to 10 milliseconds, was 250 milliseconds.
|
145
|
+
* publish thread count to 2, was 4
|
146
|
+
* callback thread count to 4, was 8.
|
147
|
+
|
3
148
|
### 1.1.3 / 2019-12-18
|
4
149
|
|
5
150
|
#### Bug Fixes
|
data/EMULATOR.md
CHANGED
@@ -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"
|
data/TROUBLESHOOTING.md
CHANGED
@@ -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/
|
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
|
-
[
|
31
|
+
[gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
|
@@ -44,20 +44,17 @@ module Google
|
|
44
44
|
#
|
45
45
|
# topic.async_publisher.stop.wait!
|
46
46
|
#
|
47
|
-
# @attr_reader [String] topic_name The name of the topic the messages
|
48
|
-
# are published to. In the form of
|
47
|
+
# @attr_reader [String] topic_name The name of the topic the messages are published to. In the form of
|
49
48
|
# "/projects/project-identifier/topics/topic-name".
|
50
|
-
# @attr_reader [Integer] max_bytes The maximum size of messages to be
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# @attr_reader [Numeric]
|
58
|
-
#
|
59
|
-
# @attr_reader [Numeric] callback_threads The number of threads to
|
60
|
-
# handle the published messages' callbacks. Default is 8.
|
49
|
+
# @attr_reader [Integer] max_bytes The maximum size of messages to be collected before the batch is published.
|
50
|
+
# Default is 1,000,000 (1MB).
|
51
|
+
# @attr_reader [Integer] max_messages The maximum number of messages to be collected before the batch is
|
52
|
+
# published. Default is 100.
|
53
|
+
# @attr_reader [Numeric] interval The number of seconds to collect messages before the batch is published. Default
|
54
|
+
# is 0.01.
|
55
|
+
# @attr_reader [Numeric] publish_threads The number of threads used to publish messages. Default is 2.
|
56
|
+
# @attr_reader [Numeric] callback_threads The number of threads to handle the published messages' callbacks.
|
57
|
+
# Default is 4.
|
61
58
|
#
|
62
59
|
class AsyncPublisher
|
63
60
|
include MonitorMixin
|
@@ -71,28 +68,27 @@ module Google
|
|
71
68
|
|
72
69
|
##
|
73
70
|
# @private Create a new instance of the object.
|
74
|
-
def initialize topic_name, service, max_bytes:
|
71
|
+
def initialize topic_name, service, max_bytes: 1_000_000, max_messages: 100, interval: 0.01, threads: {}
|
75
72
|
# init MonitorMixin
|
76
73
|
super()
|
77
|
-
|
78
74
|
@topic_name = service.topic_path topic_name
|
79
75
|
@service = service
|
80
76
|
|
81
77
|
@max_bytes = max_bytes
|
82
78
|
@max_messages = max_messages
|
83
79
|
@interval = interval
|
84
|
-
@publish_threads = (threads[:publish] ||
|
85
|
-
@callback_threads = (threads[:callback] ||
|
80
|
+
@publish_threads = (threads[:publish] || 2).to_i
|
81
|
+
@callback_threads = (threads[:callback] || 4).to_i
|
86
82
|
|
87
83
|
@published_at = nil
|
88
84
|
@publish_thread_pool = Concurrent::ThreadPoolExecutor.new max_threads: @publish_threads
|
89
85
|
@callback_thread_pool = Concurrent::ThreadPoolExecutor.new max_threads: @callback_threads
|
90
|
-
@thread = Thread.new { run_background }
|
91
86
|
|
92
87
|
@ordered = false
|
93
88
|
@batches = {}
|
94
|
-
|
95
89
|
@cond = new_cond
|
90
|
+
|
91
|
+
@thread = Thread.new { run_background }
|
96
92
|
end
|
97
93
|
|
98
94
|
##
|
@@ -378,8 +374,7 @@ module Google
|
|
378
374
|
|
379
375
|
PUBLISH_RETRY_ERRORS = [
|
380
376
|
GRPC::Cancelled, GRPC::DeadlineExceeded, GRPC::Internal,
|
381
|
-
GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable
|
382
|
-
GRPC::Core::CallError
|
377
|
+
GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable
|
383
378
|
].freeze
|
384
379
|
|
385
380
|
def publish_batch_error_retryable? error
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "googleauth"
|
17
|
-
require "google/cloud/pubsub/v1/credentials.rb"
|
17
|
+
require "google/cloud/pubsub/v1/publisher/credentials.rb"
|
18
18
|
|
19
19
|
module Google
|
20
20
|
module Cloud
|
@@ -38,7 +38,7 @@ module Google
|
|
38
38
|
#
|
39
39
|
# pubsub.project_id #=> "my-project"
|
40
40
|
#
|
41
|
-
class Credentials < Google::Cloud::PubSub::V1::Credentials
|
41
|
+
class Credentials < Google::Cloud::PubSub::V1::Publisher::Credentials
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -89,19 +89,15 @@ module Google
|
|
89
89
|
#
|
90
90
|
# Hash keys and values may include the following:
|
91
91
|
#
|
92
|
-
# * `:max_bytes` (Integer) The maximum size of messages to be
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# * `:publish` (Integer) The number of threads used to publish
|
102
|
-
# messages. Default is 4.
|
103
|
-
# * `:callback` (Integer) The number of threads to handle the
|
104
|
-
# published messages' callbacks. Default is 8.
|
92
|
+
# * `:max_bytes` (Integer) The maximum size of messages to be collected before the batch is published. Default
|
93
|
+
# is 1,000,000 (1MB).
|
94
|
+
# * `:max_messages` (Integer) The maximum number of messages to be collected before the batch is published.
|
95
|
+
# Default is 100.
|
96
|
+
# * `:interval` (Numeric) The number of seconds to collect messages before the batch is published. Default is
|
97
|
+
# 0.01.
|
98
|
+
# * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
|
99
|
+
# * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
|
100
|
+
# * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
|
105
101
|
#
|
106
102
|
# @return [Google::Cloud::PubSub::Topic, nil] Returns `nil` if topic
|
107
103
|
# does not exist.
|
@@ -183,19 +179,15 @@ module Google
|
|
183
179
|
#
|
184
180
|
# Hash keys and values may include the following:
|
185
181
|
#
|
186
|
-
# * `:max_bytes` (Integer) The maximum size of messages to be
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
# * `:publish` (Integer) The number of threads used to publish
|
196
|
-
# messages. Default is 4.
|
197
|
-
# * `:callback` (Integer) The number of threads to handle the
|
198
|
-
# published messages' callbacks. Default is 8.
|
182
|
+
# * `:max_bytes` (Integer) The maximum size of messages to be collected before the batch is published. Default
|
183
|
+
# is 1,000,000 (1MB).
|
184
|
+
# * `:max_messages` (Integer) The maximum number of messages to be collected before the batch is published.
|
185
|
+
# Default is 100.
|
186
|
+
# * `:interval` (Numeric) The number of seconds to collect messages before the batch is published. Default is
|
187
|
+
# 0.01.
|
188
|
+
# * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
|
189
|
+
# * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
|
190
|
+
# * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
|
199
191
|
#
|
200
192
|
# @return [Google::Cloud::PubSub::Topic]
|
201
193
|
#
|
@@ -63,6 +63,44 @@ module Google
|
|
63
63
|
@grpc.ack_id
|
64
64
|
end
|
65
65
|
|
66
|
+
##
|
67
|
+
# Returns the delivery attempt counter for the message. If a dead letter policy is not set on the subscription,
|
68
|
+
# this will be `nil`. See {Topic#subscribe}, {Subscription#dead_letter_topic=} and
|
69
|
+
# {Subscription#dead_letter_max_delivery_attempts=}.
|
70
|
+
#
|
71
|
+
# The delivery attempt counter is `1 + (the sum of number of NACKs and number of ack_deadline exceeds)` for the
|
72
|
+
# message.
|
73
|
+
#
|
74
|
+
# A NACK is any call to `ModifyAckDeadline` with a `0` deadline. An `ack_deadline` exceeds event is whenever a
|
75
|
+
# message is not acknowledged within `ack_deadline`. Note that `ack_deadline` is initially
|
76
|
+
# `Subscription.ackDeadlineSeconds`, but may get extended automatically by the client library.
|
77
|
+
#
|
78
|
+
# The first delivery of a given message will have this value as `1`. The value is calculated at best effort and
|
79
|
+
# is approximate.
|
80
|
+
#
|
81
|
+
# @return [Integer, nil] A delivery attempt value of `1` or greater, or `nil` if a dead letter policy is not set
|
82
|
+
# on the subscription.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# require "google/cloud/pubsub"
|
86
|
+
#
|
87
|
+
# pubsub = Google::Cloud::PubSub.new
|
88
|
+
#
|
89
|
+
# topic = pubsub.topic "my-topic"
|
90
|
+
# dead_letter_topic = pubsub.topic "my-dead-letter-topic", skip_lookup: true
|
91
|
+
# sub = topic.subscribe "my-topic-sub",
|
92
|
+
# dead_letter_topic: dead_letter_topic,
|
93
|
+
# dead_letter_max_delivery_attempts: 10
|
94
|
+
#
|
95
|
+
# subscriber = sub.listen do |received_message|
|
96
|
+
# puts received_message.message.delivery_attempt
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
def delivery_attempt
|
100
|
+
return nil if @grpc.delivery_attempt && @grpc.delivery_attempt < 1
|
101
|
+
@grpc.delivery_attempt
|
102
|
+
end
|
103
|
+
|
66
104
|
##
|
67
105
|
# The received message.
|
68
106
|
def message
|
@@ -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
|