google-cloud-pubsub 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5faee5de29df83057422ad7029a047eb10e8408a9b4e87599d301bc1c907a06
4
- data.tar.gz: bc9d9b75232d66b09b5d45310875fbbd734663cf226575e43656da47aa955204
3
+ metadata.gz: 78dd56b9b8fa38d07a2d712afbf6b2d32f20ab11c292018ca15e23c838102e31
4
+ data.tar.gz: e60a9d91b0f0ac99ac8207f3cbfa14d10f48f3fa831461494c3ca05dda804bc6
5
5
  SHA512:
6
- metadata.gz: b59bc075932f2a592276a8e0472371a18a8cc6e835ccb6c36ece17f277528bf92813d978e06393cf384c54c282c8a04fa6ba1d2fcfab08214e3cb3a55d2724ac
7
- data.tar.gz: 8a6fffc01ab630eaf960c3c87858f942fe6a0241cfdf024875d379f2a915be724ea209bcfdc07c7ab12a1299949785456c27f0725d6d4b4cac519749cbc6f1fc
6
+ metadata.gz: 823ff96d9886348199ce5e46335e8bd17f8f0fb316fde14336d9c464c49c13978daab8bd6b15e84c44422d3494b877207535bbc6b15f57c5caff1fb7d4c9f7f0
7
+ data.tar.gz: 04cbd6adba655294efefc38bbf18c48bada0ad7c7f61ab482c8fb9c460115e5a2acf1a936a3e20e39cdac83de004fb404f23032f5a1cc29d2ac9b85d94d6528d
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 2.1.0 / 2020-09-17
4
+
5
+ #### Features
6
+
7
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
8
+ * Add push_config (PushConfig) param to Topic#subscribe
9
+ * Make PushConfig constructor public.
10
+
11
+ #### Documentation
12
+
13
+ * Update sample code for on_error, at_exit, and concurrency tuning
14
+
3
15
  ### 2.0.0 / 2020-08-06
4
16
 
5
17
  This is a major update that removes the "low-level" client interface code, and
@@ -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
@@ -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 }
@@ -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.
@@ -856,6 +863,7 @@ module Google
856
863
  #
857
864
  # subscriber = sub.listen do |received_message|
858
865
  # # process message
866
+ # puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
859
867
  # received_message.acknowledge!
860
868
  # end
861
869
  #
@@ -863,7 +871,7 @@ module Google
863
871
  # subscriber.start
864
872
  #
865
873
  # # Shut down the subscriber when ready to stop receiving messages.
866
- # subscriber.stop.wait!
874
+ # subscriber.stop!
867
875
  #
868
876
  # @example Configuring to increase concurrent callbacks:
869
877
  # require "google/cloud/pubsub"
@@ -882,7 +890,7 @@ module Google
882
890
  # subscriber.start
883
891
  #
884
892
  # # Shut down the subscriber when ready to stop receiving messages.
885
- # subscriber.stop.wait!
893
+ # subscriber.stop!
886
894
  #
887
895
  # @example Ordered messages are supported using ordering_key:
888
896
  # require "google/cloud/pubsub"
@@ -902,7 +910,7 @@ module Google
902
910
  # subscriber.start
903
911
  #
904
912
  # # Shut down the subscriber when ready to stop receiving messages.
905
- # subscriber.stop.wait!
913
+ # subscriber.stop!
906
914
  #
907
915
  # @example Set the maximum amount of time before redelivery if the subscriber fails to extend the deadline:
908
916
  # require "google/cloud/pubsub"
@@ -921,7 +929,7 @@ module Google
921
929
  # subscriber.start
922
930
  #
923
931
  # # Shut down the subscriber when ready to stop receiving messages.
924
- # subscriber.stop.wait!
932
+ # subscriber.stop!
925
933
  #
926
934
  def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block
927
935
  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
@@ -320,15 +323,25 @@ module Google
320
323
  # sub = topic.subscribe "my-topic-sub"
321
324
  # sub.name # => "my-topic-sub"
322
325
  #
323
- # @example Wait 2 minutes for acknowledgement and push all to endpoint:
326
+ # @example Wait 2 minutes for acknowledgement:
324
327
  # require "google/cloud/pubsub"
