google-cloud-pubsub 0.27.1 → 0.27.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d86a72ae11e23498af47c4a4137eb6ecd9382df9
4
- data.tar.gz: e34a6d21a79b06b387193d17d087405e8c995cf2
3
+ metadata.gz: f83c458e0a45afd77106e7e66922ad2b1e1d8515
4
+ data.tar.gz: 6aeda54db32d7f78e6c8b649cad9beac294408d4
5
5
  SHA512:
6
- metadata.gz: c88a3987a5bac8329cbf89dde504a3c7f74a52f5ad2d0e0557bf9bff83e57dc869965f90b03829f66de54031b5693a52a9c6ceb0a8a24fb2f7d85d9ed9767c75
7
- data.tar.gz: e03c8e11e8a5f30c738e3fd3a1ca97d99407a6ea6fcba7c1dba206763164ec2f11c83f5e48cfd79de7af0ebdacccd6f25ef8dff55609d0099a7f06d4d6cd1bd8
6
+ metadata.gz: 609784712397870174e5fd07a41978f74616ee7bab81db6ad007efda11b8bb2d1d13f8dce68e0681f1ff4e64be8d2b5c5035e8ae8a10e0a669776eda474430d1
7
+ data.tar.gz: af8a25738680f2d7fb74e236ecb6ce7db9a7b5de56774fc34d33f917464c251c13caec9f4cc4d96750a1db786a8a424fd92064dd5b379278820f2d73222f432f
data/README.md CHANGED
@@ -37,8 +37,17 @@ msg = topic.publish "new-message"
37
37
  # Retrieve a subscription
38
38
  sub = pubsub.subscription "my-topic-sub"
39
39
 
40
- # Pull available messages
41
- msgs = sub.pull
40
+ # Create a subscriber to listen for available messages
41
+ subscriber = sub.listen do |received_message|
42
+ # process message
43
+ received_message.acknowledge!
44
+ end
45
+
46
+ # Start background threads that will call the block passed to listen.
47
+ subscriber.start
48
+
49
+ # Shut down the subscriber when ready to stop receiving messages.
50
+ subscriber.stop.wait!
42
51
  ```
43
52
 
44
53
  ## Supported Ruby Versions
@@ -185,10 +185,12 @@ module Google
185
185
  # end
186
186
  # ```
187
187
  #
188
- # ## Pulling Messages
188
+ # ## Receiving messages
189
189
  #
190
- # Messages are pulled from a Subscription. (See
191
- # {Google::Cloud::Pubsub::Subscription#pull})
190
+ # Messages can be streamed from a subscription with a subscriber object
191
+ # that is created using `listen`. (See
192
+ # {Google::Cloud::Pubsub::Subscription#listen} and
193
+ # {Google::Cloud::Pubsub::Subscriber})
192
194
  #
193
195
  # ```ruby
194
196
  # require "google/cloud/pubsub"
@@ -196,22 +198,21 @@ module Google
196
198
  # pubsub = Google::Cloud::Pubsub.new
197
199
  #
198
200
  # sub = pubsub.subscription "my-topic-sub"
199
- # msgs = sub.pull
200
- # ```
201
- #
202
- # A maximum number of messages returned can also be specified:
203
201
  #
204
- # ```ruby
205
- # require "google/cloud/pubsub"
202
+ # subscriber = sub.listen do |received_message|
203
+ # # process message
204
+ # received_message.acknowledge!
205
+ # end
206
206
  #
207
- # pubsub = Google::Cloud::Pubsub.new
207
+ # # Start background threads that will call the block passed to listen.
208
+ # subscriber.start
208
209
  #
209
- # sub = pubsub.subscription "my-topic-sub", max: 10
210
- # msgs = sub.pull
210
+ # # Shut down the subscriber when ready to stop receiving messages.
211
+ # subscriber.stop.wait!
211
212
  # ```
212
213
  #
