google-cloud-pubsub 2.0.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5faee5de29df83057422ad7029a047eb10e8408a9b4e87599d301bc1c907a06
4
- data.tar.gz: bc9d9b75232d66b09b5d45310875fbbd734663cf226575e43656da47aa955204
3
+ metadata.gz: 3af82f9222001a7e9b8a4648b53370da523629e3950822ec70b2994c7ff1ab69
4
+ data.tar.gz: c65a361d505e5416be05189668fb62260b91eabb89be8fedc8b4928a9a0724dc
5
5
  SHA512:
6
- metadata.gz: b59bc075932f2a592276a8e0472371a18a8cc6e835ccb6c36ece17f277528bf92813d978e06393cf384c54c282c8a04fa6ba1d2fcfab08214e3cb3a55d2724ac
7
- data.tar.gz: 8a6fffc01ab630eaf960c3c87858f942fe6a0241cfdf024875d379f2a915be724ea209bcfdc07c7ab12a1299949785456c27f0725d6d4b4cac519749cbc6f1fc
6
+ metadata.gz: e0fd3399bed14e3ec636a352cefc9c03a34f76ad20adbd12c3c043bdebf23ea75c68b9cab5e0fe0e259911b7a466f8b0e4d0b138ea9cd3244653d13749b38920
7
+ data.tar.gz: 91243885834f4cb5c3423bc8f6e75383d95cbdb5b09b6a4bd409b701a6c0433838882188a28cf150302cd4ea3fa8c48afc669f7590d9578d67858b246ad77fc7
@@ -1,5 +1,48 @@
1
1
  # Release History
2
2
 
3
+ ### 2.3.1 / 2021-01-13
4
+
5
+ #### Bug Fixes
6
+
7
+ * Update Subscription#retry_policy=
8
+ * Remove conditional RPC to fetch full resource before update.
9
+
10
+ ### 2.3.0 / 2020-11-18
11
+
12
+ #### Features
13
+
14
+ * Add inventory.use_legacy_flow_control to listen options
15
+ * Add inventory.use_legacy_flow_control to Subscription#listen options
16
+ * Add Subscriber#use_legacy_flow_control?
17
+
18
+ #### Documentation
19
+
20
+ * Remove EXPERIMENTAL label from RetryPolicy docs
21
+
22
+ ### 2.2.0 / 2020-11-11
23
+
24
+ #### Features
25
+
26
+ * Add Subscription#remove_dead_letter_policy
27
+
28
+ ### 2.1.1 / 2020-10-26
29
+
30
+ #### Documentation
31
+
32
+ * Update deprecated attribute name limit to max_outstanding_messages
33
+
34
+ ### 2.1.0 / 2020-09-17
35
+
36
+ #### Features
37
+
38
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
39
+ * Add push_config (PushConfig) param to Topic#subscribe
40
+ * Make PushConfig constructor public.
41
+
42
+ #### Documentation
43
+
44
+ * Update sample code for on_error, at_exit, and concurrency tuning
45
+
3
46
  ### 2.0.0 / 2020-08-06
4
47
 
5
48
  This is a major update that removes the "low-level" client interface code, and
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-pubsub/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
@@ -142,7 +142,7 @@ topic.publish_async "task completed" do |result|
142
142
  end
143
143
  end
144
144
 
145
- topic.async_publisher.stop.wait!
145
+ topic.async_publisher.stop!
146
146
  ```
147
147
 
148
148
  Or multiple messages can be published in batches at the same time by passing a
@@ -174,16 +174,32 @@ pubsub = Google::Cloud::PubSub.new
174
174
 
175
175
  sub = pubsub.subscription "my-topic-sub"
176
176
 
177
- subscriber = sub.listen do |received_message|
177
+ # Create a subscriber to listen for available messages.
178
+ # By default, this block will be called on 8 concurrent threads
179
+ # but this can be tuned with the `threads` option.
180
+ # The `streams` and `inventory` parameters allow further tuning.
181
+ subscriber = sub.listen threads: { callback: 16 } do |received_message|
178
182
  # process message
183
+ puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
179
184
  received_message.acknowledge!
180
185
  end
181
186
 
187
+ # Handle exceptions from listener
188
+ subscriber.on_error do |exception|
189
+ puts "Exception: #{exception.class} #{exception.message}"
190
+ end
191
+
192
+ # Gracefully shut down the subscriber on program exit, blocking until
193
+ # all received messages have been processed or 10 seconds have passed
194
+ at_exit do
195
+ subscriber.stop!(10)
196
+ end
197
+
182
198
  # Start background threads that will call the block passed to listen.
183
199
  subscriber.start
184
200
 
185
- # Shut down the subscriber when ready to stop receiving messages.
186
- subscriber.stop.wait!
201
+ # Block, letting processing threads continue in the background
202
+ sleep
187
203
  ```
188
204
 
