google-cloud-pubsub 2.22.0 → 3.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/CHANGELOG.md +27 -0
- data/OVERVIEW.md +188 -144
- data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
- data/lib/google/cloud/pubsub/async_publisher.rb +9 -9
- data/lib/google/cloud/pubsub/batch_publisher.rb +4 -4
- data/lib/google/cloud/pubsub/errors.rb +3 -3
- data/lib/google/cloud/pubsub/message.rb +8 -8
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +2 -4
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +10 -10
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +1 -1
- data/lib/google/cloud/pubsub/message_listener.rb +413 -0
- data/lib/google/cloud/pubsub/project.rb +98 -531
- data/lib/google/cloud/pubsub/publisher.rb +373 -0
- data/lib/google/cloud/pubsub/received_message.rb +50 -45
- data/lib/google/cloud/pubsub/service.rb +24 -386
- data/lib/google/cloud/pubsub/subscriber.rb +442 -279
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/cloud/pubsub.rb +8 -15
- data/lib/google-cloud-pubsub.rb +5 -4
- metadata +18 -26
- data/lib/google/cloud/pubsub/policy.rb +0 -188
- data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
- data/lib/google/cloud/pubsub/schema/list.rb +0 -180
- data/lib/google/cloud/pubsub/schema.rb +0 -378
- data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
- data/lib/google/cloud/pubsub/snapshot.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
- data/lib/google/cloud/pubsub/subscription.rb +0 -1467
- data/lib/google/cloud/pubsub/topic/list.rb +0 -171
- data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -0,0 +1,373 @@
|
|
1
|
+
# Copyright 2015 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
|
+
require "google/cloud/pubsub/async_publisher"
|
18
|
+
require "google/cloud/pubsub/batch_publisher"
|
19
|
+
|
20
|
+
module Google
|
21
|
+
module Cloud
|
22
|
+
module PubSub
|
23
|
+
##
|
24
|
+
# # Publisher
|
25
|
+
#
|
26
|
+
# A {Publisher} is the primary interface for data plane operations on a
|
27
|
+
# topic, including publishing messages, batching messages for higher
|
28
|
+
# throughput, and managing ordering keys.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# require "google/cloud/pubsub"
|
32
|
+
#
|
33
|
+
# pubsub = Google::Cloud::PubSub.new
|
34
|
+
#
|
35
|
+
# publisher = pubsub.publisher "my-topic-only"
|
36
|
+
#
|
37
|
+
# publisher.publish "task completed"
|
38
|
+
#
|
39
|
+
class Publisher
|
40
|
+
##
|
41
|
+
# @private The Service object.
|
42
|
+
attr_accessor :service
|
43
|
+
|
44
|
+
##
|
45
|
+
# @private The Google::Cloud::PubSub::V1::Topic object.
|
46
|
+
attr_accessor :grpc
|
47
|
+
|
48
|
+
##
|
49
|
+
# @private Create an empty {Topic} object.
|
50
|
+
def initialize
|
51
|
+
@service = nil
|
52
|
+
@grpc = nil
|
53
|
+
@resource_name = nil
|
54
|
+
@async_opts = {}
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# AsyncPublisher object used to publish multiple messages in batches.
|
59
|
+
#
|
60
|
+
# @return [AsyncPublisher] Returns publisher object if calls to
|
61
|
+
# {#publish_async} have been made, returns `nil` otherwise.
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# require "google/cloud/pubsub"
|
65
|
+
#
|
66
|
+
# pubsub = Google::Cloud::PubSub.new
|
67
|
+
#
|
68
|
+
# publisher = pubsub.publisher "my-topic"
|
69
|
+
# publisher.publish_async "task completed" do |result|
|
70
|
+
# if result.succeeded?
|
71
|
+
# log_publish_success result.data
|
72
|
+
# else
|
73
|
+
# log_publish_failure result.data, result.error
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# publisher.async_publisher.stop!
|
78
|
+
#
|
79
|
+
def async_publisher
|
80
|
+
@async_publisher
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# The name of the publisher.
|
85
|
+
#
|
86
|
+
# @return [String] A fully-qualified topic name in the form
|
87
|
+
# `projects/{project_id}/topics/{topic_id}`.
|
88
|
+
#
|
89
|
+
def name
|
90
|
+
@grpc.name
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Publishes one or more messages to the publisher.
|
95
|
+
#
|
96
|
+
# The message payload must not be empty; it must contain either a
|
97
|
+
# non-empty data field, or at least one attribute.
|
98
|
+
#
|
99
|
+
# @param [String, File] data The message payload. This will be converted
|
100
|
+
# to bytes encoded as ASCII-8BIT.
|
101
|
+
# @param [Hash] attributes Optional attributes for the message.
|
102
|
+
# @param [String] ordering_key Identifies related messages for which
|
103
|
+
# publish order should be respected.
|
104
|
+
# @yield [batch] a block for publishing multiple messages in one
|
105
|
+
# request
|
106
|
+
# @yieldparam [BatchPublisher] batch the topic batch publisher
|
107
|
+
# object
|
108
|
+
#
|
109
|
+
# @return [Message, Array<Message>] Returns the published message when
|
110
|
+
# called without a block, or an array of messages when called with a
|
111
|
+
# block.
|
112
|
+
#
|
113
|
+
# @example
|
114
|
+
# require "google/cloud/pubsub"
|
115
|
+
#
|
116
|
+
# pubsub = Google::Cloud::PubSub.new
|
117
|
+
#
|
118
|
+
# publisher = pubsub.publisher "my-topic"
|
119
|
+
# msg = publisher.publish "task completed"
|
120
|
+
#
|
121
|
+
# @example A message can be published using a File object:
|
122
|
+
# require "google/cloud/pubsub"
|
123
|
+
#
|
124
|
+
# pubsub = Google::Cloud::PubSub.new
|
125
|
+
#
|
126
|
+
# publisher = pubsub.publisher "my-topic"
|
127
|
+
# file = File.open "message.txt", mode: "rb"
|
128
|
+
# msg = publisher.publish file
|
129
|
+
#
|
130
|
+
# @example Additionally, a message can be published with attributes:
|
131
|
+
# require "google/cloud/pubsub"
|
132
|
+
#
|
133
|
+
# pubsub = Google::Cloud::PubSub.new
|
134
|
+
#
|
135
|
+
# publisher = pubsub.publisher "my-topic"
|
136
|
+
# msg = publisher.publish "task completed",
|
137
|
+
# foo: :bar,
|
138
|
+
# this: :that
|
139
|
+
#
|
140
|
+
# @example Multiple messages can be sent at the same time using a block:
|
141
|
+
# require "google/cloud/pubsub"
|
142
|
+
#
|
143
|
+
# pubsub = Google::Cloud::PubSub.new
|
144
|
+
#
|
145
|
+
# publisher = pubsub.publisher "my-topic"
|
146
|
+
#
|
147
|
+
# msgs = publisher.publish do |p|
|
148
|
+
# p.publish "task 1 completed", foo: :bar
|
149
|
+
# p.publish "task 2 completed", foo: :baz
|
150
|
+
# p.publish "task 3 completed", foo: :bif
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# @example Ordered messages are supported using ordering_key:
|
154
|
+
# require "google/cloud/pubsub"
|
155
|
+
#
|
156
|
+
# pubsub = Google::Cloud::PubSub.new
|
157
|
+
#
|
158
|
+
# publisher = pubsub.publisher "my-ordered-topic"
|
159
|
+
#
|
160
|
+
# # Ensure that message ordering is enabled.
|
161
|
+
# publisher.enable_message_ordering!
|
162
|
+
#
|
163
|
+
# # Publish an ordered message with an ordering key.
|
164
|
+
# publisher.publish "task completed",
|
165
|
+
# ordering_key: "task-key"
|
166
|
+
#
|
167
|
+
def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, compression_bytes_threshold: nil,
|
168
|
+
**extra_attrs, &block
|
169
|
+
ensure_service!
|
170
|
+
batch = BatchPublisher.new data,
|
171
|
+
attributes,
|
172
|
+
ordering_key,
|
173
|
+
extra_attrs,
|
174
|
+
compress: compress,
|
175
|
+
compression_bytes_threshold: compression_bytes_threshold
|
176
|
+
|
177
|
+
block&.call batch
|
178
|
+
return nil if batch.messages.count.zero?
|
179
|
+
batch.publish_batch_messages name, service
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Publishes a message asynchronously to the topic using
|
184
|
+
# {#async_publisher}.
|
185
|
+
#
|
186
|
+
# The message payload must not be empty; it must contain either a
|
187
|
+
# non-empty data field, or at least one attribute.
|
188
|
+
#
|
189
|
+
# Google Cloud Pub/Sub ordering keys provide the ability to ensure
|
190
|
+
# related messages are sent to subscribers in the order in which they
|
191
|
+
# were published. Messages can be tagged with an ordering key, a string
|
192
|
+
# that identifies related messages for which publish order should be
|
193
|
+
# respected. The service guarantees that, for a given ordering key and
|
194
|
+
# publisher, messages are sent to subscribers in the order in which they
|
195
|
+
# were published. Ordering does not require sacrificing high throughput
|
196
|
+
# or scalability, as the service automatically distributes messages for
|
197
|
+
# different ordering keys across subscribers.
|
198
|
+
#
|
199
|
+
# To use ordering keys, specify `ordering_key`. Before specifying
|
200
|
+
# `ordering_key` on a message a call to `#enable_message_ordering!` must
|
201
|
+
# be made or an error will be raised.
|
202
|
+
#
|
203
|
+
# @note At the time of this release, ordering keys are not yet publicly
|
204
|
+
# enabled and requires special project enablements.
|
205
|
+
#
|
206
|
+
# Publisher flow control limits the number of outstanding messages that
|
207
|
+
# are allowed to wait to be published.
|
208
|
+
#
|
209
|
+
# @param [String, File] data The message payload. This will be converted
|
210
|
+
# to bytes encoded as ASCII-8BIT.
|
211
|
+
# @param [Hash] attributes Optional attributes for the message.
|
212
|
+
# @param [String] ordering_key Identifies related messages for which
|
213
|
+
# publish order should be respected.
|
214
|
+
# @yield [result] the callback for when the message has been published
|
215
|
+
# @yieldparam [PublishResult] result the result of the asynchronous
|
216
|
+
# publish
|
217
|
+
# @raise [Google::Cloud::PubSub::AsyncPublisherStopped] when the
|
218
|
+
# publisher is stopped. (See {AsyncPublisher#stop} and
|
219
|
+
# {AsyncPublisher#stopped?}.)
|
220
|
+
# @raise [Google::Cloud::PubSub::OrderedMessagesDisabled] when
|
221
|
+
# publishing a message with an `ordering_key` but ordered messages are
|
222
|
+
# not enabled. (See {#message_ordering?} and
|
223
|
+
# {#enable_message_ordering!}.)
|
224
|
+
# @raise [Google::Cloud::PubSub::OrderingKeyError] when publishing a
|
225
|
+
# message with an `ordering_key` that has already failed when
|
226
|
+
# publishing. Use {#resume_publish} to allow this `ordering_key` to be
|
227
|
+
# published again.
|
228
|
+
# @raise [Google::Cloud::PubSub::FlowControlLimitError] when publish flow
|
229
|
+
# control limits are exceeded, and the `async` parameter key
|
230
|
+
# `flow_control.limit_exceeded_behavior` is set to `:error` or `:block`.
|
231
|
+
# If `flow_control.limit_exceeded_behavior` is set to `:block`, this error
|
232
|
+
# will be raised only when a limit would be exceeded by a single message.
|
233
|
+
#
|
234
|
+
# @example
|
235
|
+
# require "google/cloud/pubsub"
|
236
|
+
#
|
237
|
+
# pubsub = Google::Cloud::PubSub.new
|
238
|
+
#
|
239
|
+
# publisher = pubsub.publisher "my-topic"
|
240
|
+
# publisher.publish_async "task completed" do |result|
|
241
|
+
# if result.succeeded?
|
242
|
+
# log_publish_success result.data
|
243
|
+
# else
|
244
|
+
# log_publish_failure result.data, result.error
|
245
|
+
# end
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
# # Shut down the publisher when ready to stop publishing messages.
|
249
|
+
# publisher.async_publisher.stop!
|
250
|
+
#
|
251
|
+
# @example A message can be published using a File object:
|
252
|
+
# require "google/cloud/pubsub"
|
253
|
+
#
|
254
|
+
# pubsub = Google::Cloud::PubSub.new
|
255
|
+
#
|
256
|
+
# publisher = pubsub.publisher "my-topic"
|
257
|
+
# file = File.open "message.txt", mode: "rb"
|
258
|
+
# publisher.publish_async file
|
259
|
+
#
|
260
|
+
# # Shut down the publisher when ready to stop publishing messages.
|
261
|
+
# publisher.async_publisher.stop!
|
262
|
+
#
|
263
|
+
# @example Additionally, a message can be published with attributes:
|
264
|
+
# require "google/cloud/pubsub"
|
265
|
+
#
|
266
|
+
# pubsub = Google::Cloud::PubSub.new
|
267
|
+
#
|
268
|
+
# publisher = pubsub.publisher "my-topic"
|
269
|
+
# publisher.publish_async "task completed",
|
270
|
+
# foo: :bar, this: :that
|
271
|
+
#
|
272
|
+
# # Shut down the publisher when ready to stop publishing messages.
|
273
|
+
# publisher.async_publisher.stop!
|
274
|
+
#
|
275
|
+
# @example Ordered messages are supported using ordering_key:
|
276
|
+
# require "google/cloud/pubsub"
|
277
|
+
#
|
278
|
+
# pubsub = Google::Cloud::PubSub.new
|
279
|
+
#
|
280
|
+
# publisher = pubsub.publisher "my-ordered-topic"
|
281
|
+
#
|
282
|
+
# # Ensure that message ordering is enabled.
|
283
|
+
# publisher.enable_message_ordering!
|
284
|
+
#
|
285
|
+
# # Publish an ordered message with an ordering key.
|
286
|
+
# publisher.publish_async "task completed",
|
287
|
+
# ordering_key: "task-key"
|
288
|
+
#
|
289
|
+
# # Shut down the publisher when ready to stop publishing messages.
|
290
|
+
# publisher.async_publisher.stop!
|
291
|
+
#
|
292
|
+
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
|
293
|
+
ensure_service!
|
294
|
+
|
295
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
296
|
+
@async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
|
297
|
+
end
|
298
|
+
|
299
|
+
##
|
300
|
+
# Enables message ordering for messages with ordering keys on the
|
301
|
+
# {#async_publisher}. When enabled, messages published with the same
|
302
|
+
# `ordering_key` will be delivered in the order they were published.
|
303
|
+
#
|
304
|
+
# @note At the time of this release, ordering keys are not yet publicly
|
305
|
+
# enabled and requires special project enablements.
|
306
|
+
#
|
307
|
+
# See {#message_ordering?}. See {#publish_async},
|
308
|
+
# {Subscriber#listen}, and {Message#ordering_key}.
|
309
|
+
#
|
310
|
+
def enable_message_ordering!
|
311
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
312
|
+
@async_publisher.enable_message_ordering!
|
313
|
+
end
|
314
|
+
|
315
|
+
##
|
316
|
+
# Whether message ordering for messages with ordering keys has been
|
317
|
+
# enabled on the {#async_publisher}. When enabled, messages published
|
318
|
+
# with the same `ordering_key` will be delivered in the order they were
|
319
|
+
# published. When disabled, messages may be delivered in any order.
|
320
|
+
#
|
321
|
+
# See {#enable_message_ordering!}. See {#publish_async},
|
322
|
+
# {Subscriber#listen}, and {Message#ordering_key}.
|
323
|
+
#
|
324
|
+
# @return [Boolean]
|
325
|
+
#
|
326
|
+
def message_ordering?
|
327
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
328
|
+
@async_publisher.message_ordering?
|
329
|
+
end
|
330
|
+
|
331
|
+
##
|
332
|
+
# Resume publishing ordered messages for the provided ordering key.
|
333
|
+
#
|
334
|
+
# @param [String] ordering_key Identifies related messages for which
|
335
|
+
# publish order should be respected.
|
336
|
+
#
|
337
|
+
# @return [boolean] `true` when resumed, `false` otherwise.
|
338
|
+
#
|
339
|
+
def resume_publish ordering_key
|
340
|
+
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
|
341
|
+
@async_publisher.resume_publish ordering_key
|
342
|
+
end
|
343
|
+
|
344
|
+
##
|
345
|
+
# @private New Publisher from a Google::Cloud::PubSub::V1::Topic object.
|
346
|
+
def self.from_grpc grpc, service, async: nil
|
347
|
+
new.tap do |t|
|
348
|
+
t.grpc = grpc
|
349
|
+
t.service = service
|
350
|
+
t.instance_variable_set :@async_opts, async if async
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
protected
|
355
|
+
|
356
|
+
##
|
357
|
+
# @private Raise an error unless an active connection to the service is
|
358
|
+
# available.
|
359
|
+
def ensure_service!
|
360
|
+
raise "Must have active connection to service" unless service
|
361
|
+
end
|
362
|
+
|
363
|
+
##
|
364
|
+
# Ensures a Google::Cloud::PubSub::V1::Topic object exists.
|
365
|
+
def ensure_grpc!
|
366
|
+
ensure_service!
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
372
|
+
end
|
373
|
+
end
|
@@ -29,21 +29,21 @@ module Google
|
|
29
29
|
#
|
30
30
|
# pubsub = Google::Cloud::PubSub.new
|
31
31
|
#
|
32
|
-
#
|
33
|
-
#
|
32
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
33
|
+
# listener = subscriber.listen do |received_message|
|
34
34
|
# puts received_message.message.data
|
35
35
|
# received_message.acknowledge!
|
36
36
|
# end
|
37
37
|
#
|
38
38
|
# # Start background threads that will call the block passed to listen.
|
39
|
-
#
|
39
|
+
# listener.start
|
40
40
|
#
|
41
41
|
# # Shut down the subscriber when ready to stop receiving messages.
|
42
|
-
#
|
42
|
+
# listener.stop!
|
43
43
|
#
|
44
44
|
class ReceivedMessage
|
45
45
|
##
|
46
|
-
# @private The {Subscription} object.
|
46
|
+
# @private The {Google::Cloud::PubSub::V1::Subscription} object.
|
47
47
|
attr_accessor :subscription
|
48
48
|
|
49
49
|
##
|
@@ -51,7 +51,7 @@ module Google
|
|
51
51
|
attr_accessor :grpc
|
52
52
|
|
53
53
|
##
|
54
|
-
# @private Create an empty {Subscription} object.
|
54
|
+
# @private Create an empty {Google::Cloud::PubSub::V1::Subscription} object.
|
55
55
|
def initialize
|
56
56
|
@subscription = nil
|
57
57
|
@grpc = Google::Cloud::PubSub::V1::ReceivedMessage.new
|
@@ -65,8 +65,7 @@ module Google
|
|
65
65
|
|
66
66
|
##
|
67
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`.
|
69
|
-
# {Subscription#dead_letter_max_delivery_attempts=}.
|
68
|
+
# this will be `nil`.
|
70
69
|
#
|
71
70
|
# The delivery attempt counter is `1 + (the sum of number of NACKs and number of ack_deadline exceeds)` for the
|
72
71
|
# message.
|
@@ -86,13 +85,19 @@ module Google
|
|
86
85
|
#
|
87
86
|
# pubsub = Google::Cloud::PubSub.new
|
88
87
|
#
|
89
|
-
#
|
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
|
88
|
+
# subscription_admin = pubsub.subscription_admin
|
94
89
|
#
|
95
|
-
#
|
90
|
+
# subscription = subscription_admin.create_subscription \
|
91
|
+
# name: pubsub.subscription_path("my-topic-sub"),
|
92
|
+
# topic: pubsub.topic_path("my-topic"),
|
93
|
+
# dead_letter_policy: {
|
94
|
+
# dead_letter_topic: pubsub.topic_path("my-dead-letter-topic"),
|
95
|
+
# max_delivery_attempts: 10
|
96
|
+
# }
|
97
|
+
#
|
98
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
99
|
+
#
|
100
|
+
# listener = subscriber.listen do |received_message|
|
96
101
|
# puts received_message.message.delivery_attempt
|
97
102
|
# end
|
98
103
|
#
|
@@ -143,7 +148,7 @@ module Google
|
|
143
148
|
# or scalability, as the service automatically distributes messages for
|
144
149
|
# different ordering keys across subscribers.
|
145
150
|
#
|
146
|
-
# See {
|
151
|
+
# See {Publisher#publish_async} and {Subscriber#listen}.
|
147
152
|
#
|
148
153
|
# @return [String]
|
149
154
|
#
|
@@ -169,8 +174,8 @@ module Google
|
|
169
174
|
#
|
170
175
|
# pubsub = Google::Cloud::PubSub.new
|
171
176
|
#
|
172
|
-
#
|
173
|
-
#
|
177
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
178
|
+
# listener = subscriber.listen do |received_message|
|
174
179
|
# puts received_message.message.data
|
175
180
|
#
|
176
181
|
# received_message.acknowledge! do |result|
|
@@ -179,33 +184,33 @@ module Google
|
|
179
184
|
# end
|
180
185
|
#
|
181
186
|
# # Start background threads that will call block passed to listen.
|
182
|
-
#
|
187
|
+
# listener.start
|
183
188
|
#
|
184
189
|
# # Shut down the subscriber when ready to stop receiving messages.
|
185
|
-
#
|
190
|
+
# listener.stop!
|
186
191
|
#
|
187
192
|
# @example
|
188
193
|
# require "google/cloud/pubsub"
|
189
194
|
#
|
190
195
|
# pubsub = Google::Cloud::PubSub.new
|
191
196
|
#
|
192
|
-
#
|
193
|
-
#
|
197
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
198
|
+
# listener = subscriber.listen do |received_message|
|
194
199
|
# puts received_message.message.data
|
195
200
|
#
|
196
201
|
# received_message.acknowledge!
|
197
202
|
# end
|
198
203
|
#
|
199
204
|
# # Start background threads that will call block passed to listen.
|
200
|
-
#
|
205
|
+
# listener.start
|
201
206
|
#
|
202
207
|
# # Shut down the subscriber when ready to stop receiving messages.
|
203
|
-
#
|
208
|
+
# listener.stop!
|
204
209
|
#
|
205
|
-
def acknowledge!
|
210
|
+
def acknowledge!(&)
|
206
211
|
ensure_subscription!
|
207
212
|
if subscription.respond_to?(:exactly_once_delivery_enabled) && subscription.exactly_once_delivery_enabled
|
208
|
-
subscription.acknowledge ack_id, &
|
213
|
+
subscription.acknowledge ack_id, &
|
209
214
|
else
|
210
215
|
subscription.acknowledge ack_id
|
211
216
|
yield AcknowledgeResult.new(AcknowledgeResult::SUCCESS) if block_given?
|
@@ -233,8 +238,8 @@ module Google
|
|
233
238
|
#
|
234
239
|
# pubsub = Google::Cloud::PubSub.new
|
235
240
|
#
|
236
|
-
#
|
237
|
-
#
|
241
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
242
|
+
# listener = subscriber.listen do |received_message|
|
238
243
|
# puts received_message.message.data
|
239
244
|
#
|
240
245
|
# # Delay for 2 minutes
|
@@ -244,18 +249,18 @@ module Google
|
|
244
249
|
# end
|
245
250
|
#
|
246
251
|
# # Start background threads that will call block passed to listen.
|
247
|
-
#
|
252
|
+
# listener.start
|
248
253
|
#
|
249
254
|
# # Shut down the subscriber when ready to stop receiving messages.
|
250
|
-
#
|
255
|
+
# listener.stop!
|
251
256
|
#
|
252
257
|
# @example
|
253
258
|
# require "google/cloud/pubsub"
|
254
259
|
#
|
255
260
|
# pubsub = Google::Cloud::PubSub.new
|
256
261
|
#
|
257
|
-
#
|
258
|
-
#
|
262
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
263
|
+
# listener = subscriber.listen do |received_message|
|
259
264
|
# puts received_message.message.data
|
260
265
|
#
|
261
266
|
# # Delay for 2 minutes
|
@@ -263,15 +268,15 @@ module Google
|
|
263
268
|
# end
|
264
269
|
#
|
265
270
|
# # Start background threads that will call block passed to listen.
|
266
|
-
#
|
271
|
+
# listener.start
|
267
272
|
#
|
268
273
|
# # Shut down the subscriber when ready to stop receiving messages.
|
269
|
-
#
|
274
|
+
# listener.stop!
|
270
275
|
#
|
271
|
-
def modify_ack_deadline!
|
276
|
+
def modify_ack_deadline!(new_deadline, &)
|
272
277
|
ensure_subscription!
|
273
278
|
if subscription.respond_to?(:exactly_once_delivery_enabled) && subscription.exactly_once_delivery_enabled
|
274
|
-
subscription.modify_ack_deadline new_deadline, ack_id, &
|
279
|
+
subscription.modify_ack_deadline new_deadline, ack_id, &
|
275
280
|
else
|
276
281
|
subscription.modify_ack_deadline new_deadline, ack_id
|
277
282
|
yield AcknowledgeResult.new(AcknowledgeResult::SUCCESS) if block_given?
|
@@ -292,8 +297,8 @@ module Google
|
|
292
297
|
#
|
293
298
|
# pubsub = Google::Cloud::PubSub.new
|
294
299
|
#
|
295
|
-
#
|
296
|
-
#
|
300
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
301
|
+
# listener = subscriber.listen do |received_message|
|
297
302
|
# puts received_message.message.data
|
298
303
|
#
|
299
304
|
# # Release message back to the API.
|
@@ -303,18 +308,18 @@ module Google
|
|
303
308
|
# end
|
304
309
|
#
|
305
310
|
# # Start background threads that will call block passed to listen.
|
306
|
-
#
|
311
|
+
# listener.start
|
307
312
|
#
|
308
313
|
# # Shut down the subscriber when ready to stop receiving messages.
|
309
|
-
#
|
314
|
+
# listener.stop!
|
310
315
|
#
|
311
316
|
# @example
|
312
317
|
# require "google/cloud/pubsub"
|
313
318
|
#
|
314
319
|
# pubsub = Google::Cloud::PubSub.new
|
315
320
|
#
|
316
|
-
#
|
317
|
-
#
|
321
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
322
|
+
# listener = subscriber.listen do |received_message|
|
318
323
|
# puts received_message.message.data
|
319
324
|
#
|
320
325
|
# # Release message back to the API.
|
@@ -322,13 +327,13 @@ module Google
|
|
322
327
|
# end
|
323
328
|
#
|
324
329
|
# # Start background threads that will call block passed to listen.
|
325
|
-
#
|
330
|
+
# listener.start
|
326
331
|
#
|
327
332
|
# # Shut down the subscriber when ready to stop receiving messages.
|
328
|
-
#
|
333
|
+
# listener.stop!
|
329
334
|
#
|
330
|
-
def reject!
|
331
|
-
modify_ack_deadline! 0, &
|
335
|
+
def reject!(&)
|
336
|
+
modify_ack_deadline! 0, &
|
332
337
|
end
|
333
338
|
alias nack! reject!
|
334
339
|
alias ignore! reject!
|