213
- # The request for messages can also block until messages are available.
214
- # (See {Google::Cloud::Pubsub::Subscription#wait_for_messages})
214
+ # Messages also can be pulled directly in a one-time operation. (See
215
+ # {Google::Cloud::Pubsub::Subscription#pull})
215
216
  #
216
217
  # ```ruby
217
218
  # require "google/cloud/pubsub"
@@ -219,13 +220,10 @@ module Google
219
220
  # pubsub = Google::Cloud::Pubsub.new
220
221
  #
221
222
  # sub = pubsub.subscription "my-topic-sub"
222
- # msgs = sub.wait_for_messages
223
+ # received_messages = sub.pull
223
224
  # ```
224
225
  #
225
- # Messages can also be streamed from a subscription with a subscriber object
226
- # that can be created using `listen`. (See
227
- # {Google::Cloud::Pubsub::Subscription#listen} and
228
- # {Google::Cloud::Pubsub::Subscriber})
226
+ # A maximum number of messages to pull can be specified:
229
227
  #
230
228
  # ```ruby
231
229
  # require "google/cloud/pubsub"
@@ -233,16 +231,7 @@ module Google
233
231
  # pubsub = Google::Cloud::Pubsub.new
234
232
  #
235
233
  # sub = pubsub.subscription "my-topic-sub"
236
- #
237
- # subscriber = sub.listen do |msg|
238
- # # process msg
239
- # msg.ack!
240
- # end
241
- #
242
- # subscriber.start
243
- #
244
- # # Shut down the subscriber when ready to stop receiving messages.
245
- # subscriber.stop.wait!
234
+ # received_messages = sub.pull max: 10
246
235
  # ```
247
236
  #
248
237
  # ## Acknowledging a Message
@@ -260,7 +249,17 @@ module Google
260
249
  # pubsub = Google::Cloud::Pubsub.new
261
250
  #
262
251
  # sub = pubsub.subscription "my-topic-sub"
263
- # sub.pull.each { |msg| msg.acknowledge! }
252
+ #
253
+ # subscriber = sub.listen do |received_message|
254
+ # # process message
255
+ # received_message.acknowledge!
256
+ # end
257
+ #
258
+ # # Start background threads that will call the block passed to listen.
259
+ # subscriber.start
260
+ #
261
+ # # Shut down the subscriber when ready to stop receiving messages.
262
+ # subscriber.stop.wait!
264
263
  # ```
265
264
  #
266
265
  # Or, multiple messages can be acknowledged in a single API call:
@@ -290,12 +289,18 @@ module Google
290
289
  # pubsub = Google::Cloud::Pubsub.new
291
290
  #
292
291
  # sub = pubsub.subscription "my-topic-sub"
293
- # received_message = sub.pull.first
294
- # if received_message
292
+ # subscriber = sub.listen do |received_message|
295
293
  # puts received_message.message.data
294
+ #
296
295
  # # Delay for 2 minutes
297
296
  # received_message.delay! 120
298
297
  # end
298
+ #
299
+ # # Start background threads that will call the block passed to listen.
300
+ # subscriber.start
301
+ #
302
+ # # Shut down the subscriber when ready to stop receiving messages.
303
+ # subscriber.stop.wait!
299
304
  # ```
300
305
  #
301
306
  # The message can also be made available for immediate redelivery:
@@ -306,12 +311,18 @@ module Google
306
311
  # pubsub = Google::Cloud::Pubsub.new
307
312
  #
308
313
  # sub = pubsub.subscription "my-topic-sub"
309
- # received_message = sub.pull.first
310
- # if received_message
314
+ # subscriber = sub.listen do |received_message|
311
315
  # puts received_message.message.data
312
- # # Mark for redelivery by setting the deadline to now
313
- # received_message.delay! 0
316
+ #
317
+ # # Mark for redelivery
318
+ # received_message.reject!
314
319
  # end
