google-cloud-pubsub 2.22.0 → 3.2.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +12 -1
  3. data/CHANGELOG.md +69 -0
  4. data/OVERVIEW.md +189 -145
  5. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  6. data/lib/google/cloud/pubsub/async_publisher.rb +20 -19
  7. data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
  8. data/lib/google/cloud/pubsub/errors.rb +3 -3
  9. data/lib/google/cloud/pubsub/internal_logger.rb +76 -0
  10. data/lib/google/cloud/pubsub/message.rb +8 -8
  11. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  12. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +13 -10
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  14. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +61 -18
  15. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +29 -9
  16. data/lib/google/cloud/pubsub/message_listener.rb +414 -0
  17. data/lib/google/cloud/pubsub/project.rb +102 -530
  18. data/lib/google/cloud/pubsub/publisher.rb +424 -0
  19. data/lib/google/cloud/pubsub/received_message.rb +50 -45
  20. data/lib/google/cloud/pubsub/service.rb +34 -385
  21. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  22. data/lib/google/cloud/pubsub/version.rb +1 -1
  23. data/lib/google/cloud/pubsub.rb +37 -19
  24. data/lib/google-cloud-pubsub.rb +27 -8
  25. metadata +19 -26
  26. data/lib/google/cloud/pubsub/policy.rb +0 -188
  27. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  28. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  29. data/lib/google/cloud/pubsub/schema.rb +0 -378
  30. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  31. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  32. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  33. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  34. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  35. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  36. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -0,0 +1,424 @@
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
+ return @resource_name if reference?
91
+ @grpc.name
92
+ end
93
+
94
+ ##
95
+ # Determines whether the publisher object was created with a resource
96
+ # representation from the Pub/Sub service.
97
+ #
98
+ # @return [Boolean] `true` when the publisher was created with a resource
99
+ # representation, `false` otherwise.
100
+ #
101
+ def reference?
102
+ @grpc.nil?
103
+ end
104
+
105
+ ##
106
+ # Determines whether the publisher object was created with a resource
107
+ # representation from the Pub/Sub service.
108
+ #
109
+ # @return [Boolean] `true` when the publisher was created with a resource
110
+ # representation, `false` otherwise.
111
+ #
112
+ def resource?
113
+ !@grpc.nil?
114
+ end
115
+
116
+
117
+ ##
118
+ # Reloads the publisher with current data from the Pub/Sub service.
119
+ #
120
+ # @return [Google::Cloud::PubSub::Publisher] Returns the reloaded
121
+ # publisher
122
+ #
123
+ # @example
124
+ # require "google/cloud/pubsub"
125
+ #
126
+ # pubsub = Google::Cloud::PubSub.new
127
+ #
128
+ # publisher = pubsub.publisher "my-topic", skip_lookup: true
129
+ #
130
+ # publisher.reload!
131
+ #
132
+ def reload!
133
+ ensure_service!
134
+ topic_path = service.topic_path name
135
+ @grpc = service.topic_admin.get_topic topic: topic_path
136
+ @resource_name = nil
137
+ self
138
+ end
139
+
140
+ ##
141
+ # Publishes one or more messages to the publisher.
142
+ #
143
+ # The message payload must not be empty; it must contain either a
144
+ # non-empty data field, or at least one attribute.
145
+ #
146
+ # @param [String, File] data The message payload. This will be converted
147
+ # to bytes encoded as ASCII-8BIT.
148
+ # @param [Hash] attributes Optional attributes for the message.
149
+ # @param [String] ordering_key Identifies related messages for which
150
+ # publish order should be respected.
151
+ # @yield [batch] a block for publishing multiple messages in one
152
+ # request
153
+ # @yieldparam [BatchPublisher] batch the topic batch publisher
154
+ # object
155
+ #
156
+ # @return [Message, Array<Message>] Returns the published message when
157
+ # called without a block, or an array of messages when called with a
158
+ # block.
159
+ #
160
+ # @example
161
+ # require "google/cloud/pubsub"
162
+ #
163
+ # pubsub = Google::Cloud::PubSub.new
164
+ #
165
+ # publisher = pubsub.publisher "my-topic"
166
+ # msg = publisher.publish "task completed"
167
+ #
168
+ # @example A message can be published using a File object:
169
+ # require "google/cloud/pubsub"
170
+ #
171
+ # pubsub = Google::Cloud::PubSub.new
172
+ #
173
+ # publisher = pubsub.publisher "my-topic"
174
+ # file = File.open "message.txt", mode: "rb"
175
+ # msg = publisher.publish file
176
+ #
177
+ # @example Additionally, a message can be published with attributes:
178
+ # require "google/cloud/pubsub"
179
+ #
180
+ # pubsub = Google::Cloud::PubSub.new
181
+ #
182
+ # publisher = pubsub.publisher "my-topic"
183
+ # msg = publisher.publish "task completed",
184
+ # foo: :bar,
185
+ # this: :that
186
+ #
187
+ # @example Multiple messages can be sent at the same time using a block:
188
+ # require "google/cloud/pubsub"
189
+ #
190
+ # pubsub = Google::Cloud::PubSub.new
191
+ #
192
+ # publisher = pubsub.publisher "my-topic"
193
+ #
194
+ # msgs = publisher.publish do |p|
195
+ # p.publish "task 1 completed", foo: :bar
196
+ # p.publish "task 2 completed", foo: :baz
197
+ # p.publish "task 3 completed", foo: :bif
198
+ # end
199
+ #
200
+ # @example Ordered messages are supported using ordering_key:
201
+ # require "google/cloud/pubsub"
202
+ #
203
+ # pubsub = Google::Cloud::PubSub.new
204
+ #
205
+ # publisher = pubsub.publisher "my-ordered-topic"
206
+ #
207
+ # # Ensure that message ordering is enabled.
208
+ # publisher.enable_message_ordering!
209
+ #
210
+ # # Publish an ordered message with an ordering key.
211
+ # publisher.publish "task completed",
212
+ # ordering_key: "task-key"
213
+ #
214
+ def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, compression_bytes_threshold: nil,
215
+ **extra_attrs, &block
216
+ ensure_service!
217
+ batch = BatchPublisher.new data,
218
+ attributes,
219
+ ordering_key,
220
+ extra_attrs,
221
+ compress: compress,
222
+ compression_bytes_threshold: compression_bytes_threshold
223
+
224
+ block&.call batch
225
+ return nil if batch.messages.count.zero?
226
+ reason = block_given? ? "synchronous publish multiple" : "synchronous publish single"
227
+ batch.publish_batch_messages name, service, reason: reason
228
+ end
229
+
230
+ ##
231
+ # Publishes a message asynchronously to the topic using
232
+ # {#async_publisher}.
233
+ #
234
+ # The message payload must not be empty; it must contain either a
235
+ # non-empty data field, or at least one attribute.
236
+ #
237
+ # Google Cloud Pub/Sub ordering keys provide the ability to ensure
238
+ # related messages are sent to subscribers in the order in which they
239
+ # were published. Messages can be tagged with an ordering key, a string
240
+ # that identifies related messages for which publish order should be
241
+ # respected. The service guarantees that, for a given ordering key and
242
+ # publisher, messages are sent to subscribers in the order in which they
243
+ # were published. Ordering does not require sacrificing high throughput
244
+ # or scalability, as the service automatically distributes messages for
245
+ # different ordering keys across subscribers.
246
+ #
247
+ # To use ordering keys, specify `ordering_key`. Before specifying
248
+ # `ordering_key` on a message a call to `#enable_message_ordering!` must
249
+ # be made or an error will be raised.
250
+ #
251
+ # @note At the time of this release, ordering keys are not yet publicly
252
+ # enabled and requires special project enablements.
253
+ #
254
+ # Publisher flow control limits the number of outstanding messages that
255
+ # are allowed to wait to be published.
256
+ #
257
+ # @param [String, File] data The message payload. This will be converted
258
+ # to bytes encoded as ASCII-8BIT.
259
+ # @param [Hash] attributes Optional attributes for the message.
260
+ # @param [String] ordering_key Identifies related messages for which
261
+ # publish order should be respected.
262
+ # @yield [result] the callback for when the message has been published
263
+ # @yieldparam [PublishResult] result the result of the asynchronous
264
+ # publish
265
+ # @raise [Google::Cloud::PubSub::AsyncPublisherStopped] when the
266
+ # publisher is stopped. (See {AsyncPublisher#stop} and
267
+ # {AsyncPublisher#stopped?}.)
268
+ # @raise [Google::Cloud::PubSub::OrderedMessagesDisabled] when
269
+ # publishing a message with an `ordering_key` but ordered messages are
270
+ # not enabled. (See {#message_ordering?} and
271
+ # {#enable_message_ordering!}.)
272
+ # @raise [Google::Cloud::PubSub::OrderingKeyError] when publishing a
273
+ # message with an `ordering_key` that has already failed when
274
+ # publishing. Use {#resume_publish} to allow this `ordering_key` to be
275
+ # published again.
276
+ # @raise [Google::Cloud::PubSub::FlowControlLimitError] when publish flow
277
+ # control limits are exceeded, and the `async` parameter key
278
+ # `flow_control.limit_exceeded_behavior` is set to `:error` or `:block`.
279
+ # If `flow_control.limit_exceeded_behavior` is set to `:block`, this error
280
+ # will be raised only when a limit would be exceeded by a single message.
281
+ #
282
+ # @example
283
+ # require "google/cloud/pubsub"
284
+ #
285
+ # pubsub = Google::Cloud::PubSub.new
286
+ #
287
+ # publisher = pubsub.publisher "my-topic"
288
+ # publisher.publish_async "task completed" do |result|
289
+ # if result.succeeded?
290
+ # log_publish_success result.data
291
+ # else
292
+ # log_publish_failure result.data, result.error
293
+ # end
294
+ # end
295
+ #
296
+ # # Shut down the publisher when ready to stop publishing messages.
297
+ # publisher.async_publisher.stop!
298
+ #
299
+ # @example A message can be published using a File object:
300
+ # require "google/cloud/pubsub"
301
+ #
302
+ # pubsub = Google::Cloud::PubSub.new
303
+ #
304
+ # publisher = pubsub.publisher "my-topic"
305
+ # file = File.open "message.txt", mode: "rb"
306
+ # publisher.publish_async file
307
+ #
308
+ # # Shut down the publisher when ready to stop publishing messages.
309
+ # publisher.async_publisher.stop!
310
+ #
311
+ # @example Additionally, a message can be published with attributes:
312
+ # require "google/cloud/pubsub"
313
+ #
314
+ # pubsub = Google::Cloud::PubSub.new
315
+ #
316
+ # publisher = pubsub.publisher "my-topic"
317
+ # publisher.publish_async "task completed",
318
+ # foo: :bar, this: :that
319
+ #
320
+ # # Shut down the publisher when ready to stop publishing messages.
321
+ # publisher.async_publisher.stop!
322
+ #
323
+ # @example Ordered messages are supported using ordering_key:
324
+ # require "google/cloud/pubsub"
325
+ #
326
+ # pubsub = Google::Cloud::PubSub.new
327
+ #
328
+ # publisher = pubsub.publisher "my-ordered-topic"
329
+ #
330
+ # # Ensure that message ordering is enabled.
331
+ # publisher.enable_message_ordering!
332
+ #
333
+ # # Publish an ordered message with an ordering key.
334
+ # publisher.publish_async "task completed",
335
+ # ordering_key: "task-key"
336
+ #
337
+ # # Shut down the publisher when ready to stop publishing messages.
338
+ # publisher.async_publisher.stop!
339
+ #
340
+ def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
341
+ ensure_service!
342
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
343
+ @async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
344
+ end
345
+
346
+ ##
347
+ # Enables message ordering for messages with ordering keys on the
348
+ # {#async_publisher}. When enabled, messages published with the same
349
+ # `ordering_key` will be delivered in the order they were published.
350
+ #
351
+ # @note At the time of this release, ordering keys are not yet publicly
352
+ # enabled and requires special project enablements.
353
+ #
354
+ # See {#message_ordering?}. See {#publish_async},
355
+ # {Subscriber#listen}, and {Message#ordering_key}.
356
+ #
357
+ def enable_message_ordering!
358
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
359
+ @async_publisher.enable_message_ordering!
360
+ end
361
+
362
+ ##
363
+ # Whether message ordering for messages with ordering keys has been
364
+ # enabled on the {#async_publisher}. When enabled, messages published
365
+ # with the same `ordering_key` will be delivered in the order they were
366
+ # published. When disabled, messages may be delivered in any order.
367
+ #
368
+ # See {#enable_message_ordering!}. See {#publish_async},
369
+ # {Subscriber#listen}, and {Message#ordering_key}.
370
+ #
371
+ # @return [Boolean]
372
+ #
373
+ def message_ordering?
374
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
375
+ @async_publisher.message_ordering?
376
+ end
377
+
378
+ ##
379
+ # Resume publishing ordered messages for the provided ordering key.
380
+ #
381
+ # @param [String] ordering_key Identifies related messages for which
382
+ # publish order should be respected.
383
+ #
384
+ # @return [boolean] `true` when resumed, `false` otherwise.
385
+ #
386
+ def resume_publish ordering_key
387
+ @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
388
+ @async_publisher.resume_publish ordering_key
389
+ end
390
+
391
+ ##
392
+ # @private New Publisher from a Google::Cloud::PubSub::V1::Topic object.
393
+ def self.from_grpc grpc, service, async: nil
394
+ new.tap do |t|
395
+ t.grpc = grpc
396
+ t.service = service
397
+ t.instance_variable_set :@async_opts, async if async
398
+ end
399
+ end
400
+
401
+ ##
402
+ # @private New reference {Publisher} from a topic name without making
403
+ # a HTTP request.
404
+ def self.from_name name, service, options = {}
405
+ name = service.topic_path name, options
406
+ from_grpc(nil, service, async: options[:async]).tap do |t|
407
+ t.instance_variable_set :@resource_name, name
408
+ end
409
+ end
410
+
411
+ protected
412
+
413
+ ##
414
+ # @private Raise an error unless an active connection to the service is
415
+ # available.
416
+ def ensure_service!
417
+ raise "Must have active connection to service" unless service
418
+ end
419
+ end
420
+ end
421
+
422
+ Pubsub = PubSub unless const_defined? :Pubsub
423
+ end
424
+ end
@@ -29,21 +29,21 @@ module Google
29
29
  #
