google-cloud-pubsub 0.20.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +18 -0
- data/AUTHENTICATION.md +178 -0
- data/CHANGELOG.md +659 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +187 -0
- data/EMULATOR.md +37 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +528 -0
- data/TROUBLESHOOTING.md +31 -0
- data/lib/google/cloud/pubsub/async_publisher/batch.rb +310 -0
- data/lib/google/cloud/pubsub/async_publisher.rb +402 -0
- data/lib/google/cloud/pubsub/batch_publisher.rb +100 -0
- data/lib/google/cloud/pubsub/convert.rb +91 -0
- data/lib/google/cloud/pubsub/credentials.rb +26 -10
- data/lib/google/cloud/pubsub/errors.rb +85 -0
- data/lib/google/cloud/pubsub/message.rb +82 -20
- data/lib/google/cloud/pubsub/policy.rb +40 -61
- data/lib/google/cloud/pubsub/project.rb +405 -265
- data/lib/google/cloud/pubsub/publish_result.rb +103 -0
- data/lib/google/cloud/pubsub/received_message.rb +165 -30
- data/lib/google/cloud/pubsub/retry_policy.rb +88 -0
- data/lib/google/cloud/pubsub/schema/list.rb +180 -0
- data/lib/google/cloud/pubsub/schema.rb +310 -0
- data/lib/google/cloud/pubsub/service.rb +304 -162
- data/lib/google/cloud/pubsub/snapshot/list.rb +178 -0
- data/lib/google/cloud/pubsub/snapshot.rb +205 -0
- data/lib/google/cloud/pubsub/subscriber/enumerator_queue.rb +54 -0
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +173 -0
- data/lib/google/cloud/pubsub/subscriber/sequencer.rb +115 -0
- data/lib/google/cloud/pubsub/subscriber/stream.rb +400 -0
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +230 -0
- data/lib/google/cloud/pubsub/subscriber.rb +417 -0
- data/lib/google/cloud/pubsub/subscription/list.rb +38 -43
- data/lib/google/cloud/pubsub/subscription/push_config.rb +268 -0
- data/lib/google/cloud/pubsub/subscription.rb +1040 -210
- data/lib/google/cloud/pubsub/topic/list.rb +32 -37
- data/lib/google/cloud/pubsub/topic.rb +726 -177
- data/lib/google/cloud/pubsub/version.rb +6 -4
- data/lib/google/cloud/pubsub.rb +138 -413
- data/lib/google-cloud-pubsub.rb +60 -42
- metadata +88 -39
- data/lib/google/cloud/pubsub/topic/publisher.rb +0 -87
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -117
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright 2016 Google
|
1
|
+
# Copyright 2016 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -15,8 +15,10 @@
|
|
15
15
|
|
16
16
|
module Google
|
17
17
|
module Cloud
|
18
|
-
module
|
19
|
-
VERSION = "
|
18
|
+
module PubSub
|
19
|
+
VERSION = "2.6.1".freeze
|
20
20
|
end
|
21
|
+
|
22
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
21
23
|
end
|
22
24
|
end
|
data/lib/google/cloud/pubsub.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright 2015 Google
|
1
|
+
# Copyright 2015 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
require "google-cloud-pubsub"
|
17
17
|
require "google/cloud/pubsub/project"
|
18
|
+
require "google/cloud/config"
|
19
|
+
require "google/cloud/env"
|
18
20
|
|
19
21
|
module Google
|
20
22
|
module Cloud
|
@@ -28,418 +30,141 @@ module Google
|
|
28
30
|
# Cloud Pub/Sub allows developers to communicate between independently
|
29
31
|
# written applications.
|
30
32
|
#
|
31
|
-
#
|
32
|
-
# Rubyists. Authentication is handled by {Google::Cloud#pubsub}. You can
|
33
|
-
# provide the project and credential information to connect to the Pub/Sub
|
34
|
-
# service, or if you are running on Google Compute Engine this configuration
|
35
|
-
# is taken care of for you.
|
33
|
+
# See {file:OVERVIEW.md Google Cloud Pub/Sub Overview}.
|
36
34
|
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
#
|
166
|
-
# topic = pubsub.topic "my-topic"
|
167
|
-
# msgs = topic.publish do |batch|
|
168
|
-
# batch.publish "new-message-1", foo: :bar
|
169
|
-
# batch.publish "new-message-2", foo: :baz
|
170
|
-
# batch.publish "new-message-3", foo: :bif
|
171
|
-
# end
|
172
|
-
# ```
|
173
|
-
#
|
174
|
-
# ## Pulling Messages
|
175
|
-
#
|
176
|
-
# Messages are pulled from a Subscription. (See
|
177
|
-
# {Google::Cloud::Pubsub::Subscription#pull})
|
178
|
-
#
|
179
|
-
# ```ruby
|
180
|
-
# require "google/cloud"
|
181
|
-
#
|
182
|
-
# gcloud = Google::Cloud.new
|
183
|
-
# pubsub = gcloud.pubsub
|
184
|
-
#
|
185
|
-
# sub = pubsub.subscription "my-topic-sub"
|
186
|
-
# msgs = sub.pull
|
187
|
-
# ```
|
188
|
-
#
|
189
|
-
# A maximum number of messages returned can also be specified:
|
190
|
-
#
|
191
|
-
# ```ruby
|
192
|
-
# require "google/cloud"
|
193
|
-
#
|
194
|
-
# gcloud = Google::Cloud.new
|
195
|
-
# pubsub = gcloud.pubsub
|
196
|
-
#
|
197
|
-
# sub = pubsub.subscription "my-topic-sub", max: 10
|
198
|
-
# msgs = sub.pull
|
199
|
-
# ```
|
200
|
-
#
|
201
|
-
# The request for messages can also block until messages are available.
|
202
|
-
# (See {Google::Cloud::Pubsub::Subscription#wait_for_messages})
|
203
|
-
#
|
204
|
-
# ```ruby
|
205
|
-
# require "google/cloud"
|
206
|
-
#
|
207
|
-
# gcloud = Google::Cloud.new
|
208
|
-
# pubsub = gcloud.pubsub
|
209
|
-
#
|
210
|
-
# sub = pubsub.subscription "my-topic-sub"
|
211
|
-
# msgs = sub.wait_for_messages
|
212
|
-
# ```
|
213
|
-
#
|
214
|
-
# ## Acknowledging a Message
|
215
|
-
#
|
216
|
-
# Messages that are received can be acknowledged in Pub/Sub, marking the
|
217
|
-
# message to be removed so it cannot be pulled again.
|
218
|
-
#
|
219
|
-
# A Message that can be acknowledged is called a ReceivedMessage.
|
220
|
-
# ReceivedMessages can be acknowledged one at a time:
|
221
|
-
# (See {Google::Cloud::Pubsub::ReceivedMessage#acknowledge!})
|
222
|
-
#
|
223
|
-
# ```ruby
|
224
|
-
# require "google/cloud"
|
225
|
-
#
|
226
|
-
# gcloud = Google::Cloud.new
|
227
|
-
# pubsub = gcloud.pubsub
|
228
|
-
#
|
229
|
-
# sub = pubsub.subscription "my-topic-sub"
|
230
|
-
# sub.pull.each { |msg| msg.acknowledge! }
|
231
|
-
# ```
|
232
|
-
#
|
233
|
-
# Or, multiple messages can be acknowledged in a single API call:
|
234
|
-
# (See {Google::Cloud::Pubsub::Subscription#acknowledge})
|
235
|
-
#
|
236
|
-
# ```ruby
|
237
|
-
# require "google/cloud"
|
238
|
-
#
|
239
|
-
# gcloud = Google::Cloud.new
|
240
|
-
# pubsub = gcloud.pubsub
|
241
|
-
#
|
242
|
-
# sub = pubsub.subscription "my-topic-sub"
|
243
|
-
# received_messages = sub.pull
|
244
|
-
# sub.acknowledge received_messages
|
245
|
-
# ```
|
246
|
-
#
|
247
|
-
# ## Modifying a Deadline
|
248
|
-
#
|
249
|
-
# A message must be acknowledged after it is pulled, or Pub/Sub will mark
|
250
|
-
# the message for redelivery. The message acknowledgement deadline can
|
251
|
-
# delayed if more time is needed. This will allow more time to process the
|
252
|
-
# message before the message is marked for redelivery. (See
|
253
|
-
# {Google::Cloud::Pubsub::ReceivedMessage#delay!})
|
254
|
-
#
|
255
|
-
# ```ruby
|
256
|
-
# require "google/cloud"
|
257
|
-
#
|
258
|
-
# gcloud = Google::Cloud.new
|
259
|
-
# pubsub = gcloud.pubsub
|
260
|
-
#
|
261
|
-
# sub = pubsub.subscription "my-topic-sub"
|
262
|
-
# received_message = sub.pull.first
|
263
|
-
# if received_message
|
264
|
-
# puts received_message.message.data
|
265
|
-
# # Delay for 2 minutes
|
266
|
-
# received_message.delay! 120
|
267
|
-
# end
|
268
|
-
# ```
|
269
|
-
#
|
270
|
-
# The message can also be made available for immediate redelivery:
|
271
|
-
#
|
272
|
-
# ```ruby
|
273
|
-
# require "google/cloud"
|
274
|
-
#
|
275
|
-
# gcloud = Google::Cloud.new
|
276
|
-
# pubsub = gcloud.pubsub
|
277
|
-
#
|
278
|
-
# sub = pubsub.subscription "my-topic-sub"
|
279
|
-
# received_message = sub.pull.first
|
280
|
-
# if received_message
|
281
|
-
# puts received_message.message.data
|
282
|
-
# # Mark for redelivery by setting the deadline to now
|
283
|
-
# received_message.delay! 0
|
284
|
-
# end
|
285
|
-
# ```
|
286
|
-
#
|
287
|
-
# Multiple messages can be delayed or made available for immediate
|
288
|
-
# redelivery: (See {Google::Cloud::Pubsub::Subscription#delay})
|
289
|
-
#
|
290
|
-
# ```ruby
|
291
|
-
# require "google/cloud"
|
292
|
-
#
|
293
|
-
# gcloud = Google::Cloud.new
|
294
|
-
# pubsub = gcloud.pubsub
|
295
|
-
#
|
296
|
-
# sub = pubsub.subscription "my-topic-sub"
|
297
|
-
# received_messages = sub.pull
|
298
|
-
# sub.delay 120, received_messages
|
299
|
-
# ```
|
300
|
-
#
|
301
|
-
# ## Listening for Messages
|
302
|
-
#
|
303
|
-
# Long running workers are easy to create with `listen`, which runs an
|
304
|
-
# infinitely blocking loop to process messages as they are received. (See
|
305
|
-
# {Google::Cloud::Pubsub::Subscription#listen})
|
306
|
-
#
|
307
|
-
# ```ruby
|
308
|
-
# require "google/cloud"
|
309
|
-
#
|
310
|
-
# gcloud = Google::Cloud.new
|
311
|
-
# pubsub = gcloud.pubsub
|
312
|
-
#
|
313
|
-
# sub = pubsub.subscription "my-topic-sub"
|
314
|
-
# sub.listen do |msg|
|
315
|
-
# # process msg
|
316
|
-
# end
|
317
|
-
# ```
|
318
|
-
#
|
319
|
-
# Messages are retrieved in batches for efficiency. The number of messages
|
320
|
-
# pulled per batch can be limited with the `max` option:
|
321
|
-
#
|
322
|
-
# ```ruby
|
323
|
-
# require "google/cloud"
|
324
|
-
#
|
325
|
-
# gcloud = Google::Cloud.new
|
326
|
-
# pubsub = gcloud.pubsub
|
327
|
-
#
|
328
|
-
# sub = pubsub.subscription "my-topic-sub"
|
329
|
-
# sub.listen max: 20 do |msg|
|
330
|
-
# # process msg
|
331
|
-
# end
|
332
|
-
# ```
|
333
|
-
#
|
334
|
-
# When processing time and the acknowledgement deadline are a concern,
|
335
|
-
# messages can be automatically acknowledged as they are pulled with the
|
336
|
-
# `autoack` option:
|
337
|
-
#
|
338
|
-
# ```ruby
|
339
|
-
# require "google/cloud"
|
340
|
-
#
|
341
|
-
# gcloud = Google::Cloud.new
|
342
|
-
# pubsub = gcloud.pubsub
|
343
|
-
#
|
344
|
-
# sub = pubsub.subscription "my-topic-sub"
|
345
|
-
# sub.listen autoack: true do |msg|
|
346
|
-
# # process msg
|
347
|
-
# end
|
348
|
-
# ```
|
349
|
-
#
|
350
|
-
# ## Configuring retries and timeout
|
351
|
-
#
|
352
|
-
# You can configure how many times API requests may be automatically
|
353
|
-
# retried. When an API request fails, the response will be inspected to see
|
354
|
-
# if the request meets criteria indicating that it may succeed on retry,
|
355
|
-
# such as `500` and `503` status codes or a specific internal error code
|
356
|
-
# such as `rateLimitExceeded`. If it meets the criteria, the request will be
|
357
|
-
# retried after a delay. If another error occurs, the delay will be
|
358
|
-
# increased before a subsequent attempt, until the `retries` limit is
|
359
|
-
# reached.
|
360
|
-
#
|
361
|
-
# You can also set the request `timeout` value in seconds.
|
362
|
-
#
|
363
|
-
# ```ruby
|
364
|
-
# require "google/cloud"
|
365
|
-
#
|
366
|
-
# gcloud = Google::Cloud.new
|
367
|
-
# pubsub = gcloud.pubsub retries: 10, timeout: 120
|
368
|
-
# ```
|
369
|
-
#
|
370
|
-
# See the [Pub/Sub error codes](https://cloud.google.com/pubsub/error-codes)
|
371
|
-
# for a list of error conditions.
|
372
|
-
#
|
373
|
-
# ## Working Across Projects
|
374
|
-
#
|
375
|
-
# All calls to the Pub/Sub service use the same project and credentials
|
376
|
-
# provided to the {Google::Cloud#pubsub} method. However, it is common to
|
377
|
-
# reference topics or subscriptions in other projects, which can be achieved
|
378
|
-
# by using the `project` option. The main credentials must have permissions
|
379
|
-
# to the topics and subscriptions in other projects.
|
380
|
-
#
|
381
|
-
# ```ruby
|
382
|
-
# require "google/cloud"
|
383
|
-
#
|
384
|
-
# gcloud = Google::Cloud.new # my-project-id
|
385
|
-
# pubsub = gcloud.pubsub
|
386
|
-
#
|
387
|
-
# # Get a topic in the current project
|
388
|
-
# my_topic = pubsub.topic "my-topic"
|
389
|
-
# my_topic.name #=> "projects/my-project-id/topics/my-topic"
|
390
|
-
# # Get a topic in another project
|
391
|
-
# other_topic = pubsub.topic "other-topic", project: "other-project-id"
|
392
|
-
# other_topic.name #=> "projects/other-project-id/topics/other-topic"
|
393
|
-
# ```
|
394
|
-
#
|
395
|
-
# It is possible to create a subscription in the current project that pulls
|
396
|
-
# from a topic in another project:
|
397
|
-
#
|
398
|
-
# ```ruby
|
399
|
-
# require "google/cloud"
|
400
|
-
#
|
401
|
-
# gcloud = Google::Cloud.new # my-project-id
|
402
|
-
# pubsub = gcloud.pubsub
|
403
|
-
#
|
404
|
-
# # Get a topic in another project
|
405
|
-
# topic = pubsub.topic "other-topic", project: "other-project-id"
|
406
|
-
# # Create a subscription in the current project that pulls from
|
407
|
-
# # the topic in another project
|
408
|
-
# sub = topic.subscribe "my-sub"
|
409
|
-
# sub.name #=> "projects/my-project-id/subscriptions/my-sub"
|
410
|
-
# sub.topic.name #=> "projects/other-project-id/topics/other-topic"
|
411
|
-
# ```
|
412
|
-
#
|
413
|
-
# ## Using the Google Cloud Pub/Sub Emulator
|
414
|
-
#
|
415
|
-
# To develop and test your application locally, you can use the [Google
|
416
|
-
# Cloud Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which
|
417
|
-
# provides [local
|
418
|
-
# emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/)
|
419
|
-
# of the production Google Cloud Pub/Sub environment. You can start the
|
420
|
-
# Google Cloud Pub/Sub emulator using the `gcloud` command-line tool.
|
421
|
-
#
|
422
|
-
# To configure your ruby code to use the emulator, set the
|
423
|
-
# `PUBSUB_EMULATOR_HOST` environment variable to the host and port where the
|
424
|
-
# emulator is running. The value can be set as an environment variable in
|
425
|
-
# the shell running the ruby code, or can be set directly in the ruby code
|
426
|
-
# as shown below.
|
427
|
-
#
|
428
|
-
# ```ruby
|
429
|
-
# require "google/cloud"
|
430
|
-
#
|
431
|
-
# # Make Pub/Sub use the emulator
|
432
|
-
# ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
|
433
|
-
#
|
434
|
-
# gcloud = Google::Cloud.new "emulator-project-id"
|
435
|
-
# pubsub = gcloud.pubsub
|
436
|
-
#
|
437
|
-
# # Get a topic in the current project
|
438
|
-
# my_topic = pubsub.new_topic "my-topic"
|
439
|
-
# my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
|
440
|
-
# ```
|
441
|
-
#
|
442
|
-
module Pubsub
|
35
|
+
module PubSub
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
37
|
+
|
38
|
+
##
|
39
|
+
# Creates a new object for connecting to the Pub/Sub service.
|
40
|
+
# Each call creates a new connection.
|
41
|
+
#
|
42
|
+
# For more information on connecting to Google Cloud see the
|
43
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
44
|
+
#
|
45
|
+
# @param [String] project_id Project identifier for the Pub/Sub service
|
46
|
+
# you are connecting to. If not present, the default project for the
|
47
|
+
# credentials is used.
|
48
|
+
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
49
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
50
|
+
# Google::Auth::Credentials object. (See {PubSub::Credentials})
|
51
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
52
|
+
# the set of resources and operations that the connection can access.
|
53
|
+
# See [Using OAuth 2.0 to Access Google
|
54
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
55
|
+
#
|
56
|
+
# The default scope is:
|
57
|
+
#
|
58
|
+
# * `https://www.googleapis.com/auth/pubsub`
|
59
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
60
|
+
# @param [String] endpoint Override of the endpoint host name. Optional.
|
61
|
+
# If the param is nil, uses the default endpoint.
|
62
|
+
# @param [String] emulator_host Pub/Sub emulator host. Optional.
|
63
|
+
# If the param is nil, uses the value of the `emulator_host` config.
|
64
|
+
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
65
|
+
# @param [String] keyfile Alias for the `credentials` argument.
|
66
|
+
# Deprecated.
|
67
|
+
#
|
68
|
+
# @return [Google::Cloud::PubSub::Project]
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# require "google/cloud/pubsub"
|
72
|
+
#
|
73
|
+
# pubsub = Google::Cloud::PubSub.new
|
74
|
+
#
|
75
|
+
# topic = pubsub.topic "my-topic"
|
76
|
+
# topic.publish "task completed"
|
77
|
+
#
|
78
|
+
def self.new project_id: nil,
|
79
|
+
credentials: nil,
|
80
|
+
scope: nil,
|
81
|
+
timeout: nil,
|
82
|
+
endpoint: nil,
|
83
|
+
emulator_host: nil,
|
84
|
+
project: nil,
|
85
|
+
keyfile: nil
|
86
|
+
project_id ||= (project || default_project_id)
|
87
|
+
scope ||= configure.scope
|
88
|
+
timeout ||= configure.timeout
|
89
|
+
endpoint ||= configure.endpoint
|
90
|
+
emulator_host ||= configure.emulator_host
|
91
|
+
|
92
|
+
if emulator_host
|
93
|
+
project_id = project_id.to_s # Always cast to a string
|
94
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
95
|
+
|
96
|
+
service = PubSub::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
|
97
|
+
return PubSub::Project.new service
|
98
|
+
end
|
99
|
+
|
100
|
+
credentials ||= (keyfile || default_credentials(scope: scope))
|
101
|
+
unless credentials.is_a? Google::Auth::Credentials
|
102
|
+
credentials = PubSub::Credentials.new credentials, scope: scope
|
103
|
+
end
|
104
|
+
|
105
|
+
project_id ||= credentials.project_id if credentials.respond_to? :project_id
|
106
|
+
project_id = project_id.to_s # Always cast to a string
|
107
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
108
|
+
|
109
|
+
service = PubSub::Service.new project_id, credentials, host: endpoint, timeout: timeout
|
110
|
+
PubSub::Project.new service
|
111
|
+
end
|
112
|
+
|
113
|
+
# rubocop:enable Metrics/AbcSize
|
114
|
+
|
115
|
+
##
|
116
|
+
# Configure the Google Cloud PubSub library.
|
117
|
+
#
|
118
|
+
# The following PubSub configuration parameters are supported:
|
119
|
+
#
|
120
|
+
# * `project_id` - (String) Identifier for a PubSub project. (The
|
121
|
+
# parameter `project` is considered deprecated, but may also be used.)
|
122
|
+
# * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
|
123
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
124
|
+
# Google::Auth::Credentials object. (See {PubSub::Credentials}) (The
|
125
|
+
# parameter `keyfile` is considered deprecated, but may also be used.)
|
126
|
+
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
127
|
+
# the set of resources and operations that the connection can access.
|
128
|
+
# * `retries` - (Integer) Number of times to retry requests on server
|
129
|
+
# error.
|
130
|
+
# * `timeout` - (Integer) Default timeout to use in requests.
|
131
|
+
# * `endpoint` - (String) Override of the endpoint host name, or `nil`
|
132
|
+
# to use the default endpoint.
|
133
|
+
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
134
|
+
# `ENV["PUBSUB_EMULATOR_HOST"]`
|
135
|
+
# * `on_error` - (Proc) A Proc to be run when an error is encountered
|
136
|
+
# on a background thread. The Proc must take the error object as the
|
137
|
+
# single argument. (See {Subscriber.on_error}.)
|
138
|
+
#
|
139
|
+
# @return [Google::Cloud::Config] The configuration object the
|
140
|
+
# Google::Cloud::PubSub library uses.
|
141
|
+
#
|
142
|
+
def self.configure
|
143
|
+
yield Google::Cloud.configure.pubsub if block_given?
|
144
|
+
|
145
|
+
Google::Cloud.configure.pubsub
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# @private Default project.
|
150
|
+
def self.default_project_id
|
151
|
+
Google::Cloud.configure.pubsub.project_id ||
|
152
|
+
Google::Cloud.configure.project_id ||
|
153
|
+
Google::Cloud.env.project_id
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# @private Default credentials.
|
158
|
+
def self.default_credentials scope: nil
|
159
|
+
Google::Cloud.configure.pubsub.credentials ||
|
160
|
+
Google::Cloud.configure.credentials ||
|
161
|
+
PubSub::Credentials.default(scope: scope)
|
162
|
+
end
|
443
163
|
end
|
164
|
+
|
165
|
+
## Legacy veneer namespace
|
166
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
444
167
|
end
|
168
|
+
## Legacy generated client namespace
|
169
|
+
Pubsub = Cloud::PubSub unless const_defined? :Pubsub
|
445
170
|
end
|