320
+ #
321
+ # # Start background threads that will call the block passed to listen.
322
+ # subscriber.start
323
+ #
324
+ # # Shut down the subscriber when ready to stop receiving messages.
325
+ # subscriber.stop.wait!
315
326
  # ```
316
327
  #
317
328
  # Multiple messages can be delayed or made available for immediate
@@ -349,8 +360,8 @@ module Google
349
360
  #
350
361
  # snapshot = sub.create_snapshot
351
362
  #
352
- # messages = sub.pull
353
- # sub.acknowledge messages
363
+ # received_messages = sub.pull
364
+ # sub.acknowledge received_messages
354
365
  #
355
366
  # sub.seek snapshot
356
367
  # ```
@@ -369,11 +380,12 @@ module Google
369
380
  #
370
381
  # sub = pubsub.subscription "my-topic-sub"
371
382
  #
372
- # subscriber = sub.listen do |msg|
373
- # # process msg
374
- # msg.ack!
383
+ # subscriber = sub.listen do |received_message|
384
+ # # process message
385
+ # received_message.acknowledge!
375
386
  # end
376
387
  #
388
+ # # Start background threads that will call the block passed to listen.
377
389
  # subscriber.start
378
390
  #
379
391
  # # Shut down the subscriber when ready to stop receiving messages.
@@ -392,12 +404,13 @@ module Google
392
404
  #
393
405
  # sub = pubsub.subscription "my-topic-sub"
394
406
  #
395
- # subscriber = sub.listen threads: { callback: 16 } do |msg|
407
+ # subscriber = sub.listen threads: { callback: 16 } do |received_message|
396
408
  # # store the message somewhere before acknowledging
397
- # store_in_backend msg.data # takes a few seconds
398
- # msg.ack!
409
+ # store_in_backend received_message.data # takes a few seconds
410
+ # received_message.acknowledge!
399
411
  # end
400
412
  #
413
+ # # Start background threads that will call the block passed to listen.
401
414
  # subscriber.start
402
415
  # ```
403
416
  #
@@ -39,10 +39,18 @@ module Google
39
39
  # message = topic.publish "task completed"
40
40
  # message.data #=> "task completed"
41
41
  #
42
- # # Pull a message
42
+ # # Listen for messages
43
43
  # sub = pubsub.subscription "my-topic-sub"
44
- # received_message = sub.pull.first
45
- # received_message.message.data #=> "task completed"
44
+ # subscriber = sub.listen do |received_message|
45
+ # # process message
46
+ # received_message.acknowledge!
47
+ # end
48
+ #
49
+ # # Start background threads that will call the block passed to listen.
50
+ # subscriber.start
51
+ #
52
+ # # Shut down the subscriber when ready to stop receiving messages.
53
+ # subscriber.stop.wait!
46
54
  #
47
55
  class Message
48
56
  ##
@@ -30,12 +30,17 @@ module Google
30
30
  # pubsub = Google::Cloud::Pubsub.new
31
31
  #
32
32
  # sub = pubsub.subscription "my-topic-sub"
33
- # received_message = sub.pull.first
34
- # if received_message
33
+ # subscriber = sub.listen do |received_message|
35
34
  # puts received_message.message.data
36
35
  # received_message.acknowledge!
37
36
  # end
38
37
  #
38
+ # # Start background threads that will call the block passed to listen.
39
+ # subscriber.start
40
+ #
41
+ # # Shut down the subscriber when ready to stop receiving messages.
42
+ # subscriber.stop.wait!
43
+ #
39
44
  class ReceivedMessage
40
45
  ##
41
46
  # @private The {Subscription} object.
@@ -102,12 +107,18 @@ module Google
102
107
  # pubsub = Google::Cloud::Pubsub.new
103
108
  #
104
109
  # sub = pubsub.subscription "my-topic-sub"