325
328
  #
326
329
  # pubsub = Google::Cloud::PubSub.new
327
330
  #
328
331
  # topic = pubsub.topic "my-topic"
329
332
  # sub = topic.subscribe "my-topic-sub",
330
- # deadline: 120,
331
- # endpoint: "https://example.com/push"
333
+ # deadline: 120
334
+ #
335
+ # @example Configure a push endpoint:
336
+ # require "google/cloud/pubsub"
337
+ #
338
+ # pubsub = Google::Cloud::PubSub.new
339
+ # topic = pubsub.topic "my-topic"
340
+ #
341
+ # push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
342
+ # push_config.set_oidc_token "service-account@example.net", "audience-header-value"
343
+ #
344
+ # sub = topic.subscribe "my-subscription", push_config: push_config
332
345
  #
333
346
  # @example Configure a Dead Letter Queues policy:
334
347
  # require "google/cloud/pubsub"
@@ -361,19 +374,40 @@ module Google
361
374
  # retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
362
375
  # sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
363
376
  #
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
377
+ def subscribe subscription_name,
378
+ deadline: nil,
379
+ retain_acked: false,
380
+ retention: nil,
381
+ endpoint: nil,
382
+ push_config: nil,
383
+ labels: nil,
384
+ message_ordering: nil,
385
+ filter: nil,
386
+ dead_letter_topic: nil,
387
+ dead_letter_max_delivery_attempts: nil,
388
+ retry_policy: nil
367
389
  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 }
390
+ if push_config && endpoint
391
+ raise ArgumentError, "endpoint and push_config were both provided. Please provide only one."
392
+ end
393
+ push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: endpoint if endpoint
394
+
395
+ options = {
396
+ deadline: deadline,
397
+ retain_acked: retain_acked,
398
+ retention: retention,
399
+ labels: labels,
400
+ message_ordering: message_ordering,
401
+ filter: filter,
402
+ dead_letter_max_delivery_attempts: dead_letter_max_delivery_attempts
403
+ }
371
404
 
372
405
  options[:dead_letter_topic_name] = dead_letter_topic.name if dead_letter_topic
373
406
  if options[:dead_letter_max_delivery_attempts] && !options[:dead_letter_topic_name]
374
407
  # Service error message "3:Invalid resource name given (name=)." does not identify param.
375
408
  raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
376
409
  end
410
+ options[:push_config] = push_config.to_grpc if push_config
377
411
  options[:retry_policy] = retry_policy.to_grpc if retry_policy
378
412
  grpc = service.create_subscription name, subscription_name, options
379
413
  Subscription.from_grpc grpc, service
@@ -590,7 +624,7 @@ module Google
590
624
  # end
591
625
  #
592
626
  # # Shut down the publisher when ready to stop publishing messages.
593
- # topic.async_publisher.stop.wait!
627
+ # topic.async_publisher.stop!
594
628
  #
595
629
  # @example A message can be published using a File object:
596
630
  # require "google/cloud/pubsub"
@@ -602,7 +636,7 @@ module Google
602
636
  # topic.publish_async file
603
637
  #
604
638
  # # Shut down the publisher when ready to stop publishing messages.
605
- # topic.async_publisher.stop.wait!
639
+ # topic.async_publisher.stop!
606
640
  #
607
641
  # @example Additionally, a message can be published with attributes:
608
642
  # require "google/cloud/pubsub"
@@ -614,7 +648,7 @@ module Google
614
648
  # foo: :bar, this: :that
615
649
  #
616
650
  # # Shut down the publisher when ready to stop publishing messages.
617
- # topic.async_publisher.stop.wait!
651
+ # topic.async_publisher.stop!
618
652
  #
619
653
  # @example Ordered messages are supported using ordering_key:
620
654
  # require "google/cloud/pubsub"
@@ -631,7 +665,7 @@ module Google
631
665
  # ordering_key: "task-key"
632
666
  #
633
667
  # # Shut down the publisher when ready to stop publishing messages.
634
- # topic.async_publisher.stop.wait!
668
+ # topic.async_publisher.stop!
635
669
  #
636
670
  def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
637
671
  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.1.0".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.1.0
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: 2020-09-17 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