google-cloud-pubsub 2.19.0 → 3.0.3

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +12 -1
  3. data/CHANGELOG.md +66 -0
  4. data/OVERVIEW.md +188 -144
  5. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  6. data/lib/google/cloud/pubsub/async_publisher.rb +9 -9
  7. data/lib/google/cloud/pubsub/batch_publisher.rb +4 -4
  8. data/lib/google/cloud/pubsub/errors.rb +3 -3
  9. data/lib/google/cloud/pubsub/message.rb +8 -8
  10. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  11. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +2 -4
  12. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +10 -10
  14. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +1 -1
  15. data/lib/google/cloud/pubsub/message_listener.rb +413 -0
  16. data/lib/google/cloud/pubsub/project.rb +98 -531
  17. data/lib/google/cloud/pubsub/publisher.rb +373 -0
  18. data/lib/google/cloud/pubsub/received_message.rb +50 -45
  19. data/lib/google/cloud/pubsub/service.rb +24 -346
  20. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  21. data/lib/google/cloud/pubsub/version.rb +1 -1
  22. data/lib/google/cloud/pubsub.rb +26 -18
  23. data/lib/google-cloud-pubsub.rb +23 -8
  24. metadata +20 -37
  25. data/lib/google/cloud/pubsub/policy.rb +0 -188
  26. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  27. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  28. data/lib/google/cloud/pubsub/schema.rb +0 -310
  29. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  30. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  31. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  32. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  33. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  34. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  35. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.19.0".freeze
19
+ VERSION = "3.0.3".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
@@ -43,9 +43,24 @@ module Google
43
43
  # @param [String] project_id Project identifier for the Pub/Sub service
44
44
  # you are connecting to. If not present, the default project for the
45
45
  # credentials is used.
46
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
47
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
48
- # Google::Auth::Credentials object. (See {PubSub::Credentials})
46
+ # @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
47
+ # object. (See {PubSub::Credentials})
48
+ # @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
49
+ # is deprecated. Providing an unvalidated credential configuration to
50
+ # Google APIs can compromise the security of your systems and data.
51
+ #
52
+ # @example
53
+ #
54
+ # # The recommended way to provide credentials is to use the `make_creds` method
55
+ # # on the appropriate credentials class for your environment.
56
+ #
57
+ # require "googleauth"
58
+ #
59
+ # credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
60
+ # json_key_io: ::File.open("/path/to/keyfile.json")
61
+ # )
62
+ #
63
+ # pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
49
64
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
50
65
  # the set of resources and operations that the connection can access.
51
66
  # See [Using OAuth 2.0 to Access Google
@@ -59,9 +74,6 @@ module Google
59
74
  # If the param is nil, uses the default endpoint.
60
75
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
61
76
  # If the param is nil, uses the value of the `emulator_host` config.
62
- # @param [String] project Alias for the `project_id` argument. Deprecated.
63
- # @param [String] keyfile Alias for the `credentials` argument.
64
- # Deprecated.
65
77
  # @param universe_domain [String] A custom universe domain. Optional.
66
78
  #
67
79
  # @return [Google::Cloud::PubSub::Project]
@@ -71,8 +83,8 @@ module Google
71
83
  #
72
84
  # pubsub = Google::Cloud::PubSub.new
73
85
  #
74
- # topic = pubsub.topic "my-topic"
75
- # topic.publish "task completed"
86
+ # publisher = pubsub.publisher "my-topic"
87
+ # publisher.publish "task completed"
76
88
  #
77
89
  def self.new project_id: nil,
78
90
  credentials: nil,
@@ -80,10 +92,8 @@ module Google
80
92
  timeout: nil,
81
93
  universe_domain: nil,
82
94
  endpoint: nil,
83
- emulator_host: nil,
84
- project: nil,
85
- keyfile: nil
86
- project_id ||= project || default_project_id
95
+ emulator_host: nil
96
+ project_id ||= default_project_id
87
97
  scope ||= configure.scope
88
98
  timeout ||= configure.timeout
89
99
  endpoint ||= configure.endpoint
@@ -94,7 +104,7 @@ module Google
94
104
  credentials = :this_channel_is_insecure