30
30
  # pubsub = Google::Cloud::PubSub.new
31
31
  #
32
- # sub = pubsub.subscription "my-topic-sub"
33
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
39
+ # listener.start
40
40
  #
41
41
  # # Shut down the subscriber when ready to stop receiving messages.
42
- # subscriber.stop!
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`. See {Topic#subscribe}, {Subscription#dead_letter_topic=} and
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
- # 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
88
+ # subscription_admin = pubsub.subscription_admin
94
89
  #
95
- # subscriber = sub.listen do |received_message|
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 {Topic#publish_async} and {Subscription#listen}.
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
- # sub = pubsub.subscription "my-topic-sub"
173
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
187
+ # listener.start
183
188
  #
184
189
  # # Shut down the subscriber when ready to stop receiving messages.
185
- # subscriber.stop!
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
- # sub = pubsub.subscription "my-topic-sub"
193
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
205
+ # listener.start
201
206
  #
202
207
  # # Shut down the subscriber when ready to stop receiving messages.
203
- # subscriber.stop!
208
+ # listener.stop!
204
209
  #
205
- def acknowledge! &block
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, &block
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
- # sub = pubsub.subscription "my-topic-sub"
237
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
252
+ # listener.start
248
253
  #
249
254
  # # Shut down the subscriber when ready to stop receiving messages.
250
- # subscriber.stop!
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
- # sub = pubsub.subscription "my-topic-sub"
258
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
271
+ # listener.start
267
272
  #
268
273
  # # Shut down the subscriber when ready to stop receiving messages.
269
- # subscriber.stop!
274
+ # listener.stop!
270
275
  #
271
- def modify_ack_deadline! new_deadline, &block
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, &block
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
- # sub = pubsub.subscription "my-topic-sub"
296
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
311
+ # listener.start
307
312
  #
308
313
  # # Shut down the subscriber when ready to stop receiving messages.
309
- # subscriber.stop!
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
- # sub = pubsub.subscription "my-topic-sub"
317
- # subscriber = sub.listen do |received_message|
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
- # subscriber.start
330
+ # listener.start
326
331
  #
327
332
  # # Shut down the subscriber when ready to stop receiving messages.
328
- # subscriber.stop!
333
+ # listener.stop!
329
334
  #
330
- def reject! &block
331
- modify_ack_deadline! 0, &block
335
+ def reject!(&)
336
+ modify_ack_deadline! 0, &
332
337
  end
333
338
  alias nack! reject!
334
339
  alias ignore! reject!