189
205
  Messages also can be pulled directly in a one-time operation. (See
@@ -235,7 +251,7 @@ end
235
251
  subscriber.start
236
252
 
237
253
  # Shut down the subscriber when ready to stop receiving messages.
238
- subscriber.stop.wait!
254
+ subscriber.stop!
239
255
  ```
240
256
 
241
257
  Or, multiple messages can be acknowledged in a single API call: (See
@@ -277,7 +293,7 @@ end
277
293
  subscriber.start
278
294
 
279
295
  # Shut down the subscriber when ready to stop receiving messages.
280
- subscriber.stop.wait!
296
+ subscriber.stop!
281
297
  ```
282
298
 
283
299
  The message can also be made available for immediate redelivery:
@@ -299,7 +315,7 @@ end
299
315
  subscriber.start
300
316
 
301
317
  # Shut down the subscriber when ready to stop receiving messages.
302
- subscriber.stop.wait!
318
+ subscriber.stop!
303
319
  ```
304
320
 
305
321
  Multiple messages can be delayed or made available for immediate redelivery:
@@ -353,7 +369,7 @@ topic.publish_async "task completed",
353
369
  ordering_key: "task-key"
354
370
 
355
371
  # Shut down the publisher when ready to stop publishing messages.
356
- topic.async_publisher.stop.wait!
372
+ topic.async_publisher.stop!
357
373
  ```
358
374
 
359
375
  ### Handling errors with Ordered Keys
@@ -395,7 +411,7 @@ end
395
411
  subscriber.start
396
412
 
397
413
  # Shut down the subscriber when ready to stop receiving messages.
398
- subscriber.stop.wait!
414
+ subscriber.stop!
399
415
  ```
400
416
 
401
417
  ## Minimizing API calls before receiving and acknowledging messages
@@ -425,7 +441,7 @@ end
425
441
  subscriber.start
426
442
 
427
443
  # Shut down the subscriber when ready to stop receiving messages.
428
- subscriber.stop.wait!
444
+ subscriber.stop!
429
445
  ```
430
446
 
431
447
  Skipping API calls may be used to avoid `Google::Cloud::PermissionDeniedError`
@@ -464,54 +480,6 @@ sub.acknowledge received_messages
464
480
  sub.seek snapshot
465
481
  ```
466
482
 
467
- ## Listening for Messages
468
-
469
- A subscriber object can be created using `listen`, which streams messages from
470
- the backend and processes them as they are received. (See
471
- {Google::Cloud::PubSub::Subscription#listen Subscription#listen} and
472
- {Google::Cloud::PubSub::Subscriber Subscriber})
473
-
474
- ```ruby
475
- require "google/cloud/pubsub"
476
-
477
- pubsub = Google::Cloud::PubSub.new
478
-
479
- sub = pubsub.subscription "my-topic-sub"
480
-
481
- subscriber = sub.listen do |received_message|
482
- # process message
483
- received_message.acknowledge!
484
- end
485
-
486
- # Start background threads that will call the block passed to listen.
487
- subscriber.start
488
-
489
- # Shut down the subscriber when ready to stop receiving messages.
490
- subscriber.stop.wait!
491
- ```
492
-
493
- The subscriber object can be configured to control the number of concurrent
494
- streams to open, the number of received messages to be collected, and the number
495
- of threads each stream opens for concurrent calls made to handle the received
496
- messages.
497
-
498
- ```ruby
499
- require "google/cloud/pubsub"
500
-
501
- pubsub = Google::Cloud::PubSub.new
502
-
503
- sub = pubsub.subscription "my-topic-sub"
504
-
505
- subscriber = sub.listen threads: { callback: 16 } do |received_message|
506
- # store the message somewhere before acknowledging
507
- store_in_backend received_message.data # takes a few seconds
508
- received_message.acknowledge!
509
- end
510
-
511
- # Start background threads that will call the block passed to listen.
512
- subscriber.start
513
- ```
514
-
515
483
  ## Working Across Projects
516
484
 
517
485
  All calls to the Pub/Sub service use the same project and credentials provided
@@ -132,6 +132,7 @@ Google::Cloud.configure.add_config! :pubsub do |config|
132
132
  config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
133
133
  config.add_alias! :keyfile, :credentials
134
134
  config.add_field! :scope, default_scopes, match: [String, Array]
135
+ config.add_field! :quota_project, nil, match: String
135
136
  config.add_field! :timeout, nil, match: Integer
136
137
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
137
138
  config.add_field! :on_error, nil, match: Proc
@@ -42,7 +42,7 @@ module Google
42
42
  # end
43
43
  # end
44
44
  #
45
- # topic.async_publisher.stop.wait!
45
+ # topic.async_publisher.stop!
46
46
  #
47
47
  # @attr_reader [String] topic_name The name of the topic the messages are published to. In the form of
48
48
  # "/projects/project-identifier/topics/topic-name".
@@ -50,7 +50,7 @@ module Google
50
50
  # subscriber.start
51
51
  #
52
52
  # # Shut down the subscriber when ready to stop receiving messages.
53
- # subscriber.stop.wait!
53
+ # subscriber.stop!
54
54
  #
55
55
  class Message
56
56
  ##
@@ -141,7 +141,7 @@ module Google
141
141
  # end
142
142
  # end
143
143
  #
144
- # topic.async_publisher.stop.wait!
144
+ # topic.async_publisher.stop!
145
145
  #
146
146
  def topic topic_name, project: nil, skip_lookup: nil, async: nil
147
147
  ensure_service!
@@ -39,7 +39,7 @@ module Google
39
39
  # subscriber.start
40
40
  #
41
41
  # # Shut down the subscriber when ready to stop receiving messages.
42
- # subscriber.stop.wait!
42
+ # subscriber.stop!
43
43
  #
44
44
  class ReceivedMessage
45
45
  ##
@@ -177,7 +177,7 @@ module Google
177
177
  # subscriber.start
178
178
  #
179
179
  # # Shut down the subscriber when ready to stop receiving messages.
180
- # subscriber.stop.wait!
180
+ # subscriber.stop!
181
181
  #
182
182
  def acknowledge!
183
183
  ensure_subscription!
@@ -214,7 +214,7 @@ module Google
214
214
  # subscriber.start
215
215
  #
216
216
  # # Shut down the subscriber when ready to stop receiving messages.
217
- # subscriber.stop.wait!
217
+ # subscriber.stop!
218
218
  #
219
219
  def modify_ack_deadline! new_deadline
220
220
  ensure_subscription!
@@ -244,7 +244,7 @@ module Google
244
244
  # subscriber.start
245
245
  #
246
246
  # # Shut down the subscriber when ready to stop receiving messages.
247
- # subscriber.stop.wait!
247
+ # subscriber.stop!
248
248
  #
249
249
  def reject!
250
250
  modify_ack_deadline! 0
@@ -31,9 +31,6 @@ module Google
31
31
  # Retry Policy is implemented on a best effort basis. At times, the delay between consecutive deliveries may not
32
32
  # match the configuration. That is, delay can be more or less than configured backoff.
33
33
  #
34
- # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for production
35
- # use. It is not subject to any SLA or deprecation policy.
36
- #
37
34
  # @attr [Numeric] minimum_backoff The minimum delay between consecutive deliveries of a given message. Value
38
35
  # should be between 0 and 600 seconds. The default value is 10 seconds.
39
36
  # @attr [Numeric] maximum_backoff The maximum delay between consecutive deliveries of a given message. Value
@@ -175,15 +175,10 @@ module Google
175
175
  ##
176
176
  # Creates a subscription on a given topic for a given subscriber.
177
177
  def create_subscription topic, subscription_name, options = {}
178
- push_config = if options[:endpoint]
179
- Google::Cloud::PubSub::V1::PushConfig.new \
180
- push_endpoint: options[:endpoint],
181
- attributes: (options[:attributes] || {}).to_h
182
- end
183
178
  subscriber.create_subscription \
184
179
  name: subscription_path(subscription_name, options),
185
180
  topic: topic_path(topic),
186
- push_config: push_config,
181
+ push_config: options[:push_config],
187
182
  ack_deadline_seconds: options[:deadline],
188
183
  retain_acked_messages: options[:retain_acked],
189
184
  message_retention_duration: Convert.number_to_duration(options[:retention]),
@@ -41,7 +41,7 @@ module Google
41
41
  # subscriber.start
42
42
  #
43
43
  # # Shut down the subscriber when ready to stop receiving messages.
44
- # subscriber.stop.wait!
44
+ # subscriber.stop!
45
45
  #
46
46
  # @attr_reader [String] subscription_name The name of the subscription the
47
47
  # messages are pulled from.
@@ -240,7 +240,7 @@ module Google
240
240
  # subscriber.start
241
241
  #
242
242
  # # Shut down the subscriber when ready to stop receiving messages.
243
- # subscriber.stop.wait!
243
+ # subscriber.stop!
244
244
  #
245
245
  def on_error &block
246
246
  synchronize do
@@ -276,7 +276,7 @@ module Google
276
276
  # subscriber.last_error #=> nil
277
277
  #
278
278
  # # Shut down the subscriber when ready to stop receiving messages.
279
- # subscriber.stop.wait!
279
+ # subscriber.stop!
280
280
  #
281
281
  def last_error
282
282
  synchronize { @last_error }
@@ -306,6 +306,17 @@ module Google
306
306
  # @deprecated Use {#max_outstanding_bytes}.
307
307
  alias inventory_bytesize max_outstanding_bytes
308
308
 
309
+ ##
310
+ # Whether to enforce flow control at the client side only or to enforce it at both the client and
311
+ # the server. For more details about flow control see https://cloud.google.com/pubsub/docs/pull#config.
312
+ #
313
+ # @return [Boolean] `true` when only client side flow control is enforced, `false` when both client and
314
+ # server side flow control are enforced.
315
+ #
316
+ def use_legacy_flow_control?
317
+ @inventory[:use_legacy_flow_control]
318
+ end
319
+
309
320
  ##
310
321
  # The number of seconds that received messages can be held awaiting processing. Default is 3,600 (1 hour).
311
322
  #
@@ -334,7 +345,8 @@ module Google
334
345
  limit: @inventory[:max_outstanding_messages].fdiv(@streams).ceil,
335
346
  bytesize: @inventory[:max_outstanding_bytes].fdiv(@streams).ceil,
336
347
  extension: @inventory[:max_total_lease_duration],
337
- max_duration_per_lease_extension: @inventory[:max_duration_per_lease_extension]
348
+ max_duration_per_lease_extension: @inventory[:max_duration_per_lease_extension],
349
+ use_legacy_flow_control: @inventory[:use_legacy_flow_control]
338
350
  }
339
351
  end
340
352
 
@@ -377,6 +389,7 @@ module Google
377
389
  @inventory[:max_outstanding_bytes] = Integer(@inventory[:max_outstanding_bytes] || 100_000_000)
378
390
  @inventory[:max_total_lease_duration] = Integer(@inventory[:max_total_lease_duration] || 3600)
379
391
  @inventory[:max_duration_per_lease_extension] = Integer(@inventory[:max_duration_per_lease_extension] || 0)
392
+ @inventory[:use_legacy_flow_control] = @inventory[:use_legacy_flow_control] || false
380
393
  end
381
394
 
382
395
  def default_error_callbacks
@@ -30,15 +30,18 @@ module Google
30
30
 
31
31
  include MonitorMixin
32
32
 
33
- attr_reader :stream, :limit, :bytesize, :extension, :max_duration_per_lease_extension
33
+ attr_reader :stream, :limit, :bytesize, :extension, :max_duration_per_lease_extension,
34
+ :use_legacy_flow_control
34
35
 
35
- def initialize stream, limit:, bytesize:, extension:, max_duration_per_lease_extension:
36
+ def initialize stream, limit:, bytesize:, extension:, max_duration_per_lease_extension:,
37
+ use_legacy_flow_control:
36
38
  super()
37
39
  @stream = stream
38
40
  @limit = limit
39
41
  @bytesize = bytesize
40
42
  @extension = extension
41
43
  @max_duration_per_lease_extension = max_duration_per_lease_extension
44
+ @use_legacy_flow_control = use_legacy_flow_control
42
45
  @inventory = {}
43
46
  @wait_cond = new_cond
44
47
  end
@@ -363,8 +363,8 @@ module Google
363
363
  req.modify_deadline_ack_ids += @inventory.ack_ids
364
364
  req.modify_deadline_seconds += @inventory.ack_ids.map { @subscriber.deadline }
365
365
  req.client_id = @subscriber.service.client_id
366
- req.max_outstanding_messages = @inventory.limit
367
- req.max_outstanding_bytes = @inventory.bytesize
366
+ req.max_outstanding_messages = @inventory.use_legacy_flow_control ? 0 : @inventory.limit
367
+ req.max_outstanding_bytes = @inventory.use_legacy_flow_control ? 0 : @inventory.bytesize
368
368
  end
369
369
  end
370
370
 
@@ -43,12 +43,19 @@ module Google
43
43
  # received_message.acknowledge!
44
44
  # end
45
45
  #
46
- # # Start background threads that will call the block passed to listen.
47
- # subscriber.start
46
+ # # Handle exceptions from listener
47
+ # subscriber.on_error do |exception|
48
+ # puts "Exception: #{exception.class} #{exception.message}"
49
+ # end
48
50
  #
49
- # # Shut down the subscriber when ready to stop receiving messages.
50
- # subscriber.stop.wait!
51
+ # # Gracefully shut down the subscriber
52
+ # at_exit do
53
+ # subscriber.stop!
54
+ # end
51
55
  #
56
+ # # Start background threads that will call the block passed to listen.
57
+ # subscriber.start
58
+ # sleep
52
59
  class Subscription
53
60
  ##
54
61
  # @private The Service object.
@@ -323,7 +330,7 @@ module Google
323
330
  # If {#expires_in=} is not set, a *default* value of of 31 days will be
324
331
  # used. The minimum allowed value is 1 day.
325
332
  #
326
- # Makes an API call to retrieve the value when called on a
333
+ # Makes an API call to retrieve the expires_in value when called on a
327
334
  # reference object. See {#reference?}.
328
335
  #
329
336
  # @return [Numeric, nil] The expiration duration, or `nil` if unset.
@@ -358,6 +365,9 @@ module Google
358
365
  # `attributes` field matches the filter are delivered on this subscription. If empty, then no messages are
359
366
  # filtered out.
360
367
  #
368
+ # Makes an API call to retrieve the filter value when called on a reference
369
+ # object. See {#reference?}.
370
+ #
361
371
  # @return [String] The frozen filter string.
362
372
  #
363
373
  def filter
@@ -370,8 +380,8 @@ module Google
370
380
  # otherwise `nil`. Dead lettering is done on a best effort basis. The same message might be dead lettered
371
381
  # multiple times.
372
382
  #
373
- # See also {#dead_letter_topic=}, {#dead_letter_max_delivery_attempts=} and
374
- # {#dead_letter_max_delivery_attempts}.
383
+ # See also {#dead_letter_topic=}, {#dead_letter_max_delivery_attempts=}, {#dead_letter_max_delivery_attempts}
384
+ # and {#remove_dead_letter_policy}.
375
385
  #
376
386
  # Makes an API call to retrieve the topic name when called on a reference object. See {#reference?}.
377
387
  #
@@ -402,7 +412,11 @@ module Google
402
412
  # The operation will fail if the topic does not exist. Users should ensure that there is a subscription attached
403
413
  # to this topic since messages published to a topic with no subscriptions are lost.
404
414
  #
405
- # See also {#dead_letter_topic}, {#dead_letter_max_delivery_attempts=} and {#dead_letter_max_delivery_attempts}.
415
+ # Makes an API call to retrieve the dead_letter_policy value when called on a
416
+ # reference object. See {#reference?}.
417
+ #
418
+ # See also {#dead_letter_topic}, {#dead_letter_max_delivery_attempts=}, {#dead_letter_max_delivery_attempts}
419
+ # and {#remove_dead_letter_policy}.
406
420
  #
407
421
  # @param [Topic] new_dead_letter_topic The topic to which dead letter messages for the subscription should be
408
422
  # published.
@@ -434,14 +448,15 @@ module Google
434
448
  # acknowledgement deadline has been exceeded for the message). A NACK is any call to ModifyAckDeadline with a 0
435
449
  # deadline. Note that client libraries may automatically extend ack_deadlines.
436
450
  #
437
- # This field will be honored on a best effort basis. If this parameter is 0, a default value of 5 is used.
451
+ # This field will be honored on a best effort basis. If this parameter is `nil` or `0`, a default value of `5`
452
+ # is used.
438
453
  #
439
- # See also {#dead_letter_max_delivery_attempts=}, {#dead_letter_topic=} and {#dead_letter_topic}.
454
+ # See also {#dead_letter_max_delivery_attempts=}, {#dead_letter_topic=}, {#dead_letter_topic}
455
+ # and {#remove_dead_letter_policy}.
440
456
  #
441
- # Makes an API call to retrieve the value when called on a reference object. See {#reference?}.
457
+ # Makes an API call to retrieve the dead_letter_policy when called on a reference object. See {#reference?}.
442
458
  #
443
- # @return [Integer, nil] A value between 5 and 100, or `nil` if no dead letter policy is configured. If this
444
- # value is 0, a default value of 5 is used.
459
+ # @return [Integer, nil] A value between `5` and `100`, or `nil` if no dead letter policy is configured.
445
460
  #
446
461
  # @example
447
462
  # require "google/cloud/pubsub"
@@ -468,10 +483,15 @@ module Google
468
483
  #
469
484
  # This field will be honored on a best effort basis. If this parameter is 0, a default value of 5 is used.
470
485
  #
471
- # The dead letter topic must also be set. See {#dead_letter_topic=} and {#dead_letter_topic}.
486
+ # Makes an API call to retrieve the dead_letter_policy when called on a reference object. See {#reference?}.
472
487
  #
473
- # @param [Integer] new_dead_letter_max_delivery_attempts A value between 5 and 100. If this parameter is 0, a
474
- # default value of 5 is used.
488
+ # The dead letter topic must be set first. See {#dead_letter_topic=}, {#dead_letter_topic} and
489
+ # {#remove_dead_letter_policy}.
490
+ #
491
+ # @param [Integer, nil] new_dead_letter_max_delivery_attempts A value between 5 and 100. If this parameter is
492
+ # `nil` or `0`, a default value of 5 is used.
493
+ #
494
+ # @raise [ArgumentError] if the dead letter topic has not been set. See {#dead_letter_topic=}.
475
495
  #
476
496
  # @example
477
497
  # require "google/cloud/pubsub"
@@ -496,14 +516,48 @@ module Google
496
516
  @resource_name = nil
497
517
  end
498
518
 
519
+ ##
520
+ # Removes an existing dead letter policy. A dead letter policy specifies the conditions for dead lettering
521
+ # messages in the subscription. If a dead letter policy is not set, dead lettering is disabled.
522
+ #
523
+ # Makes an API call to retrieve the dead_letter_policy when called on a reference object. See {#reference?}.
524
+ #
525
+ # See {#dead_letter_topic}, {#dead_letter_topic=}, {#dead_letter_max_delivery_attempts} and
526
+ # {#dead_letter_max_delivery_attempts=}.
527
+ #
528
+ # @return [Boolean] `true` if an existing dead letter policy was removed, `false` if no existing dead letter
529
+ # policy was present.
530
+ #
531
+ # @example
532
+ # require "google/cloud/pubsub"
533
+ #
534
+ # pubsub = Google::Cloud::PubSub.new
535
+ #
536
+ # sub = pubsub.subscription "my-topic-sub"
537
+ #
538
+ # sub.dead_letter_topic.name #=> "projects/my-project/topics/my-dead-letter-topic"
539
+ # sub.dead_letter_max_delivery_attempts #=> 10
540
+ #
541
+ # sub.remove_dead_letter_policy
542
+ #
543
+ # sub.dead_letter_topic #=> nil
544
+ # sub.dead_letter_max_delivery_attempts #=> nil
545
+ #
546
+ def remove_dead_letter_policy
547
+ ensure_grpc!
548
+ return false if @grpc.dead_letter_policy.nil?
549
+ update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, dead_letter_policy: nil
550
+ @grpc = service.update_subscription update_grpc, :dead_letter_policy
551
+ true
552
+ end
553
+
499
554
  ##
500
555
  # A policy that specifies how Cloud Pub/Sub retries message delivery for this subscription. If `nil`, the
501
556
  # default retry policy is applied. This generally implies that messages will be retried as soon as possible
502
557
  # for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
503
558
  # for a given message.
504
559
  #
505
- # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
506
- # production use. It is not subject to any SLA or deprecation policy.
560
+ # Makes an API call to retrieve the retry_policy when called on a reference object. See {#reference?}.
507
561
  #
508
562
  # @return [RetryPolicy, nil] The retry policy for the subscription, or `nil`.
509
563
  #
@@ -531,9 +585,6 @@ module Google
531
585
  # for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
532
586
  # for a given message.
533
587
  #
534
- # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
535
- # production use. It is not subject to any SLA or deprecation policy.
536
- #
537
588
  # @param [RetryPolicy, nil] new_retry_policy A new retry policy for the subscription, or `nil`.
538
589
  #
539
590
  # @example
@@ -549,10 +600,11 @@ module Google
549
600
  # sub.retry_policy.maximum_backoff #=> 300
550
601
  #
551
602
  def retry_policy= new_retry_policy
552
- ensure_grpc!
603
+ ensure_service!
553
604
  new_retry_policy = new_retry_policy.to_grpc if new_retry_policy
554
605
  update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, retry_policy: new_retry_policy
555
606
  @grpc = service.update_subscription update_grpc, :retry_policy
607
+ @resource_name = nil
556
608
  end
557
609
 
558
610
  ##
@@ -584,7 +636,7 @@ module Google
584
636
  #
585
637
  # See {Topic#subscribe} and {#detach}.
586
638
  #
587
- # Makes an API call to retrieve the value when called on a
639
+ # Makes an API call to retrieve the detached value when called on a
588
640
  # reference object. See {#reference?}.
589
641
  #
590
642
  # @return [Boolean]
@@ -816,7 +868,8 @@ module Google
816
868
  # @param [Integer] streams The number of concurrent streams to open to
817
869
  # pull messages from the subscription. Default is 4. Optional.
818
870
  # @param [Hash, Integer] inventory The settings to control how received messages are to be handled by the
819
- # subscriber. When provided as an Integer instead of a Hash only the `limit` will be set. Optional.
871
+ # subscriber. When provided as an Integer instead of a Hash only `max_outstanding_messages` will be set.
872
+ # Optional.
820
873
  #
821
874
  # Hash keys and values may include the following:
822
875
  #
@@ -824,6 +877,9 @@ module Google
824
877
  # Default is 1,000. (Note: replaces `:limit`, which is deprecated.)
825
878
  # * `:max_outstanding_bytes` [Integer] The total byte size of received messages to be collected by
826
879
  # subscriber. Default is 100,000,000 (100MB). (Note: replaces `:bytesize`, which is deprecated.)
880
+ # * `:use_legacy_flow_control` [Boolean] Disables enforcing flow control settings at the Cloud PubSub
881
+ # server and the less accurate method of only enforcing flow control at the client side is used instead.
882
+ # Default is false.
827
883
  # * `:max_total_lease_duration` [Integer] The number of seconds that received messages can be held awaiting
828
884
  # processing. Default is 3,600 (1 hour). (Note: replaces `:extension`, which is deprecated.)
829
885
  # * `:max_duration_per_lease_extension` [Integer] The maximum amount of time in seconds for a single lease
@@ -856,6 +912,7 @@ module Google
856
912
  #
857
913
  # subscriber = sub.listen do |received_message|
858
914
  # # process message
915
+ # puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
859
916
  # received_message.acknowledge!
860
917
  # end
861
918
  #
@@ -863,7 +920,7 @@ module Google
863
920
  # subscriber.start
864
921
  #
865
922
  # # Shut down the subscriber when ready to stop receiving messages.
866
- # subscriber.stop.wait!
923
+ # subscriber.stop!
867
924
  #
868
925
  # @example Configuring to increase concurrent callbacks:
869
926
  # require "google/cloud/pubsub"
@@ -882,7 +939,7 @@ module Google
882
939
  # subscriber.start
883
940
  #
884
941
  # # Shut down the subscriber when ready to stop receiving messages.
885
- # subscriber.stop.wait!
942
+ # subscriber.stop!
886
943
  #
887
944
  # @example Ordered messages are supported using ordering_key:
888
945
  # require "google/cloud/pubsub"
@@ -902,7 +959,7 @@ module Google
902
959
  # subscriber.start
903
960
  #
904
961
  # # Shut down the subscriber when ready to stop receiving messages.
905
- # subscriber.stop.wait!
962
+ # subscriber.stop!
906
963
  #
907
964
  # @example Set the maximum amount of time before redelivery if the subscriber fails to extend the deadline:
908
965
  # require "google/cloud/pubsub"
@@ -921,7 +978,7 @@ module Google
921
978
  # subscriber.start
922
979
  #
923
980
  # # Shut down the subscriber when ready to stop receiving messages.
924
- # subscriber.stop.wait!
981
+ # subscriber.stop!
925
982
  #
926
983
  def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block
927
984
  ensure_service!
@@ -22,7 +22,18 @@ module Google
22
22
  ##
23
23
  # Configuration for a push delivery endpoint.
24
24
  #
25
- # @example
25
+ # @example Create a push config:
26
+ # require "google/cloud/pubsub"
27
+ #
28
+ # pubsub = Google::Cloud::PubSub.new
29
+ # topic = pubsub.topic "my-topic"
30
+ #
31
+ # push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
32
+ # push_config.set_oidc_token "service-account@example.net", "audience-header-value"
33
+ #
34
+ # sub = topic.subscribe "my-subscription", push_config: push_config
35
+ #
36
+ # @example Read a push config:
26
37
  # require "google/cloud/pubsub"
27
38
  #
28
39
  # pubsub = Google::Cloud::PubSub.new
@@ -32,7 +43,7 @@ module Google
32
43
  # sub.push_config.authentication.email #=> "user@example.com"
33
44
  # sub.push_config.authentication.audience #=> "client-12345"
34
45
  #
35
- # @example Update the push configuration by passing a block:
46
+ # @example Update a push config:
36
47
  # require "google/cloud/pubsub"
37
48
  #
38
49
  # pubsub = Google::Cloud::PubSub.new
@@ -45,14 +56,31 @@ module Google
45
56
  #
46
57
  class PushConfig
47
58
  ##
48
- # @private
49
- def initialize
59
+ # Creates a new push configuration.
60
+ #
61
+ # @param [String] endpoint A URL locating the endpoint to which messages should be pushed. For
62
+ # example, a Webhook endpoint might use `https://example.com/push`.
63
+ # @param [String] email The service account email to be used for generating the OIDC token.
64
+ # The caller must have the `iam.serviceAccounts.actAs` permission for the service account.
65
+ # @param [String] audience The audience to be used when generating OIDC token. The audience claim identifies
66
+ # the recipients that the JWT is intended for. The audience value is a single case-sensitive string. Having
67
+ # multiple values (array) for the audience field is not supported. More info about the OIDC JWT token
68
+ # audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint`
69
+ # URL will be used.
70
+ #
71
+ def initialize endpoint: nil, email: nil, audience: nil
50
72
  @grpc = Google::Cloud::PubSub::V1::PushConfig.new
73
+
74
+ self.endpoint = endpoint unless endpoint.nil?
75
+
76
+ raise ArgumentError, "audience provided without email. Authentication is invalid" if audience && !email
77
+
78
+ set_oidc_token email, audience if email
51
79
  end
52
80
 
53
81
  ##
54
- # A URL locating the endpoint to which messages should be pushed. For
55
- # example, a Webhook endpoint might use `https://example.com/push`.
82
+ # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use
83
+ # `https://example.com/push`.
56
84
  #
57
85
  # @return [String]
58
86
  def endpoint
@@ -60,9 +88,8 @@ module Google
60
88
  end
61
89
 
62
90
  ##
63
- # Sets the URL locating the endpoint to which messages should be
64
- # pushed. For example, a Webhook endpoint might use
65
- # `https://example.com/push`.
91
+ # Sets the URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might
92
+ # use `https://example.com/push`.
66
93
  #
67
94
  # @param [String, nil] new_endpoint New URL value
68
95
  def endpoint= new_endpoint
@@ -70,8 +97,7 @@ module Google
70
97
  end
71
98
 
72
99
  ##
73
- # The authentication method used by push endpoints to verify the
74
- # source of push requests.
100
+ # The authentication method used by push endpoints to verify the source of push requests.
75
101
  #
76
102
  # @return [OidcToken, nil] An OIDC JWT token if specified, `nil`
77
103
  # otherwise.
@@ -82,8 +108,7 @@ module Google
82
108
  end
83
109
 
84
110
  ##
85
- # Sets the authentication method used by push endpoints to verify the
86
- # source of push requests.
111
+ # Sets the authentication method used by push endpoints to verify the source of push requests.
87
112
  #
88
113
  # @param [OidcToken, nil] new_auth An authentication value.
89
114
  def authentication= new_auth
@@ -118,13 +143,12 @@ module Google
118
143
  end
119
144
 
120
145
  ##
121
- # The format of the pushed message. This attribute indicates the
122
- # version of the data expected by the endpoint. This controls the
123
- # shape of the pushed message (i.e., its fields and metadata). The
124
- # endpoint version is based on the version of the Pub/Sub API.
146
+ # The format of the pushed message. This attribute indicates the version of the data expected by the endpoint.
147
+ # This controls the shape of the pushed message (i.e., its fields and metadata). The endpoint version is based
148
+ # on the version of the Pub/Sub API.
125
149
  #
126
- # If not present during the Subscription creation, it will default to
127
- # the version of the API used to make such call.
150
+ # If not present during the Subscription creation, it will default to the version of the API used to make such
151
+ # call.
128
152
  #
129
153
  # The possible values for this attribute are:
130
154
  #
@@ -182,7 +206,8 @@ module Google
182
206
  end
183
207
 
184
208
  ##
185
- # Service account email to be used for generating the OIDC token.
209
+ # The service account email to be used for generating the OIDC token. The caller must have the
210
+ # `iam.serviceAccounts.actAs` permission for the service account.
186
211
  #
187
212
  # @return [String]
188
213
  def email
@@ -190,7 +215,8 @@ module Google
190
215
  end
191
216
 
192
217
  ##
193
- # Service account email to be used for generating the OIDC token.
218
+ # Sets the service account email to be used for generating the OIDC token. The caller must have the
219
+ # `iam.serviceAccounts.actAs` permission for the service account.
194
220
  #
195
221
  # @param [String] new_email New service account email value.
196
222
  def email= new_email
@@ -198,15 +224,10 @@ module Google
198
224
  end
199
225
 
200
226
  ##
201
- # Audience to be used when generating OIDC token. The audience claim
202
- # identifies the recipients that the JWT is intended for. The
203
- # audience value is a single case-sensitive string.
204
- #
205
- # Having multiple values (array) for the audience field is not
206
- # supported.
207
- #
208
- # More info about the OIDC JWT token audience here:
209
- # https://tools.ietf.org/html/rfc7519#section-4.1.3
227
+ # The audience to be used when generating OIDC token. The audience claim identifies the recipients that
228
+ # the JWT is intended for. The audience value is a single case-sensitive string. Having multiple values
229
+ # (array) for the audience field is not supported. More info about the OIDC JWT token audience here:
230
+ # https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint` URL will be used.
210
231
  #
211
232
  # @return [String]
212
233
  def audience
@@ -214,7 +235,10 @@ module Google
214
235
  end
215
236
 
216
237
  ##
217
- # Sets the audience to be used when generating OIDC token.
238
+ # Sets the audience to be used when generating OIDC token. The audience claim identifies the recipients that
239
+ # the JWT is intended for. The audience value is a single case-sensitive string. Having multiple values
240
+ # (array) for the audience field is not supported. More info about the OIDC JWT token audience here:
241
+ # https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint` URL will be used.
218
242
  #
219
243
  # @param [String] new_audience New audience value.
220
244
  def audience= new_audience
@@ -78,7 +78,7 @@ module Google
78
78
  # end
79
79
  # end
80
80
  #
81
- # topic.async_publisher.stop.wait!
81
+ # topic.async_publisher.stop!
82
82
  #
83
83
  def async_publisher
84
84
  @async_publisher
@@ -275,7 +275,10 @@ module Google
275
275
  # 604,800 seconds (7 days) or less than 600 seconds (10 minutes).
276
276
  # Default is 604,800 seconds (7 days).
277
277
  # @param [String] endpoint A URL locating the endpoint to which messages
278
- # should be pushed.
278
+ # should be pushed. The parameters `push_config` and `endpoint` should not both be provided.
279
+ # @param [Google::Cloud::PubSub::Subscription::PushConfig] push_config The configuration for a push delivery
280
+ # endpoint that should contain the endpoint, and can contain authentication data (OIDC token authentication).
281
+ # The parameters `push_config` and `endpoint` should not both be provided.
279
282
  # @param [Hash] labels A hash of user-provided labels associated with
280
283
  # the subscription. You can use these to organize and group your
281
284
  # subscriptions. Label keys and values can be no longer than 63
@@ -306,9 +309,6 @@ module Google
306
309
  # will be retried as soon as possible for healthy subscribers. Retry Policy will be triggered on NACKs or
307
310
  # acknowledgement deadline exceeded events for a given message.
308
311
  #
309
- # **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
310
- # production use. It is not subject to any SLA or deprecation policy.
311
- #
312
312
  # @return [Google::Cloud::PubSub::Subscription]
313
313
  #
314
314
  # @example
@@ -320,15 +320,25 @@ module Google
320
320
  # sub = topic.subscribe "my-topic-sub"
321
321
  # sub.name # => "my-topic-sub"
322
322
  #
323
- # @example Wait 2 minutes for acknowledgement and push all to endpoint:
323
+ # @example Wait 2 minutes for acknowledgement:
324
324
  # require "google/cloud/pubsub"
325
325
  #
326
326
  # pubsub = Google::Cloud::PubSub.new
327
327
  #
328
328
  # topic = pubsub.topic "my-topic"
329
329
  # sub = topic.subscribe "my-topic-sub",
330
- # deadline: 120,
331
- # endpoint: "https://example.com/push"
330
+ # deadline: 120
331
+ #
332
+ # @example Configure a push endpoint:
333
+ # require "google/cloud/pubsub"
334
+ #
335
+ # pubsub = Google::Cloud::PubSub.new
336
+ # topic = pubsub.topic "my-topic"
337
+ #
338
+ # push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
339
+ # push_config.set_oidc_token "service-account@example.net", "audience-header-value"
340
+ #
341
+ # sub = topic.subscribe "my-subscription", push_config: push_config
332
342
  #
333
343
  # @example Configure a Dead Letter Queues policy:
334
344
  # require "google/cloud/pubsub"
@@ -361,19 +371,40 @@ module Google
361
371
  # retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
362
372
  # sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
363
373
  #
364
- def subscribe subscription_name, deadline: nil, retain_acked: false, retention: nil, endpoint: nil, labels: nil,
365
- message_ordering: nil, filter: nil, dead_letter_topic: nil,
366
- dead_letter_max_delivery_attempts: nil, retry_policy: nil
374
+ def subscribe subscription_name,
375
+ deadline: nil,
376
+ retain_acked: false,
377
+ retention: nil,
378
+ endpoint: nil,
379
+ push_config: nil,
380
+ labels: nil,
381
+ message_ordering: nil,
382
+ filter: nil,
383
+ dead_letter_topic: nil,
384
+ dead_letter_max_delivery_attempts: nil,
385
+ retry_policy: nil
367
386
  ensure_service!
368
- options = { deadline: deadline, retain_acked: retain_acked, retention: retention, endpoint: endpoint,
369
- labels: labels, message_ordering: message_ordering, filter: filter,
370
- dead_letter_max_delivery_attempts: dead_letter_max_delivery_attempts }
387
+ if push_config && endpoint
388
+ raise ArgumentError, "endpoint and push_config were both provided. Please provide only one."
389
+ end
390
+ push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: endpoint if endpoint
391
+
392
+ options = {
393
+ deadline: deadline,
394
+ retain_acked: retain_acked,
395
+ retention: retention,
396
+ labels: labels,
397
+ message_ordering: message_ordering,
398
+ filter: filter,
399
+ dead_letter_max_delivery_attempts: dead_letter_max_delivery_attempts
400
+ }
371
401
 
372
402
  options[:dead_letter_topic_name] = dead_letter_topic.name if dead_letter_topic
373
403
  if options[:dead_letter_max_delivery_attempts] && !options[:dead_letter_topic_name]
374
404
  # Service error message "3:Invalid resource name given (name=)." does not identify param.
375
405
  raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
376
406
  end
407
+ options[:push_config] = push_config.to_grpc if push_config
377
408
  options[:retry_policy] = retry_policy.to_grpc if retry_policy
378
409
  grpc = service.create_subscription name, subscription_name, options
379
410
  Subscription.from_grpc grpc, service
@@ -590,7 +621,7 @@ module Google
590
621
  # end
591
622
  #
592
623
  # # Shut down the publisher when ready to stop publishing messages.
593
- # topic.async_publisher.stop.wait!
624
+ # topic.async_publisher.stop!
594
625
  #
595
626
  # @example A message can be published using a File object:
596
627
  # require "google/cloud/pubsub"
@@ -602,7 +633,7 @@ module Google
602
633
  # topic.publish_async file
603
634
  #
604
635
  # # Shut down the publisher when ready to stop publishing messages.
605
- # topic.async_publisher.stop.wait!
636
+ # topic.async_publisher.stop!
606
637
  #
607
638
  # @example Additionally, a message can be published with attributes:
608
639
  # require "google/cloud/pubsub"
@@ -614,7 +645,7 @@ module Google
614
645
  # foo: :bar, this: :that
615
646
  #
616
647
  # # Shut down the publisher when ready to stop publishing messages.
617
- # topic.async_publisher.stop.wait!
648
+ # topic.async_publisher.stop!
618
649
  #
619
650
  # @example Ordered messages are supported using ordering_key:
620
651
  # require "google/cloud/pubsub"
@@ -631,7 +662,7 @@ module Google
631
662
  # ordering_key: "task-key"
632
663
  #
633
664
  # # Shut down the publisher when ready to stop publishing messages.
634
- # topic.async_publisher.stop.wait!
665
+ # topic.async_publisher.stop!
635
666
  #
636
667
  def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
637
668
  ensure_service!
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.0.0".freeze
19
+ VERSION = "2.3.1".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
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: 2.0.0
4
+ version: 2.3.1
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: 2020-08-06 00:00:00.000000000 Z
12
+ date: 2021-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  - !ruby/object:Gem::Version
260
260
  version: '0'
261
261
  requirements: []
262
- rubygems_version: 3.1.3
262
+ rubygems_version: 3.1.4
263
263
  signing_key:
264
264
  specification_version: 4
265
265
  summary: API Client library for Google Cloud Pub/Sub