95
105
  endpoint = emulator_host
96
106
  else
97
- credentials ||= keyfile || default_credentials(scope: scope)
107
+ credentials ||= default_credentials scope: scope
98
108
  unless credentials.is_a? Google::Auth::Credentials
99
109
  credentials = PubSub::Credentials.new credentials, scope: scope
100
110
  end
@@ -116,12 +126,10 @@ module Google
116
126
  #
117
127
  # The following PubSub configuration parameters are supported:
118
128
  #
119
- # * `project_id` - (String) Identifier for a PubSub project. (The
120
- # parameter `project` is considered deprecated, but may also be used.)
129
+ # * `project_id` - (String) Identifier for a PubSub project.
121
130
  # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
122
131
  # the keyfile as a String, the contents of the keyfile as a Hash, or a
123
- # Google::Auth::Credentials object. (See {PubSub::Credentials}) (The
124
- # parameter `keyfile` is considered deprecated, but may also be used.)
132
+ # Google::Auth::Credentials object. (See {PubSub::Credentials})
125
133
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
126
134
  # the set of resources and operations that the connection can access.
127
135
  # * `quota_project` - (String) The project ID for a project that can be
@@ -133,7 +141,7 @@ module Google
133
141
  # `ENV["PUBSUB_EMULATOR_HOST"]`
134
142
  # * `on_error` - (Proc) A Proc to be run when an error is encountered
135
143
  # on a background thread. The Proc must take the error object as the
136
- # single argument. (See {Subscriber.on_error}.)
144
+ # single argument. (See {MessageListener.on_error}.)
137
145
  #
138
146
  # @return [Google::Cloud::Config] The configuration object the
139
147
  # Google::Cloud::PubSub library uses.
@@ -50,8 +50,9 @@ module Google
50
50
  #
51
51
  # gcloud = Google::Cloud.new
52
52
  # pubsub = gcloud.pubsub
53
- # topic = pubsub.topic "my-topic"
54
- # topic.publish "task completed"
53
+ # topic_admin = pubsub.topic_admin
54
+ # publisher = pubsub.publisher "my-topic"
55
+ # publisher.publish "task completed"
55
56
  #
56
57
  # @example The default scope can be overridden with the `scope` option:
57
58
  # require "google/cloud"
@@ -75,10 +76,24 @@ module Google
75
76
  # @param [String] project_id Project identifier for the Pub/Sub service you
76
77
  # are connecting to. If not present, the default project for the
77
78
  # credentials is used.
78
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
79
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
80
- # Google::Auth::Credentials object.
81
- # (See {Google::Cloud::PubSub::Credentials})
79
+ # @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
80
+ # object. (See {Google::Cloud::PubSub::Credentials})
81
+ # @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
82
+ # is deprecated. Providing an unvalidated credential configuration to
83
+ # Google APIs can compromise the security of your systems and data.
84
+ #
85
+ # @example
86
+ #
87
+ # # The recommended way to provide credentials is to use the `make_creds` method
88
+ # # on the appropriate credentials class for your environment.
89
+ #
90
+ # require "googleauth"
91
+ #
92
+ # credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
93
+ # json_key_io: ::File.open("/path/to/keyfile.json")
94
+ # )
95
+ #
96
+ # pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
82
97
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
83
98
  # set of resources and operations that the connection can access. See
84
99
  # [Using OAuth 2.0 to Access Google
@@ -96,8 +111,8 @@ module Google
96
111
  #
97
112
  # pubsub = Google::Cloud.pubsub
98
113
  #
99
- # topic = pubsub.topic "my-topic"
100
- # topic.publish "task completed"
114
+ # publisher = pubsub.publisher "my-topic"
115
+ # publisher.publish "task completed"
101
116
  #
102
117
  def self.pubsub project_id = nil,
103
118
  credentials = nil,
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.0
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  - Chris Smith
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-07-09 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: concurrent-ruby
@@ -17,48 +16,42 @@ dependencies:
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '1.1'
19
+ version: '1.3'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: '1.1'
26
+ version: '1.3'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: google-cloud-core
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
- version: '1.5'
33
+ version: '1.8'
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
- version: '1.5'
40
+ version: '1.8'
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: google-cloud-pubsub-v1
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0.20'
49
- - - "<"
45
+ - - "~>"
50
46
  - !ruby/object:Gem::Version