105
- # received_message = sub.pull.first
106
- # if received_message
110
+ # subscriber = sub.listen do |received_message|
107
111
  # puts received_message.message.data
112
+ #
108
113
  # received_message.acknowledge!
109
114
  # end
110
115
  #
116
+ # # Start background threads that will call block passed to listen.
117
+ # subscriber.start
118
+ #
119
+ # # Shut down the subscriber when ready to stop receiving messages.
120
+ # subscriber.stop.wait!
121
+ #
111
122
  def acknowledge!
112
123
  ensure_subscription!
113
124
  subscription.acknowledge ack_id
@@ -132,13 +143,19 @@ module Google
132
143
  # pubsub = Google::Cloud::Pubsub.new
133
144
  #
134
145
  # sub = pubsub.subscription "my-topic-sub"
135
- # received_message = sub.pull.first
136
- # if received_message
146
+ # subscriber = sub.listen do |received_message|
137
147
  # puts received_message.message.data
148
+ #
138
149
  # # Delay for 2 minutes
139
150
  # received_message.delay! 120
140
151
  # end
141
152
  #
153
+ # # Start background threads that will call block passed to listen.
154
+ # subscriber.start
155
+ #
156
+ # # Shut down the subscriber when ready to stop receiving messages.
157
+ # subscriber.stop.wait!
158
+ #
142
159
  def delay! new_deadline
143
160
  ensure_subscription!
144
161
  subscription.delay new_deadline, ack_id
@@ -157,13 +174,19 @@ module Google
157
174
  # pubsub = Google::Cloud::Pubsub.new
158
175
  #
159
176
  # sub = pubsub.subscription "my-topic-sub"
160
- # received_message = sub.pull.first
161
- # if received_message
177
+ # subscriber = sub.listen do |received_message|
162
178
  # puts received_message.message.data
179
+ #
163
180
  # # Release message back to the API.
164
181
  # received_message.reject!
165
182
  # end
166
183
  #
184
+ # # Start background threads that will call block passed to listen.
185
+ # subscriber.start
186
+ #
187
+ # # Shut down the subscriber when ready to stop receiving messages.
188
+ # subscriber.stop.wait!
189
+ #
167
190
  def reject!
168
191
  delay! 0
169
192
  end
@@ -31,11 +31,12 @@ module Google
31
31
  #
32
32
  # sub = pubsub.subscription "my-topic-sub"
33
33
  #
34
- # subscriber = sub.listen do |msg|
35
- # # process msg
36
- # msg.ack!
34
+ # subscriber = sub.listen do |received_message|
35
+ # # process message
36
+ # received_message.acknowledge!
37
37
  # end
38
38
  #
39
+ # # Start background threads that will call the block passed to listen.
39
40
  # subscriber.start
40
41
  #
41
42
  # # Shut down the subscriber when ready to stop receiving messages.
@@ -35,8 +35,16 @@ module Google
35
35
  # pubsub = Google::Cloud::Pubsub.new
36
36
  #
37
37
  # sub = pubsub.subscription "my-topic-sub"
38
- # msgs = sub.pull
39
- # msgs.each { |msg| msg.acknowledge! }
38
+ # subscriber = sub.listen do |received_message|
39
+ # # process message
40
+ # received_message.acknowledge!
41
+ # end
42
+ #
43
+ # # Start background threads that will call the block passed to listen.
44
+ # subscriber.start
45
+ #
46
+ # # Shut down the subscriber when ready to stop receiving messages.
47
+ # subscriber.stop.wait!
40
48
  #
41
49
  class Subscription
42
50
  ##
@@ -231,11 +239,17 @@ module Google
231
239
  # `UNAVAILABLE` if there are too many concurrent pull requests pending
232
240
  # for the given subscription.
233
241
  #
242
+ # See also {#listen} for the preferred way to process messages as they
243
+ # become available.
244
+ #
234
245
  # @param [Boolean] immediate When `true` the system will respond
