google-cloud-pubsub 0.33.2 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +4 -4
- data/CHANGELOG.md +45 -0
- data/EMULATOR.md +2 -2
- data/OVERVIEW.md +81 -43
- data/lib/google-cloud-pubsub.rb +10 -7
- data/lib/google/cloud/pubsub.rb +38 -21
- data/lib/google/cloud/pubsub/async_publisher.rb +8 -6
- data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
- data/lib/google/cloud/pubsub/convert.rb +5 -3
- data/lib/google/cloud/pubsub/credentials.rb +6 -4
- data/lib/google/cloud/pubsub/message.rb +9 -6
- data/lib/google/cloud/pubsub/policy.rb +12 -10
- data/lib/google/cloud/pubsub/project.rb +30 -28
- data/lib/google/cloud/pubsub/publish_result.rb +3 -1
- data/lib/google/cloud/pubsub/received_message.rb +11 -10
- data/lib/google/cloud/pubsub/service.rb +47 -37
- data/lib/google/cloud/pubsub/snapshot.rb +11 -9
- data/lib/google/cloud/pubsub/snapshot/list.rb +10 -8
- data/lib/google/cloud/pubsub/subscriber.rb +32 -6
- data/lib/google/cloud/pubsub/subscriber/enumerator_queue.rb +3 -1
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +4 -2
- data/lib/google/cloud/pubsub/subscriber/stream.rb +23 -43
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +221 -0
- data/lib/google/cloud/pubsub/subscription.rb +157 -80
- data/lib/google/cloud/pubsub/subscription/list.rb +12 -10
- data/lib/google/cloud/pubsub/topic.rb +79 -51
- data/lib/google/cloud/pubsub/topic/list.rb +10 -8
- data/lib/google/cloud/pubsub/v1/credentials.rb +4 -2
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +1 -43
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +1 -108
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +107 -61
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +58 -55
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -4
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +177 -128
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -4
- data/lib/google/cloud/pubsub/version.rb +4 -2
- data/lib/google/pubsub/v1/pubsub_pb.rb +48 -40
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +201 -161
- metadata +6 -7
- data/lib/google/cloud/pubsub/subscriber/async_stream_pusher.rb +0 -223
- data/lib/google/cloud/pubsub/subscriber/async_unary_pusher.rb +0 -271
@@ -0,0 +1,221 @@
|
|
1
|
+
# Copyright 2018 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 "concurrent"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module PubSub
|
21
|
+
class Subscriber
|
22
|
+
##
|
23
|
+
# @private
|
24
|
+
class TimedUnaryBuffer
|
25
|
+
attr_reader :max_bytes, :interval
|
26
|
+
|
27
|
+
def initialize subscriber, max_bytes: 10000000, interval: 1.0
|
28
|
+
@subscriber = subscriber
|
29
|
+
@max_bytes = max_bytes
|
30
|
+
@interval = interval
|
31
|
+
|
32
|
+
# Using a Hash ensures there is only one entry for each ack_id in
|
33
|
+
# the buffer. Adding an entry again will overwrite the previous
|
34
|
+
# entry.
|
35
|
+
@register = {}
|
36
|
+
|
37
|
+
@task = Concurrent::TimerTask.new(execution_interval: interval) do
|
38
|
+
flush!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def acknowledge ack_ids
|
43
|
+
return if ack_ids.empty?
|
44
|
+
|
45
|
+
ack_ids.each do |ack_id|
|
46
|
+
# ack has no deadline set, use :ack indicate it is an ack
|
47
|
+
@register[ack_id] = :ack
|
48
|
+
end
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def modify_ack_deadline deadline, ack_ids
|
54
|
+
return if ack_ids.empty?
|
55
|
+
|
56
|
+
ack_ids.each do |ack_id|
|
57
|
+
@register[ack_id] = deadline
|
58
|
+
end
|
59
|
+
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def renew_lease deadline, ack_ids
|
64
|
+
return if ack_ids.empty?
|
65
|
+
|
66
|
+
ack_ids.each do |ack_id|
|
67
|
+
# Do not overwrite pending actions when renewing leased messages.
|
68
|
+
@register[ack_id] ||= deadline
|
69
|
+
end
|
70
|
+
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def flush!
|
75
|
+
# Grab requests from the buffer and release synchronize ASAP
|
76
|
+
requests = flush_requests!
|
77
|
+
return if requests.empty?
|
78
|
+
|
79
|
+
# Perform the RCP calls concurrently
|
80
|
+
with_threadpool do |pool|
|
81
|
+
requests[:acknowledge].each do |ack_req|
|
82
|
+
add_future pool do
|
83
|
+
@subscriber.service.acknowledge \
|
84
|
+
ack_req.subscription, *ack_req.ack_ids
|
85
|
+
end
|
86
|
+
end
|
87
|
+
requests[:modify_ack_deadline].each do |mod_ack_req|
|
88
|
+
add_future pool do
|
89
|
+
@subscriber.service.modify_ack_deadline \
|
90
|
+
mod_ack_req.subscription, mod_ack_req.ack_ids,
|
91
|
+
mod_ack_req.ack_deadline_seconds
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
def start
|
100
|
+
@task.execute
|
101
|
+
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
def stop
|
106
|
+
@task.shutdown
|
107
|
+
flush!
|
108
|
+
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def started?
|
113
|
+
@task.running?
|
114
|
+
end
|
115
|
+
|
116
|
+
def stopped?
|
117
|
+
!started?
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def flush_requests!
|
123
|
+
return {} if @register.empty?
|
124
|
+
|
125
|
+
prev_reg = @register
|
126
|
+
@register = Concurrent::Map.new
|
127
|
+
|
128
|
+
groups = prev_reg.each_pair.group_by { |_ack_id, delay| delay }
|
129
|
+
req_hash = Hash[groups.map { |k, v| [k, v.map(&:first)] }]
|
130
|
+
|
131
|
+
requests = { acknowledge: [] }
|
132
|
+
ack_ids = Array(req_hash.delete(:ack)) # ack has no deadline set
|
133
|
+
if ack_ids.any?
|
134
|
+
requests[:acknowledge] = create_acknowledge_requests ack_ids
|
135
|
+
end
|
136
|
+
requests[:modify_ack_deadline] =
|
137
|
+
req_hash.map do |mod_deadline, mod_ack_ids|
|
138
|
+
create_modify_ack_deadline_requests mod_deadline, mod_ack_ids
|
139
|
+
end.flatten
|
140
|
+
requests
|
141
|
+
end
|
142
|
+
|
143
|
+
def create_acknowledge_requests ack_ids
|
144
|
+
req = Google::Cloud::PubSub::V1::AcknowledgeRequest.new(
|
145
|
+
subscription: subscription_name,
|
146
|
+
ack_ids: ack_ids
|
147
|
+
)
|
148
|
+
addl_to_create = req.to_proto.bytesize / max_bytes
|
149
|
+
return [req] if addl_to_create.zero?
|
150
|
+
|
151
|
+
ack_ids.each_slice(addl_to_create + 1).map do |sliced_ack_ids|
|
152
|
+
Google::Cloud::PubSub::V1::AcknowledgeRequest.new(
|
153
|
+
subscription: subscription_name,
|
154
|
+
ack_ids: sliced_ack_ids
|
155
|
+
)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def create_modify_ack_deadline_requests deadline, ack_ids
|
160
|
+
req = Google::Cloud::PubSub::V1::ModifyAckDeadlineRequest.new(
|
161
|
+
subscription: subscription_name,
|
162
|
+
ack_ids: ack_ids,
|
163
|
+
ack_deadline_seconds: deadline
|
164
|
+
)
|
165
|
+
addl_to_create = req.to_proto.bytesize / max_bytes
|
166
|
+
return [req] if addl_to_create.zero?
|
167
|
+
|
168
|
+
ack_ids.each_slice(addl_to_create + 1).map do |sliced_ack_ids|
|
169
|
+
Google::Cloud::PubSub::V1::ModifyAckDeadlineRequest.new(
|
170
|
+
subscription: subscription_name,
|
171
|
+
ack_ids: sliced_ack_ids,
|
172
|
+
ack_deadline_seconds: deadline
|
173
|
+
)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def subscription_name
|
178
|
+
@subscriber.subscription_name
|
179
|
+
end
|
180
|
+
|
181
|
+
def push_threads
|
182
|
+
@subscriber.push_threads
|
183
|
+
end
|
184
|
+
|
185
|
+
def error! error
|
186
|
+
@subscriber.error! error
|
187
|
+
end
|
188
|
+
|
189
|
+
def with_threadpool
|
190
|
+
pool = Concurrent::FixedThreadPool.new @subscriber.push_threads
|
191
|
+
|
192
|
+
yield pool
|
193
|
+
|
194
|
+
pool.shutdown
|
195
|
+
pool.wait_for_termination 60
|
196
|
+
return if pool.shutdown?
|
197
|
+
|
198
|
+
pool.kill
|
199
|
+
begin
|
200
|
+
raise "Timeout making subscriber API calls"
|
201
|
+
rescue StandardError => error
|
202
|
+
error! error
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def add_future pool
|
207
|
+
Concurrent::Future.new(executor: pool) do
|
208
|
+
begin
|
209
|
+
yield
|
210
|
+
rescue StandardError => error
|
211
|
+
error! error
|
212
|
+
end
|
213
|
+
end.execute
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
220
|
+
end
|
221
|
+
end
|
@@ -22,7 +22,7 @@ require "google/cloud/pubsub/subscriber"
|
|
22
22
|
|
23
23
|
module Google
|
24
24
|
module Cloud
|
25
|
-
module
|
25
|
+
module PubSub
|
26
26
|
##
|
27
27
|
# # Subscription
|
28
28
|
#
|
@@ -32,7 +32,7 @@ module Google
|
|
32
32
|
# @example
|
33
33
|
# require "google/cloud/pubsub"
|
34
34
|
#
|
35
|
-
# pubsub = Google::Cloud::
|
35
|
+
# pubsub = Google::Cloud::PubSub.new
|
36
36
|
#
|
37
37
|
# sub = pubsub.subscription "my-topic-sub"
|
38
38
|
# subscriber = sub.listen do |received_message|
|
@@ -52,7 +52,7 @@ module Google
|
|
52
52
|
attr_accessor :service
|
53
53
|
|
54
54
|
##
|
55
|
-
# @private The gRPC Google::
|
55
|
+
# @private The gRPC Google::Cloud::PubSub::V1::Subscription object.
|
56
56
|
attr_accessor :grpc
|
57
57
|
|
58
58
|
##
|
@@ -60,49 +60,67 @@ module Google
|
|
60
60
|
def initialize
|
61
61
|
@service = nil
|
62
62
|
@grpc = nil
|
63
|
-
@
|
63
|
+
@resource_name = nil
|
64
64
|
@exists = nil
|
65
65
|
end
|
66
66
|
|
67
67
|
##
|
68
68
|
# The name of the subscription.
|
69
|
+
#
|
70
|
+
# @return [String]
|
69
71
|
def name
|
72
|
+
return @resource_name if reference?
|
70
73
|
@grpc.name
|
71
74
|
end
|
72
75
|
|
73
76
|
##
|
74
77
|
# The {Topic} from which this subscription receives messages.
|
75
78
|
#
|
79
|
+
# Makes an API call to retrieve the topic information when called on a
|
80
|
+
# reference object. See {#reference?}.
|
81
|
+
#
|
76
82
|
# @return [Topic]
|
77
83
|
#
|
78
84
|
# @example
|
79
85
|
# require "google/cloud/pubsub"
|
80
86
|
#
|
81
|
-
# pubsub = Google::Cloud::
|
87
|
+
# pubsub = Google::Cloud::PubSub.new
|
82
88
|
#
|
83
89
|
# sub = pubsub.subscription "my-topic-sub"
|
84
90
|
# sub.topic.name #=> "projects/my-project/topics/my-topic"
|
85
91
|
#
|
86
92
|
def topic
|
87
93
|
ensure_grpc!
|
88
|
-
Topic.
|
94
|
+
Topic.from_name @grpc.topic, service
|
89
95
|
end
|
90
96
|
|
91
97
|
##
|
92
98
|
# This value is the maximum number of seconds after a subscriber
|
93
99
|
# receives a message before the subscriber should acknowledge the
|
94
100
|
# message.
|
101
|
+
#
|
102
|
+
# Makes an API call to retrieve the deadline value when called on a
|
103
|
+
# reference object. See {#reference?}.
|
104
|
+
#
|
105
|
+
# @return [Integer]
|
95
106
|
def deadline
|
96
107
|
ensure_grpc!
|
97
108
|
@grpc.ack_deadline_seconds
|
98
109
|
end
|
99
110
|
|
111
|
+
##
|
112
|
+
# Sets the maximum number of seconds after a subscriber
|
113
|
+
# receives a message before the subscriber should acknowledge the
|
114
|
+
# message.
|
115
|
+
#
|
116
|
+
# @param [Integer] new_deadline The new deadline value.
|
117
|
+
#
|
100
118
|
def deadline= new_deadline
|
101
|
-
update_grpc =
|
102
|
-
|
119
|
+
update_grpc = Google::Cloud::PubSub::V1::Subscription.new \
|
120
|
+
name: name, ack_deadline_seconds: new_deadline
|
103
121
|
@grpc = service.update_subscription update_grpc,
|
104
122
|
:ack_deadline_seconds
|
105
|
-
@
|
123
|
+
@resource_name = nil
|
106
124
|
end
|
107
125
|
|
108
126
|
##
|
@@ -111,6 +129,9 @@ module Google
|
|
111
129
|
# they are acknowledged, until they fall out of the {#retention} window.
|
112
130
|
# Default is `false`.
|
113
131
|
#
|
132
|
+
# Makes an API call to retrieve the retain_acked value when called on a
|
133
|
+
# reference object. See {#reference?}.
|
134
|
+
#
|
114
135
|
# @return [Boolean] Returns `true` if acknowledged messages are
|
115
136
|
# retained.
|
116
137
|
#
|
@@ -119,12 +140,18 @@ module Google
|
|
119
140
|
@grpc.retain_acked_messages
|
120
141
|
end
|
121
142
|
|
143
|
+
##
|
144
|
+
# Sets whether to retain acknowledged messages.
|
145
|
+
#
|
146
|
+
# @param [Boolean] new_retain_acked The new retain acknowledged messages
|
147
|
+
# value.
|
148
|
+
#
|
122
149
|
def retain_acked= new_retain_acked
|
123
|
-
update_grpc =
|
124
|
-
|
150
|
+
update_grpc = Google::Cloud::PubSub::V1::Subscription.new \
|
151
|
+
name: name, retain_acked_messages: !(!new_retain_acked)
|
125
152
|
@grpc = service.update_subscription update_grpc,
|
126
153
|
:retain_acked_messages
|
127
|
-
@
|
154
|
+
@resource_name = nil
|
128
155
|
end
|
129
156
|
|
130
157
|
##
|
@@ -136,6 +163,9 @@ module Google
|
|
136
163
|
# less than 600 seconds (10 minutes). Default is 604,800 seconds (7
|
137
164
|
# days).
|
138
165
|
#
|
166
|
+
# Makes an API call to retrieve the retention value when called on a
|
167
|
+
# reference object. See {#reference?}.
|
168
|
+
#
|
139
169
|
# @return [Numeric] The message retention duration in seconds.
|
140
170
|
#
|
141
171
|
def retention
|
@@ -143,18 +173,29 @@ module Google
|
|
143
173
|
Convert.duration_to_number @grpc.message_retention_duration
|
144
174
|
end
|
145
175
|
|
176
|
+
##
|
177
|
+
# Sets the message retention duration in seconds.
|
178
|
+
#
|
179
|
+
# @param [Numeric] new_retention The new retention value.
|
180
|
+
#
|
146
181
|
def retention= new_retention
|
147
|
-
|
148
|
-
update_grpc
|
149
|
-
|
182
|
+
new_retention_duration = Convert.number_to_duration new_retention
|
183
|
+
update_grpc = Google::Cloud::PubSub::V1::Subscription.new \
|
184
|
+
name: name, message_retention_duration: new_retention_duration
|
150
185
|
@grpc = service.update_subscription update_grpc,
|
151
186
|
:message_retention_duration
|
152
|
-
@
|
187
|
+
@resource_name = nil
|
153
188
|
end
|
154
189
|
|
155
190
|
##
|
156
191
|
# Returns the URL locating the endpoint to which messages should be
|
157
192
|
# pushed.
|
193
|
+
#
|
194
|
+
# Makes an API call to retrieve the endpoint value when called on a
|
195
|
+
# reference object. See {#reference?}.
|
196
|
+
#
|
197
|
+
# @return [String]
|
198
|
+
#
|
158
199
|
def endpoint
|
159
200
|
ensure_grpc!
|
160
201
|
@grpc.push_config.push_endpoint if @grpc.push_config
|
@@ -162,15 +203,18 @@ module Google
|
|
162
203
|
|
163
204
|
##
|
164
205
|
# Sets the URL locating the endpoint to which messages should be pushed.
|
206
|
+
#
|
207
|
+
# @param [String] new_endpoint The new endpoint value.
|
208
|
+
#
|
165
209
|
def endpoint= new_endpoint
|
166
210
|
ensure_service!
|
167
211
|
service.modify_push_config name, new_endpoint, {}
|
168
212
|
|
169
|
-
return
|
213
|
+
return if reference?
|
170
214
|
|
171
|
-
@grpc.push_config = Google::
|
215
|
+
@grpc.push_config = Google::Cloud::PubSub::V1::PushConfig.new(
|
172
216
|
push_endpoint: new_endpoint,
|
173
|
-
attributes:
|
217
|
+
attributes: {}
|
174
218
|
)
|
175
219
|
end
|
176
220
|
|
@@ -182,9 +226,13 @@ module Google
|
|
182
226
|
# The returned hash is frozen and changes are not allowed. Use
|
183
227
|
# {#labels=} to update the labels for this subscription.
|
184
228
|
#
|
229
|
+
# Makes an API call to retrieve the labels value when called on a
|
230
|
+
# reference object. See {#reference?}.
|
231
|
+
#
|
185
232
|
# @return [Hash] The frozen labels hash.
|
186
233
|
#
|
187
234
|
def labels
|
235
|
+
ensure_grpc!
|
188
236
|
@grpc.labels.to_h.freeze
|
189
237
|
end
|
190
238
|
|
@@ -202,28 +250,31 @@ module Google
|
|
202
250
|
#
|
203
251
|
def labels= new_labels
|
204
252
|
raise ArgumentError, "Value must be a Hash" if new_labels.nil?
|
205
|
-
|
206
|
-
|
207
|
-
update_grpc = @grpc.dup
|
208
|
-
update_grpc.labels = labels_map
|
253
|
+
update_grpc = Google::Cloud::PubSub::V1::Subscription.new \
|
254
|
+
name: name, labels: new_labels
|
209
255
|
@grpc = service.update_subscription update_grpc, :labels
|
210
|
-
@
|
256
|
+
@resource_name = nil
|
211
257
|
end
|
212
258
|
|
213
259
|
##
|
214
260
|
# Determines whether the subscription exists in the Pub/Sub service.
|
215
261
|
#
|
262
|
+
# Makes an API call to determine whether the subscription resource
|
263
|
+
# exists when called on a reference object. See {#reference?}.
|
264
|
+
#
|
265
|
+
# @return [Boolean]
|
266
|
+
#
|
216
267
|
# @example
|
217
268
|
# require "google/cloud/pubsub"
|
218
269
|
#
|
219
|
-
# pubsub = Google::Cloud::
|
270
|
+
# pubsub = Google::Cloud::PubSub.new
|
220
271
|
#
|
221
272
|
# sub = pubsub.subscription "my-topic-sub"
|
222
273
|
# sub.exists? #=> true
|
223
274
|
#
|
224
275
|
def exists?
|
225
|
-
# Always true if the object is not set as
|
226
|
-
return true unless
|
276
|
+
# Always true if the object is not set as reference
|
277
|
+
return true unless reference?
|
227
278
|
# If we have a value, return it
|
228
279
|
return @exists unless @exists.nil?
|
229
280
|
ensure_grpc!
|
@@ -232,23 +283,6 @@ module Google
|
|
232
283
|
@exists = false
|
233
284
|
end
|
234
285
|
|
235
|
-
##
|
236
|
-
# @private
|
237
|
-
# Determines whether the subscription object was created with an
|
238
|
-
# HTTP call.
|
239
|
-
#
|
240
|
-
# @example
|
241
|
-
# require "google/cloud/pubsub"
|
242
|
-
#
|
243
|
-
# pubsub = Google::Cloud::Pubsub.new
|
244
|
-
#
|
245
|
-
# sub = pubsub.get_subscription "my-topic-sub"
|
246
|
-
# sub.lazy? #=> nil
|
247
|
-
#
|
248
|
-
def lazy?
|
249
|
-
@lazy
|
250
|
-
end
|
251
|
-
|
252
286
|
##
|
253
287
|
# Deletes an existing subscription.
|
254
288
|
# All pending messages in the subscription are immediately dropped.
|
@@ -258,7 +292,7 @@ module Google
|
|
258
292
|
# @example
|
259
293
|
# require "google/cloud/pubsub"
|
260
294
|
#
|
261
|
-
# pubsub = Google::Cloud::
|
295
|
+
# pubsub = Google::Cloud::PubSub.new
|
262
296
|
#
|
263
297
|
# sub = pubsub.subscription "my-topic-sub"
|
264
298
|
# sub.delete
|
@@ -290,12 +324,12 @@ module Google
|
|
290
324
|
# request. The Pub/Sub system may return fewer than the number
|
291
325
|
# specified. The default value is `100`, the maximum value is `1000`.
|
292
326
|
#
|
293
|
-
# @return [Array<Google::Cloud::
|
327
|
+
# @return [Array<Google::Cloud::PubSub::ReceivedMessage>]
|
294
328
|
#
|
295
329
|
# @example
|
296
330
|
# require "google/cloud/pubsub"
|
297
331
|
#
|
298
|
-
# pubsub = Google::Cloud::
|
332
|
+
# pubsub = Google::Cloud::PubSub.new
|
299
333
|
#
|
300
334
|
# sub = pubsub.subscription "my-topic-sub"
|
301
335
|
# sub.pull.each { |received_message| received_message.acknowledge! }
|
@@ -303,7 +337,7 @@ module Google
|
|
303
337
|
# @example A maximum number of messages returned can also be specified:
|
304
338
|
# require "google/cloud/pubsub"
|
305
339
|
#
|
306
|
-
# pubsub = Google::Cloud::
|
340
|
+
# pubsub = Google::Cloud::PubSub.new
|
307
341
|
#
|
308
342
|
# sub = pubsub.subscription "my-topic-sub"
|
309
343
|
# sub.pull(max: 10).each do |received_message|
|
@@ -313,7 +347,7 @@ module Google
|
|
313
347
|
# @example The call can block until messages are available:
|
314
348
|
# require "google/cloud/pubsub"
|
315
349
|
#
|
316
|
-
# pubsub = Google::Cloud::
|
350
|
+
# pubsub = Google::Cloud::PubSub.new
|
317
351
|
#
|
318
352
|
# sub = pubsub.subscription "my-topic-sub"
|
319
353
|
# received_messages = sub.pull immediate: false
|
@@ -345,12 +379,12 @@ module Google
|
|
345
379
|
# request. The Pub/Sub system may return fewer than the number
|
346
380
|
# specified. The default value is `100`, the maximum value is `1000`.
|
347
381
|
#
|
348
|
-
# @return [Array<Google::Cloud::
|
382
|
+
# @return [Array<Google::Cloud::PubSub::ReceivedMessage>]
|
349
383
|
#
|
350
384
|
# @example
|
351
385
|
# require "google/cloud/pubsub"
|
352
386
|
#
|
353
|
-
# pubsub = Google::Cloud::
|
387
|
+
# pubsub = Google::Cloud::PubSub.new
|
354
388
|
#
|
355
389
|
# sub = pubsub.subscription "my-topic-sub"
|
356
390
|
# received_messages = sub.wait_for_messages
|
@@ -370,6 +404,9 @@ module Google
|
|
370
404
|
# will hold received messages before modifying the message's ack
|
371
405
|
# deadline. The minimum is 10, the maximum is 600. Default is
|
372
406
|
# {#deadline}. Optional.
|
407
|
+
#
|
408
|
+
# Makes an API call to retrieve the deadline value when called on a
|
409
|
+
# reference object. See {#reference?}.
|
373
410
|
# @param [Integer] streams The number of concurrent streams to open to
|
374
411
|
# pull messages from the subscription. Default is 4. Optional.
|
375
412
|
# @param [Integer] inventory The number of received messages to be
|
@@ -382,9 +419,9 @@ module Google
|
|
382
419
|
# * `:callback` (Integer) The number of threads used to handle the
|
383
420
|
# received messages. Default is 8.
|
384
421
|
# * `:push` (Integer) The number of threads to handle
|
385
|
-
# acknowledgement ({ReceivedMessage#ack!}) and
|
386
|
-
# ({ReceivedMessage#nack!},
|
387
|
-
# 4.
|
422
|
+
# acknowledgement ({ReceivedMessage#ack!}) and modify ack deadline
|
423
|
+
# messages ({ReceivedMessage#nack!},
|
424
|
+
# {ReceivedMessage#modify_ack_deadline!}). Default is 4.
|
388
425
|
#
|
389
426
|
# @yield [received_message] a block for processing new messages
|
390
427
|
# @yieldparam [ReceivedMessage] received_message the newly received
|
@@ -395,7 +432,7 @@ module Google
|
|
395
432
|
# @example
|
396
433
|
# require "google/cloud/pubsub"
|
397
434
|
#
|
398
|
-
# pubsub = Google::Cloud::
|
435
|
+
# pubsub = Google::Cloud::PubSub.new
|
399
436
|
#
|
400
437
|
# sub = pubsub.subscription "my-topic-sub"
|
401
438
|
#
|
@@ -413,7 +450,7 @@ module Google
|
|
413
450
|
# @example Configuring to increase concurrent callbacks:
|
414
451
|
# require "google/cloud/pubsub"
|
415
452
|
#
|
416
|
-
# pubsub = Google::Cloud::
|
453
|
+
# pubsub = Google::Cloud::PubSub.new
|
417
454
|
#
|
418
455
|
# sub = pubsub.subscription "my-topic-sub"
|
419
456
|
#
|
@@ -452,7 +489,7 @@ module Google
|
|
452
489
|
# @example
|
453
490
|
# require "google/cloud/pubsub"
|
454
491
|
#
|
455
|
-
# pubsub = Google::Cloud::
|
492
|
+
# pubsub = Google::Cloud::PubSub.new
|
456
493
|
#
|
457
494
|
# sub = pubsub.subscription "my-topic-sub"
|
458
495
|
# received_messages = sub.pull
|
@@ -474,7 +511,7 @@ module Google
|
|
474
511
|
# make the messages available for redelivery if the processing was
|
475
512
|
# interrupted.
|
476
513
|
#
|
477
|
-
# See also {ReceivedMessage#
|
514
|
+
# See also {ReceivedMessage#modify_ack_deadline!}.
|
478
515
|
#
|
479
516
|
# @param [Integer] new_deadline The new ack deadline in seconds from the
|
480
517
|
# time this request is sent to the Pub/Sub system. Must be >= 0. For
|
@@ -487,7 +524,7 @@ module Google
|
|
487
524
|
# @example
|
488
525
|
# require "google/cloud/pubsub"
|
489
526
|
#
|
490
|
-
# pubsub = Google::Cloud::
|
527
|
+
# pubsub = Google::Cloud::PubSub.new
|
491
528
|
#
|
492
529
|
# sub = pubsub.subscription "my-topic-sub"
|
493
530
|
# received_messages = sub.pull
|
@@ -499,7 +536,6 @@ module Google
|
|
499
536
|
service.modify_ack_deadline name, ack_ids, new_deadline
|
500
537
|
true
|
501
538
|
end
|
502
|
-
alias delay modify_ack_deadline
|
503
539
|
|
504
540
|
##
|
505
541
|
# Creates a new {Snapshot} from the subscription. The created snapshot
|
@@ -529,12 +565,12 @@ module Google
|
|
529
565
|
# label in the list must have a different key. See [Creating and
|
530
566
|
# Managing Labels](https://cloud.google.com/pubsub/docs/labels).
|
531
567
|
#
|
532
|
-
# @return [Google::Cloud::
|
568
|
+
# @return [Google::Cloud::PubSub::Snapshot]
|
533
569
|
#
|
534
570
|
# @example
|
535
571
|
# require "google/cloud/pubsub"
|
536
572
|
#
|
537
|
-
# pubsub = Google::Cloud::
|
573
|
+
# pubsub = Google::Cloud::PubSub.new
|
538
574
|
# sub = pubsub.subscription "my-sub"
|
539
575
|
#
|
540
576
|
# snapshot = sub.create_snapshot "my-snapshot"
|
@@ -543,7 +579,7 @@ module Google
|
|
543
579
|
# @example Without providing a name:
|
544
580
|
# require "google/cloud/pubsub"
|
545
581
|
#
|
546
|
-
# pubsub = Google::Cloud::
|
582
|
+
# pubsub = Google::Cloud::PubSub.new
|
547
583
|
# sub = pubsub.subscription "my-sub"
|
548
584
|
#
|
549
585
|
# snapshot = sub.create_snapshot
|
@@ -579,7 +615,7 @@ module Google
|
|
579
615
|
# @example Using a snapshot
|
580
616
|
# require "google/cloud/pubsub"
|
581
617
|
#
|
582
|
-
# pubsub = Google::Cloud::
|
618
|
+
# pubsub = Google::Cloud::PubSub.new
|
583
619
|
# sub = pubsub.subscription "my-sub"
|
584
620
|
#
|
585
621
|
# snapshot = sub.create_snapshot
|
@@ -592,7 +628,7 @@ module Google
|
|
592
628
|
# @example Using a time:
|
593
629
|
# require "google/cloud/pubsub"
|
594
630
|
#
|
595
|
-
# pubsub = Google::Cloud::
|
631
|
+
# pubsub = Google::Cloud::PubSub.new
|
596
632
|
# sub = pubsub.subscription "my-sub"
|
597
633
|
#
|
598
634
|
# time = Time.now
|
@@ -608,6 +644,44 @@ module Google
|
|
608
644
|
true
|
609
645
|
end
|
610
646
|
|
647
|
+
##
|
648
|
+
# Determines whether the subscription object was created without
|
649
|
+
# retrieving the resource representation from the Pub/Sub service.
|
650
|
+
#
|
651
|
+
# @return [Boolean] `true` when the subscription was created without a
|
652
|
+
# resource representation, `false` otherwise.
|
653
|
+
#
|
654
|
+
# @example
|
655
|
+
# require "google/cloud/pubsub"
|
656
|
+
#
|
657
|
+
# pubsub = Google::Cloud::PubSub.new
|
658
|
+
#
|
659
|
+
# sub = pubsub.get_subscription "my-topic-sub", skip_lookup: true
|
660
|
+
# sub.reference? #=> true
|
661
|
+
#
|
662
|
+
def reference?
|
663
|
+
@grpc.nil?
|
664
|
+
end
|
665
|
+
|
666
|
+
##
|
667
|
+
# Determines whether the subscription object was created with a resource
|
668
|
+
# representation from the Pub/Sub service.
|
669
|
+
#
|
670
|
+
# @return [Boolean] `true` when the subscription was created with a
|
671
|
+
# resource representation, `false` otherwise.
|
672
|
+
#
|
673
|
+
# @example
|
674
|
+
# require "google/cloud/pubsub"
|
675
|
+
#
|
676
|
+
# pubsub = Google::Cloud::PubSub.new
|
677
|
+
#
|
678
|
+
# sub = pubsub.get_subscription "my-topic-sub"
|
679
|
+
# sub.resource? #=> true
|
680
|
+
#
|
681
|
+
def resource?
|
682
|
+
!@grpc.nil?
|
683
|
+
end
|
684
|
+
|
611
685
|
##
|
612
686
|
# Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
|
613
687
|
# policy for this subscription.
|
@@ -627,7 +701,7 @@ module Google
|
|
627
701
|
# @example
|
628
702
|
# require "google/cloud/pubsub"
|
629
703
|
#
|
630
|
-
# pubsub = Google::Cloud::
|
704
|
+
# pubsub = Google::Cloud::PubSub.new
|
631
705
|
# sub = pubsub.subscription "my-subscription"
|
632
706
|
#
|
633
707
|
# policy = sub.policy
|
@@ -635,7 +709,7 @@ module Google
|
|
635
709
|
# @example Update the policy by passing a block:
|
636
710
|
# require "google/cloud/pubsub"
|
637
711
|
#
|
638
|
-
# pubsub = Google::Cloud::
|
712
|
+
# pubsub = Google::Cloud::PubSub.new
|
639
713
|
# sub = pubsub.subscription "my-subscription"
|
640
714
|
#
|
641
715
|
# sub.policy do |p|
|
@@ -654,7 +728,7 @@ module Google
|
|
654
728
|
##
|
655
729
|
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
656
730
|
# policy for this subscription. The policy should be read from
|
657
|
-
# {#policy}. See {Google::Cloud::
|
731
|
+
# {#policy}. See {Google::Cloud::PubSub::Policy} for an explanation of
|
658
732
|
# the policy `etag` property and how to modify policies.
|
659
733
|
#
|
660
734
|
# You can also update the policy by passing a block to {#policy}, which
|
@@ -671,7 +745,7 @@ module Google
|
|
671
745
|
# @example
|
672
746
|
# require "google/cloud/pubsub"
|
673
747
|
#
|
674
|
-
# pubsub = Google::Cloud::
|
748
|
+
# pubsub = Google::Cloud::PubSub.new
|
675
749
|
# sub = pubsub.subscription "my-subscription"
|
676
750
|
#
|
677
751
|
# policy = sub.policy # API call
|
@@ -712,7 +786,7 @@ module Google
|
|
712
786
|
# @example
|
713
787
|
# require "google/cloud/pubsub"
|
714
788
|
#
|
715
|
-
# pubsub = Google::Cloud::
|
789
|
+
# pubsub = Google::Cloud::PubSub.new
|
716
790
|
# sub = pubsub.subscription "my-subscription"
|
717
791
|
# perms = sub.test_permissions "pubsub.subscriptions.get",
|
718
792
|
# "pubsub.subscriptions.consume"
|
@@ -727,7 +801,8 @@ module Google
|
|
727
801
|
end
|
728
802
|
|
729
803
|
##
|
730
|
-
# @private
|
804
|
+
# @private
|
805
|
+
# New Subscription from a Google::Cloud::PubSub::V1::Subscription
|
731
806
|
# object.
|
732
807
|
def self.from_grpc grpc, service
|
733
808
|
new.tap do |f|
|
@@ -737,12 +812,12 @@ module Google
|
|
737
812
|
end
|
738
813
|
|
739
814
|
##
|
740
|
-
# @private New
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
from_grpc(
|
745
|
-
s.instance_variable_set :@
|
815
|
+
# @private New reference {Subscription} object without making an HTTP
|
816
|
+
# request.
|
817
|
+
def self.from_name name, service, options = {}
|
818
|
+
name = service.subscription_path name, options
|
819
|
+
from_grpc(nil, service).tap do |s|
|
820
|
+
s.instance_variable_set :@resource_name, name
|
746
821
|
end
|
747
822
|
end
|
748
823
|
|
@@ -756,11 +831,11 @@ module Google
|
|
756
831
|
end
|
757
832
|
|
758
833
|
##
|
759
|
-
# Ensures a Google::
|
834
|
+
# Ensures a Google::Cloud::PubSub::V1::Subscription object exists.
|
760
835
|
def ensure_grpc!
|
761
836
|
ensure_service!
|
762
|
-
@grpc = service.get_subscription name if
|
763
|
-
@
|
837
|
+
@grpc = service.get_subscription name if reference?
|
838
|
+
@resource_name = nil
|
764
839
|
end
|
765
840
|
|
766
841
|
##
|
@@ -773,5 +848,7 @@ module Google
|
|
773
848
|
end
|
774
849
|
end
|
775
850
|
end
|
851
|
+
|
852
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
776
853
|
end
|
777
854
|
end
|