51
- version: 2.a
47
+ version: '1.11'
52
48
  type: :runtime
53
49
  prerelease: false
54
50
  version_requirements: !ruby/object:Gem::Requirement
55
51
  requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0.20'
59
- - - "<"
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: 2.a
54
+ version: '1.11'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: retriable
64
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +87,7 @@ files:
94
87
  - lib/google-cloud-pubsub.rb
95
88
  - lib/google/cloud/pubsub.rb
96
89
  - lib/google/cloud/pubsub/acknowledge_result.rb
90
+ - lib/google/cloud/pubsub/admin_clients.rb
97
91
  - lib/google/cloud/pubsub/async_publisher.rb
98
92
  - lib/google/cloud/pubsub/async_publisher/batch.rb
99
93
  - lib/google/cloud/pubsub/batch_publisher.rb
@@ -102,33 +96,23 @@ files:
102
96
  - lib/google/cloud/pubsub/errors.rb
103
97
  - lib/google/cloud/pubsub/flow_controller.rb
104
98
  - lib/google/cloud/pubsub/message.rb
105
- - lib/google/cloud/pubsub/policy.rb
99
+ - lib/google/cloud/pubsub/message_listener.rb
100
+ - lib/google/cloud/pubsub/message_listener/enumerator_queue.rb
101
+ - lib/google/cloud/pubsub/message_listener/inventory.rb
102
+ - lib/google/cloud/pubsub/message_listener/sequencer.rb
103
+ - lib/google/cloud/pubsub/message_listener/stream.rb
104
+ - lib/google/cloud/pubsub/message_listener/timed_unary_buffer.rb
106
105
  - lib/google/cloud/pubsub/project.rb
107
106
  - lib/google/cloud/pubsub/publish_result.rb
107
+ - lib/google/cloud/pubsub/publisher.rb
108
108
  - lib/google/cloud/pubsub/received_message.rb
109
- - lib/google/cloud/pubsub/retry_policy.rb
110
- - lib/google/cloud/pubsub/schema.rb
111
- - lib/google/cloud/pubsub/schema/list.rb
112
109
  - lib/google/cloud/pubsub/service.rb
113
- - lib/google/cloud/pubsub/snapshot.rb
114
- - lib/google/cloud/pubsub/snapshot/list.rb
115
110
  - lib/google/cloud/pubsub/subscriber.rb
116
- - lib/google/cloud/pubsub/subscriber/enumerator_queue.rb
117
- - lib/google/cloud/pubsub/subscriber/inventory.rb
118
- - lib/google/cloud/pubsub/subscriber/sequencer.rb
119
- - lib/google/cloud/pubsub/subscriber/stream.rb
120
- - lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb
121
- - lib/google/cloud/pubsub/subscription.rb
122
- - lib/google/cloud/pubsub/subscription/list.rb
123
- - lib/google/cloud/pubsub/subscription/push_config.rb
124
- - lib/google/cloud/pubsub/topic.rb
125
- - lib/google/cloud/pubsub/topic/list.rb
126
111
  - lib/google/cloud/pubsub/version.rb
127
112
  homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
128
113
  licenses:
129
114
  - Apache-2.0
130
115
  metadata: {}
131
- post_install_message:
132
116
  rdoc_options: []
133
117
  require_paths:
134
118
  - lib
@@ -136,15 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
120
  requirements:
137
121
  - - ">="
138
122
  - !ruby/object:Gem::Version
139
- version: '2.7'
123
+ version: '3.1'
140
124
  required_rubygems_version: !ruby/object:Gem::Requirement
141
125
  requirements:
142
126
  - - ">="
143
127
  - !ruby/object:Gem::Version
144
128
  version: '0'
145
129
  requirements: []
146
- rubygems_version: 3.5.6
147
- signing_key:
130
+ rubygems_version: 3.6.9
148
131
  specification_version: 4