235
246
  # immediately even if it is not able to return messages. When `false`
236
247
  # the system is allowed to wait until it can return least one message.
237
248
  # No messages are returned when a request times out. The default value
238
249
  # is `true`.
250
+ #
251
+ # See also {#listen} for the preferred way to process messages as they
252
+ # become available.
239
253
  # @param [Integer] max The maximum number of messages to return for this
240
254
  # request. The Pub/Sub system may return fewer than the number
241
255
  # specified. The default value is `100`, the maximum value is `1000`.
@@ -248,7 +262,7 @@ module Google
248
262
  # pubsub = Google::Cloud::Pubsub.new
249
263
  #
250
264
  # sub = pubsub.subscription "my-topic-sub"
251
- # sub.pull.each { |msg| msg.acknowledge! }
265
+ # sub.pull.each { |received_message| received_message.acknowledge! }
252
266
  #
253
267
  # @example A maximum number of messages returned can also be specified:
254
268
  # require "google/cloud/pubsub"
@@ -256,7 +270,9 @@ module Google
256
270
  # pubsub = Google::Cloud::Pubsub.new
257
271
  #
258
272
  # sub = pubsub.subscription "my-topic-sub"
259
- # sub.pull(max: 10).each { |msg| msg.acknowledge! }
273
+ # sub.pull(max: 10).each do |received_message|
274
+ # received_message.acknowledge!
275
+ # end
260
276
  #
261
277
  # @example The call can block until messages are available:
262
278
  # require "google/cloud/pubsub"
@@ -264,8 +280,10 @@ module Google
264
280
  # pubsub = Google::Cloud::Pubsub.new
265
281
  #
266
282
  # sub = pubsub.subscription "my-topic-sub"
267
- # msgs = sub.pull immediate: false
268
- # msgs.each { |msg| msg.acknowledge! }
283
+ # received_messages = sub.pull immediate: false
284
+ # received_messages.each do |received_message|
285
+ # received_message.acknowledge!
286
+ # end
269
287
  #
270
288
  def pull immediate: true, max: 100
271
289
  ensure_service!
@@ -284,6 +302,9 @@ module Google
284
302
  #
285
303
  # subscription.pull immediate: false
286
304
  #
305
+ # See also {#listen} for the preferred way to process messages as they
306
+ # become available.
307
+ #
287
308
  # @param [Integer] max The maximum number of messages to return for this
288
309
  # request. The Pub/Sub system may return fewer than the number
289
310
  # specified. The default value is `100`, the maximum value is `1000`.
@@ -296,8 +317,10 @@ module Google
296
317
  # pubsub = Google::Cloud::Pubsub.new
297
318
  #
298
319
  # sub = pubsub.subscription "my-topic-sub"
299
- # msgs = sub.wait_for_messages
300
- # msgs.each { |msg| msg.acknowledge! }
320
+ # received_messages = sub.wait_for_messages
321
+ # received_messages.each do |received_message|
322
+ # received_message.acknowledge!
323
+ # end
301
324
  #
302
325
  def wait_for_messages max: 100
303
326
  pull immediate: false, max: max
@@ -327,8 +350,9 @@ module Google
327
350
  # ({ReceivedMessage#nack!}, {ReceivedMessage#delay!}). Default is
328
351
  # 4.
329
352
  #
330
- # @yield [msg] a block for processing new messages
331
- # @yieldparam [ReceivedMessage] msg the newly received message
353
+ # @yield [received_message] a block for processing new messages
354
+ # @yieldparam [ReceivedMessage] received_message the newly received
355
+ # message
332
356
  #
333
357
  # @return [Subscriber]
334
358
  #
@@ -339,11 +363,12 @@ module Google
339
363
  #
340
364
  # sub = pubsub.subscription "my-topic-sub"
341
365
  #
342
- # subscriber = sub.listen do |msg|
343
- # # process msg
344
- # msg.ack!
366
+ # subscriber = sub.listen do |received_message|
367
+ # # process message
368
+ # received_message.acknowledge!
345
369
  # end
346
370
  #
371
+ # # Start background threads that will call block passed to listen.
347
372
  # subscriber.start
348
373
  #
349
374
  # # Shut down the subscriber when ready to stop receiving messages.
@@ -356,12 +381,13 @@ module Google
356
381
  #
357
382
  # sub = pubsub.subscription "my-topic-sub"
358
383
  #
359
- # subscriber = sub.listen threads: { callback: 16 } do |msg|
384
+ # subscriber = sub.listen threads: { callback: 16 } do |rec_message|
360
385
  # # store the message somewhere before acknowledging
361
- # store_in_backend msg.data # takes a few seconds
362
- # msg.ack!
386
+ # store_in_backend rec_message.data # takes a few seconds
387
+ # rec_message.acknowledge!
363
388
  # end
364
389
  #
390
+ # # Start background threads that will call block passed to listen.
365
391
  # subscriber.start
366
392
  #
367
393
  def listen deadline: nil, streams: nil, inventory: nil, threads: {},
@@ -382,6 +408,8 @@ module Google
382
408
  # Acknowledging a message more than once will not result in an error.
383
409
  # This is only used for messages received via pull.
384
410
  #
411
+ # See also {ReceivedMessage#acknowledge!}.
412
+ #
385
413
  # @param [ReceivedMessage, String] messages One or more
386
414
  # {ReceivedMessage} objects or ack_id values.
387
415
  #
@@ -391,8 +419,8 @@ module Google
391
419
  # pubsub = Google::Cloud::Pubsub.new
392
420
  #
393
421
  # sub = pubsub.subscription "my-topic-sub"
394
- # messages = sub.pull
395
- # sub.acknowledge messages
422
+ # received_messages = sub.pull
423
+ # sub.acknowledge received_messages
396
424
  #
397
425
  def acknowledge *messages
398
426
  ack_ids = coerce_ack_ids messages
@@ -410,6 +438,8 @@ module Google
410
438
  # make the messages available for redelivery if the processing was
411
439
  # interrupted.
412
440
  #
441
+ # See also {ReceivedMessage#delay!}.
442
+ #
413
443
  # @param [Integer] new_deadline The new ack deadline in seconds from the
414
444
  # time this request is sent to the Pub/Sub system. Must be >= 0. For
415
445
  # example, if the value is `10`, the new ack deadline will expire 10
@@ -424,8 +454,8 @@ module Google
424
454
  # pubsub = Google::Cloud::Pubsub.new
425
455
  #
426
456
  # sub = pubsub.subscription "my-topic-sub"
427
- # messages = sub.pull
428
- # sub.delay 120, messages
457
+ # received_messages = sub.pull
458
+ # sub.delay 120, received_messages
429
459
  #
430
460
  def delay new_deadline, *messages
431
461
  ack_ids = coerce_ack_ids messages
@@ -510,8 +540,8 @@ module Google
510
540
  #
511
541
  # snapshot = sub.create_snapshot
512
542
  #
513
- # messages = sub.pull
514
- # sub.acknowledge messages
543
+ # received_messages = sub.pull
544
+ # sub.acknowledge received_messages
515
545
  #
516
546
  # sub.seek snapshot
517
547
  #
@@ -523,8 +553,8 @@ module Google
523
553
  #
524
554
  # time = Time.now
525
555
  #
526
- # messages = sub.pull
527
- # sub.acknowledge messages
556
+ # received_messages = sub.pull
557
+ # sub.acknowledge received_messages
528
558
  #
529
559
  # sub.seek time
530
560
  #
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Pubsub
19
- VERSION = "0.27.1"
19
+ VERSION = "0.27.2"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.1
4
+ version: 0.27.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-11 00:00:00.000000000 Z
12
+ date: 2017-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core