149
132
  summary: API Client library for Google Cloud Pub/Sub
150
133
  test_files: []
@@ -1,188 +0,0 @@
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
- # # Policy
23
- #
24
- # Represents a Cloud IAM Policy for the Pub/Sub service.
25
- #
26
- # A common pattern for updating a resource's metadata, such as its Policy,
27
- # is to read the current data from the service, update the data locally,
28
- # and then send the modified data for writing. This pattern may result in
29
- # a conflict if two or more processes attempt the sequence simultaneously.
30
- # IAM solves this problem with the {Google::Cloud::PubSub::Policy#etag}
31
- # property, which is used to verify whether the policy has changed since
32
- # the last request. When you make a request to with an `etag` value, Cloud
33
- # IAM compares the `etag` value in the request with the existing `etag`
34
- # value associated with the policy. It writes the policy only if the
35
- # `etag` values match.
36
- #
37
- # When you update a policy, first read the policy (and its current `etag`)
38
- # from the service, then modify the policy locally, and then write the
39
- # modified policy to the service. See
40
- # {Google::Cloud::PubSub::Topic#policy} and
41
- # {Google::Cloud::PubSub::Topic#policy=}.
42
- #
43
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
44
- # policies
45
- # @see https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#iampolicy
46
- # google.iam.v1.IAMPolicy
47
- #
48
- # @attr [String] etag Used to verify whether the policy has changed since
49
- # the last request. The policy will be written only if the `etag` values
50
- # match.
51
- # @attr [Hash{String => Array<String>}] roles The bindings that associate
52
- # roles with an array of members. See [Understanding
53
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
54
- # listing of primitive and curated roles.
55
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
56
- # for a listing of values and patterns for members.
57
- #
58
- # @example
59
- # require "google/cloud/pubsub"
60
- #
61
- # pubsub = Google::Cloud::PubSub.new
62
- # topic = pubsub.topic "my-topic"
63
- #
64
- # topic.policy do |p|
65
- # p.remove "roles/owner", "user:owner@example.com"
66
- # p.add "roles/owner", "user:newowner@example.com"
67
- # p.roles["roles/viewer"] = ["allUsers"]
68
- # end
69
- #
70
- class Policy
71
- attr_reader :etag
72
- attr_reader :roles
73
-
74
- ##
75
- # @private Creates a Policy object.
76
- def initialize etag, roles
77
- @etag = etag
78
- @roles = roles
79
- end
80
-
81
- ##
82
- # Convenience method for adding a member to a binding on this policy.
83
- # See [Understanding
84
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
85
- # listing of primitive and curated roles.
86
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
87
- # for a listing of values and patterns for members.
88
- #
89
- # @param [String] role_name A Cloud IAM role, such as
90
- # `"roles/pubsub.admin"`.
91
- # @param [String] member A Cloud IAM identity, such as
92
- # `"user:owner@example.com"`.
93
- #
94
- # @example
95
- # require "google/cloud/pubsub"
96
- #
97
- # pubsub = Google::Cloud::PubSub.new
98
- # topic = pubsub.topic "my-topic"
99
- #
100
- # topic.policy do |p|
101
- # p.add "roles/owner", "user:newowner@example.com"
102
- # end
103
- #
104
- def add role_name, member
105
- role(role_name) << member
106
- end
107
-
108
- ##
109
- # Convenience method for removing a member from a binding on this
110
- # policy. See [Understanding
111
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
112
- # listing of primitive and curated roles. See
113
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
114
- # for a listing of values and patterns for members.
115
- #
116
- # @param [String] role_name A Cloud IAM role, such as
117
- # `"roles/pubsub.admin"`.
118
- # @param [String] member A Cloud IAM identity, such as
119
- # `"user:owner@example.com"`.
120
- #
121
- # @example
122
- # require "google/cloud/pubsub"
123
- #
124
- # pubsub = Google::Cloud::PubSub.new
125
- # topic = pubsub.topic "my-topic"
126
- #
127
- # topic.policy do |p|
128
- # p.remove "roles/owner", "user:owner@example.com"
129
- # end
130
- #
131
- def remove role_name, member
132
- role(role_name).delete member
133
- end
134
-
135
- ##
136
- # Convenience method returning the array of members bound to a role in
137
- # this policy, or an empty array if no value is present for the role in
138
- # {#roles}. See [Understanding
139
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
140
- # listing of primitive and curated roles. See
141
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
142
- # for a listing of values and patterns for members.
143
- #
144
- # @return [Array<String>] The members strings, or an empty array.
145
- #
146
- # @example
147
- # require "google/cloud/pubsub"
148
- #
149
- # pubsub = Google::Cloud::PubSub.new
150
- # topic = pubsub.topic "my-topic"
151
- #
152
- # topic.policy do |p|
153
- # p.role("roles/viewer") << "user:viewer@example.com"
154
- # end
155
- #
156
- def role role_name
157
- roles[role_name] ||= []
158
- end
159
-
160
- ##
161
- # @private Convert the Policy to a Google::Iam::V1::Policy object.
162
- def to_grpc
163
- Google::Iam::V1::Policy.new(
164
- etag: etag,
165
- bindings: roles.keys.map do |role_name|
166
- next if roles[role_name].empty?
167
- Google::Iam::V1::Binding.new(
168
- role: role_name,
169
- members: roles[role_name]
170
- )
171
- end.compact
172
- )
173
- end
174
-
175
- ##
176
- # @private New Policy from a Google::Iam::V1::Policy object.
177
- def self.from_grpc grpc
178
- roles = grpc.bindings.each_with_object({}) do |binding, memo|
179
- memo[binding.role] = binding.members.to_a
180
- end
181
- new grpc.etag, roles
182
- end
183
- end
184
- end
185
-
186
- Pubsub = PubSub unless const_defined? :Pubsub
187
- end
188
- end
@@ -1,88 +0,0 @@
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
- # @attr [Numeric] minimum_backoff The minimum delay between consecutive deliveries of a given message. Value
35
- # should be between 0 and 600 seconds. The default value is 10 seconds.
36
- # @attr [Numeric] maximum_backoff The maximum delay between consecutive deliveries of a given message. Value
37
- # should be between 0 and 600 seconds. The default value is 600 seconds.
38
- #
39
- # @example
40
- # require "google/cloud/pubsub"
41
- #
42
- # pubsub = Google::Cloud::PubSub.new
43
- #
44
- # sub = pubsub.subscription "my-topic-sub"
45
- #
46
- # sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
47
- #
48
- # sub.retry_policy.minimum_backoff #=> 5
49
- # sub.retry_policy.maximum_backoff #=> 300
50
- #
51
- class RetryPolicy
52
- attr_reader :minimum_backoff
53
- attr_reader :maximum_backoff
54
-
55
- ##
56
- # Creates a new, immutable RetryPolicy value object.
57
- #
58
- # @attr [Numeric, nil] minimum_backoff The minimum delay between consecutive deliveries of a given message.
59
- # Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 10 seconds.
60
- # @attr [Numeric, nil] maximum_backoff The maximum 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 600 seconds.
62
- #
63
- def initialize minimum_backoff: nil, maximum_backoff: nil
64
- @minimum_backoff = minimum_backoff
65
- @maximum_backoff = maximum_backoff
66
- end
67
-
68
- ##
69
- # @private Convert the RetryPolicy to a Google::Cloud::PubSub::V1::RetryPolicy object.
70
- def to_grpc
71
- Google::Cloud::PubSub::V1::RetryPolicy.new(
72
- minimum_backoff: Convert.number_to_duration(minimum_backoff),
73
- maximum_backoff: Convert.number_to_duration(maximum_backoff)
74
- )
75
- end
76
-
77
- ##
78
- # @private New RetryPolicy from a Google::Cloud::PubSub::V1::RetryPolicy object.
79
- def self.from_grpc grpc
80
- new(
81
- minimum_backoff: Convert.duration_to_number(grpc.minimum_backoff),
82
- maximum_backoff: Convert.duration_to_number(grpc.maximum_backoff)
83
- )
84
- end
85
- end
86
- end
87
- end
88
- end