google-cloud-pubsub 0.26.0 → 2.6.1
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 +5 -5
- data/.yardopts +12 -2
- 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 +2 -2
- 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 +80 -17
- data/lib/google/cloud/pubsub/policy.rb +17 -14
- data/lib/google/cloud/pubsub/project.rb +364 -250
- data/lib/google/cloud/pubsub/publish_result.rb +103 -0
- data/lib/google/cloud/pubsub/received_message.rb +162 -24
- 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 +281 -265
- data/lib/google/cloud/pubsub/snapshot/list.rb +21 -21
- data/lib/google/cloud/pubsub/snapshot.rb +55 -15
- 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 +28 -28
- data/lib/google/cloud/pubsub/subscription/push_config.rb +268 -0
- data/lib/google/cloud/pubsub/subscription.rb +900 -172
- data/lib/google/cloud/pubsub/topic/list.rb +21 -21
- data/lib/google/cloud/pubsub/topic.rb +674 -95
- data/lib/google/cloud/pubsub/version.rb +6 -4
- data/lib/google/cloud/pubsub.rb +104 -439
- data/lib/google-cloud-pubsub.rb +60 -29
- metadata +88 -50
- data/README.md +0 -69
- data/lib/google/cloud/pubsub/topic/publisher.rb +0 -86
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -77
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -223
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -81
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -503
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -605
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -96
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1104
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -127
- data/lib/google/cloud/pubsub/v1.rb +0 -17
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -187
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -159
@@ -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,422 +30,24 @@ 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
|
-
# pubsub = Google::Cloud::Pubsub.new
|
41
|
-
#
|
42
|
-
# topic = pubsub.topic "my-topic"
|
43
|
-
# topic.publish "task completed"
|
44
|
-
# ```
|
45
|
-
#
|
46
|
-
# To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
|
47
|
-
# ](https://cloud.google.com/pubsub/overview).
|
48
|
-
#
|
49
|
-
# ## Retrieving Topics
|
50
|
-
#
|
51
|
-
# A Topic is a named resource to which messages are sent by publishers.
|
52
|
-
# A Topic is found by its name. (See {Google::Cloud::Pubsub::Project#topic})
|
53
|
-
#
|
54
|
-
# ```ruby
|
55
|
-
# require "google/cloud/pubsub"
|
56
|
-
#
|
57
|
-
# pubsub = Google::Cloud::Pubsub.new
|
58
|
-
# topic = pubsub.topic "my-topic"
|
59
|
-
# ```
|
60
|
-
#
|
61
|
-
# ## Creating a Topic
|
62
|
-
#
|
63
|
-
# A Topic is created from a Project. (See
|
64
|
-
# {Google::Cloud::Pubsub::Project#create_topic})
|
65
|
-
#
|
66
|
-
# ```ruby
|
67
|
-
# require "google/cloud/pubsub"
|
68
|
-
#
|
69
|
-
# pubsub = Google::Cloud::Pubsub.new
|
70
|
-
# topic = pubsub.create_topic "my-topic"
|
71
|
-
# ```
|
72
|
-
#
|
73
|
-
# ## Retrieving Subscriptions
|
74
|
-
#
|
75
|
-
# A Subscription is a named resource representing the stream of messages
|
76
|
-
# from a single, specific Topic, to be delivered to the subscribing
|
77
|
-
# application. A Subscription is found by its name. (See
|
78
|
-
# {Google::Cloud::Pubsub::Topic#subscription})
|
79
|
-
#
|
80
|
-
# ```ruby
|
81
|
-
# require "google/cloud/pubsub"
|
82
|
-
#
|
83
|
-
# pubsub = Google::Cloud::Pubsub.new
|
84
|
-
#
|
85
|
-
# topic = pubsub.topic "my-topic"
|
86
|
-
# subscription = topic.subscription "my-topic-subscription"
|
87
|
-
# puts subscription.name
|
88
|
-
# ```
|
89
|
-
#
|
90
|
-
# ## Creating a Subscription
|
91
|
-
#
|
92
|
-
# A Subscription is created from a Topic. (See
|
93
|
-
# {Google::Cloud::Pubsub::Topic#subscribe} and
|
94
|
-
# {Google::Cloud::Pubsub::Project#subscribe})
|
95
|
-
#
|
96
|
-
# ```ruby
|
97
|
-
# require "google/cloud/pubsub"
|
98
|
-
#
|
99
|
-
# pubsub = Google::Cloud::Pubsub.new
|
100
|
-
#
|
101
|
-
# topic = pubsub.topic "my-topic"
|
102
|
-
# sub = topic.subscribe "my-topic-sub"
|
103
|
-
# puts sub.name # => "my-topic-sub"
|
104
|
-
# ```
|
105
|
-
#
|
106
|
-
# The subscription can be created that specifies the number of seconds to
|
107
|
-
# wait to be acknowledged as well as an endpoint URL to push the messages
|
108
|
-
# to:
|
109
|
-
#
|
110
|
-
# ```ruby
|
111
|
-
# require "google/cloud/pubsub"
|
112
|
-
#
|
113
|
-
# pubsub = Google::Cloud::Pubsub.new
|
114
|
-
#
|
115
|
-
# topic = pubsub.topic "my-topic"
|
116
|
-
# sub = topic.subscribe "my-topic-sub",
|
117
|
-
# deadline: 120,
|
118
|
-
# endpoint: "https://example.com/push"
|
119
|
-
# ```
|
120
|
-
#
|
121
|
-
# ## Publishing Messages
|
122
|
-
#
|
123
|
-
# Messages are published to a topic. Any message published to a topic
|
124
|
-
# without a subscription will be lost. Ensure the topic has a subscription
|
125
|
-
# before publishing. (See {Google::Cloud::Pubsub::Topic#publish} and
|
126
|
-
# {Google::Cloud::Pubsub::Project#publish})
|
127
|
-
#
|
128
|
-
# ```ruby
|
129
|
-
# require "google/cloud/pubsub"
|
130
|
-
#
|
131
|
-
# pubsub = Google::Cloud::Pubsub.new
|
132
|
-
#
|
133
|
-
# topic = pubsub.topic "my-topic"
|
134
|
-
# msg = topic.publish "task completed"
|
135
|
-
# ```
|
136
|
-
#
|
137
|
-
# Messages can also be published with attributes:
|
138
|
-
#
|
139
|
-
# ```ruby
|
140
|
-
# require "google/cloud/pubsub"
|
141
|
-
#
|
142
|
-
# pubsub = Google::Cloud::Pubsub.new
|
143
|
-
#
|
144
|
-
# topic = pubsub.topic "my-topic"
|
145
|
-
# msg = topic.publish "task completed",
|
146
|
-
# foo: :bar,
|
147
|
-
# this: :that
|
148
|
-
# ```
|
149
|
-
#
|
150
|
-
# Multiple messages can be published at the same time by passing a block:
|
151
|
-
#
|
152
|
-
# ```ruby
|
153
|
-
# require "google/cloud/pubsub"
|
154
|
-
#
|
155
|
-
# pubsub = Google::Cloud::Pubsub.new
|
156
|
-
#
|
157
|
-
# topic = pubsub.topic "my-topic"
|
158
|
-
# msgs = topic.publish do |batch|
|
159
|
-
# batch.publish "task 1 completed", foo: :bar
|
160
|
-
# batch.publish "task 2 completed", foo: :baz
|
161
|
-
# batch.publish "task 3 completed", foo: :bif
|
162
|
-
# end
|
163
|
-
# ```
|
164
|
-
#
|
165
|
-
# ## Pulling Messages
|
166
|
-
#
|
167
|
-
# Messages are pulled from a Subscription. (See
|
168
|
-
# {Google::Cloud::Pubsub::Subscription#pull})
|
169
|
-
#
|
170
|
-
# ```ruby
|
171
|
-
# require "google/cloud/pubsub"
|
172
|
-
#
|
173
|
-
# pubsub = Google::Cloud::Pubsub.new
|
174
|
-
#
|
175
|
-
# sub = pubsub.subscription "my-topic-sub"
|
176
|
-
# msgs = sub.pull
|
177
|
-
# ```
|
178
|
-
#
|
179
|
-
# A maximum number of messages returned can also be specified:
|
180
|
-
#
|
181
|
-
# ```ruby
|
182
|
-
# require "google/cloud/pubsub"
|
183
|
-
#
|
184
|
-
# pubsub = Google::Cloud::Pubsub.new
|
185
|
-
#
|
186
|
-
# sub = pubsub.subscription "my-topic-sub", max: 10
|
187
|
-
# msgs = sub.pull
|
188
|
-
# ```
|
189
|
-
#
|
190
|
-
# The request for messages can also block until messages are available.
|
191
|
-
# (See {Google::Cloud::Pubsub::Subscription#wait_for_messages})
|
192
|
-
#
|
193
|
-
# ```ruby
|
194
|
-
# require "google/cloud/pubsub"
|
195
|
-
#
|
196
|
-
# pubsub = Google::Cloud::Pubsub.new
|
197
|
-
#
|
198
|
-
# sub = pubsub.subscription "my-topic-sub"
|
199
|
-
# msgs = sub.wait_for_messages
|
200
|
-
# ```
|
201
|
-
#
|
202
|
-
# ## Acknowledging a Message
|
203
|
-
#
|
204
|
-
# Messages that are received can be acknowledged in Pub/Sub, marking the
|
205
|
-
# message to be removed so it cannot be pulled again.
|
206
|
-
#
|
207
|
-
# A Message that can be acknowledged is called a ReceivedMessage.
|
208
|
-
# ReceivedMessages can be acknowledged one at a time:
|
209
|
-
# (See {Google::Cloud::Pubsub::ReceivedMessage#acknowledge!})
|
210
|
-
#
|
211
|
-
# ```ruby
|
212
|
-
# require "google/cloud/pubsub"
|
213
|
-
#
|
214
|
-
# pubsub = Google::Cloud::Pubsub.new
|
215
|
-
#
|
216
|
-
# sub = pubsub.subscription "my-topic-sub"
|
217
|
-
# sub.pull.each { |msg| msg.acknowledge! }
|
218
|
-
# ```
|
219
|
-
#
|
220
|
-
# Or, multiple messages can be acknowledged in a single API call:
|
221
|
-
# (See {Google::Cloud::Pubsub::Subscription#acknowledge})
|
222
|
-
#
|
223
|
-
# ```ruby
|
224
|
-
# require "google/cloud/pubsub"
|
225
|
-
#
|
226
|
-
# pubsub = Google::Cloud::Pubsub.new
|
227
|
-
#
|
228
|
-
# sub = pubsub.subscription "my-topic-sub"
|
229
|
-
# received_messages = sub.pull
|
230
|
-
# sub.acknowledge received_messages
|
231
|
-
# ```
|
232
|
-
#
|
233
|
-
# ## Modifying a Deadline
|
234
|
-
#
|
235
|
-
# A message must be acknowledged after it is pulled, or Pub/Sub will mark
|
236
|
-
# the message for redelivery. The message acknowledgement deadline can
|
237
|
-
# delayed if more time is needed. This will allow more time to process the
|
238
|
-
# message before the message is marked for redelivery. (See
|
239
|
-
# {Google::Cloud::Pubsub::ReceivedMessage#delay!})
|
240
|
-
#
|
241
|
-
# ```ruby
|
242
|
-
# require "google/cloud/pubsub"
|
243
|
-
#
|
244
|
-
# pubsub = Google::Cloud::Pubsub.new
|
245
|
-
#
|
246
|
-
# sub = pubsub.subscription "my-topic-sub"
|
247
|
-
# received_message = sub.pull.first
|
248
|
-
# if received_message
|
249
|
-
# puts received_message.message.data
|
250
|
-
# # Delay for 2 minutes
|
251
|
-
# received_message.delay! 120
|
252
|
-
# end
|
253
|
-
# ```
|
254
|
-
#
|
255
|
-
# The message can also be made available for immediate redelivery:
|
256
|
-
#
|
257
|
-
# ```ruby
|
258
|
-
# require "google/cloud/pubsub"
|
259
|
-
#
|
260
|
-
# pubsub = Google::Cloud::Pubsub.new
|
261
|
-
#
|
262
|
-
# sub = pubsub.subscription "my-topic-sub"
|
263
|
-
# received_message = sub.pull.first
|
264
|
-
# if received_message
|
265
|
-
# puts received_message.message.data
|
266
|
-
# # Mark for redelivery by setting the deadline to now
|
267
|
-
# received_message.delay! 0
|
268
|
-
# end
|
269
|
-
# ```
|
270
|
-
#
|
271
|
-
# Multiple messages can be delayed or made available for immediate
|
272
|
-
# redelivery: (See {Google::Cloud::Pubsub::Subscription#delay})
|
273
|
-
#
|
274
|
-
# ```ruby
|
275
|
-
# require "google/cloud/pubsub"
|
276
|
-
#
|
277
|
-
# pubsub = Google::Cloud::Pubsub.new
|
278
|
-
#
|
279
|
-
# sub = pubsub.subscription "my-topic-sub"
|
280
|
-
# received_messages = sub.pull
|
281
|
-
# sub.delay 120, received_messages
|
282
|
-
# ```
|
283
|
-
#
|
284
|
-
# ## Creating a snapshot and using seek
|
285
|
-
#
|
286
|
-
# You can create a snapshot to retain the existing backlog on a
|
287
|
-
# subscription. The snapshot will hold the messages in the subscription's
|
288
|
-
# backlog that are unacknowledged upon the successful completion of the
|
289
|
-
# `create_snapshot` operation.
|
290
|
-
#
|
291
|
-
# Later, you can use `seek` to reset the subscription's backlog to the
|
292
|
-
# snapshot.
|
293
|
-
#
|
294
|
-
# (See {Google::Cloud::Pubsub::Subscription#create_snapshot} and
|
295
|
-
# {Google::Cloud::Pubsub::Subscription#seek})
|
296
|
-
#
|
297
|
-
# ```ruby
|
298
|
-
# require "google/cloud/pubsub"
|
299
|
-
#
|
300
|
-
# pubsub = Google::Cloud::Pubsub.new
|
301
|
-
#
|
302
|
-
# sub = pubsub.subscription "my-topic-sub"
|
303
|
-
#
|
304
|
-
# snapshot = sub.create_snapshot
|
305
|
-
#
|
306
|
-
# messages = sub.pull
|
307
|
-
# sub.acknowledge messages
|
308
|
-
#
|
309
|
-
# sub.seek snapshot
|
310
|
-
# ```
|
311
|
-
#
|
312
|
-
# ## Listening for Messages
|
313
|
-
#
|
314
|
-
# Long running workers are easy to create with `listen`, which runs an
|
315
|
-
# infinitely blocking loop to process messages as they are received. (See
|
316
|
-
# {Google::Cloud::Pubsub::Subscription#listen})
|
317
|
-
#
|
318
|
-
# ```ruby
|
319
|
-
# require "google/cloud/pubsub"
|
320
|
-
#
|
321
|
-
# pubsub = Google::Cloud::Pubsub.new
|
322
|
-
#
|
323
|
-
# sub = pubsub.subscription "my-topic-sub"
|
324
|
-
# sub.listen do |msg|
|
325
|
-
# # process msg
|
326
|
-
# end
|
327
|
-
# ```
|
328
|
-
#
|
329
|
-
# Messages are retrieved in batches for efficiency. The number of messages
|
330
|
-
# pulled per batch can be limited with the `max` option:
|
331
|
-
#
|
332
|
-
# ```ruby
|
333
|
-
# require "google/cloud/pubsub"
|
334
|
-
#
|
335
|
-
# pubsub = Google::Cloud::Pubsub.new
|
336
|
-
#
|
337
|
-
# sub = pubsub.subscription "my-topic-sub"
|
338
|
-
# sub.listen max: 20 do |msg|
|
339
|
-
# # process msg
|
340
|
-
# end
|
341
|
-
# ```
|
342
|
-
#
|
343
|
-
# When processing time and the acknowledgement deadline are a concern,
|
344
|
-
# messages can be automatically acknowledged as they are pulled with the
|
345
|
-
# `autoack` option:
|
346
|
-
#
|
347
|
-
# ```ruby
|
348
|
-
# require "google/cloud/pubsub"
|
349
|
-
#
|
350
|
-
# pubsub = Google::Cloud::Pubsub.new
|
351
|
-
#
|
352
|
-
# sub = pubsub.subscription "my-topic-sub"
|
353
|
-
# sub.listen autoack: true do |msg|
|
354
|
-
# # process msg
|
355
|
-
# end
|
356
|
-
# ```
|
357
|
-
#
|
358
|
-
# ## Configuring timeout
|
359
|
-
#
|
360
|
-
# You can configure the request `timeout` value in seconds.
|
361
|
-
#
|
362
|
-
# ```ruby
|
363
|
-
# require "google/cloud/pubsub"
|
364
|
-
#
|
365
|
-
# pubsub = Google::Cloud::Pubsub.new timeout: 120
|
366
|
-
# ```
|
367
|
-
#
|
368
|
-
# ## Working Across Projects
|
369
|
-
#
|
370
|
-
# All calls to the Pub/Sub service use the same project and credentials
|
371
|
-
# provided to the {Google::Cloud#pubsub} method. However, it is common to
|
372
|
-
# reference topics or subscriptions in other projects, which can be achieved
|
373
|
-
# by using the `project` option. The main credentials must have permissions
|
374
|
-
# to the topics and subscriptions in other projects.
|
375
|
-
#
|
376
|
-
# ```ruby
|
377
|
-
# require "google/cloud/pubsub"
|
378
|
-
#
|
379
|
-
# pubsub = Google::Cloud::Pubsub.new # my-project-id
|
380
|
-
#
|
381
|
-
# # Get a topic in the current project
|
382
|
-
# my_topic = pubsub.topic "my-topic"
|
383
|
-
# my_topic.name #=> "projects/my-project-id/topics/my-topic"
|
384
|
-
# # Get a topic in another project
|
385
|
-
# other_topic = pubsub.topic "other-topic", project: "other-project-id"
|
386
|
-
# other_topic.name #=> "projects/other-project-id/topics/other-topic"
|
387
|
-
# ```
|
388
|
-
#
|
389
|
-
# It is possible to create a subscription in the current project that pulls
|
390
|
-
# from a topic in another project:
|
391
|
-
#
|
392
|
-
# ```ruby
|
393
|
-
# require "google/cloud/pubsub"
|
394
|
-
#
|
395
|
-
# pubsub = Google::Cloud::Pubsub.new # my-project-id
|
396
|
-
#
|
397
|
-
# # Get a topic in another project
|
398
|
-
# topic = pubsub.topic "other-topic", project: "other-project-id"
|
399
|
-
# # Create a subscription in the current project that pulls from
|
400
|
-
# # the topic in another project
|
401
|
-
# sub = topic.subscribe "my-sub"
|
402
|
-
# sub.name #=> "projects/my-project-id/subscriptions/my-sub"
|
403
|
-
# sub.topic.name #=> "projects/other-project-id/topics/other-topic"
|
404
|
-
# ```
|
405
|
-
#
|
406
|
-
# ## Using the Google Cloud Pub/Sub Emulator
|
407
|
-
#
|
408
|
-
# To develop and test your application locally, you can use the [Google
|
409
|
-
# Cloud Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which
|
410
|
-
# provides [local
|
411
|
-
# emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/)
|
412
|
-
# of the production Google Cloud Pub/Sub environment. You can start the
|
413
|
-
# Google Cloud Pub/Sub emulator using the `gcloud` command-line tool.
|
414
|
-
#
|
415
|
-
# To configure your ruby code to use the emulator, set the
|
416
|
-
# `PUBSUB_EMULATOR_HOST` environment variable to the host and port where the
|
417
|
-
# emulator is running. The value can be set as an environment variable in
|
418
|
-
# the shell running the ruby code, or can be set directly in the ruby code
|
419
|
-
# as shown below.
|
420
|
-
#
|
421
|
-
# ```ruby
|
422
|
-
# require "google/cloud/pubsub"
|
423
|
-
#
|
424
|
-
# # Make Pub/Sub use the emulator
|
425
|
-
# ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
|
426
|
-
#
|
427
|
-
# pubsub = Google::Cloud::Pubsub.new "emulator-project-id"
|
428
|
-
#
|
429
|
-
# # Get a topic in the current project
|
430
|
-
# my_topic = pubsub.new_topic "my-topic"
|
431
|
-
# my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
|
432
|
-
# ```
|
433
|
-
#
|
434
|
-
module Pubsub
|
35
|
+
module PubSub
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
37
|
+
|
435
38
|
##
|
436
39
|
# Creates a new object for connecting to the Pub/Sub service.
|
437
40
|
# Each call creates a new connection.
|
438
41
|
#
|
439
42
|
# For more information on connecting to Google Cloud see the
|
440
|
-
#
|
441
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
43
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
442
44
|
#
|
443
|
-
# @param [String]
|
444
|
-
# are connecting to.
|
445
|
-
#
|
446
|
-
#
|
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})
|
447
51
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
448
52
|
# the set of resources and operations that the connection can access.
|
449
53
|
# See [Using OAuth 2.0 to Access Google
|
@@ -453,53 +57,114 @@ module Google
|
|
453
57
|
#
|
454
58
|
# * `https://www.googleapis.com/auth/pubsub`
|
455
59
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
456
|
-
# @param [
|
457
|
-
#
|
60
|
+
# @param [String] endpoint Override of the endpoint host name. Optional.
|
61
|
+
# If the param is nil, uses the default endpoint.
|
458
62
|
# @param [String] emulator_host Pub/Sub emulator host. Optional.
|
459
|
-
# If the param is nil,
|
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.
|
460
67
|
#
|
461
|
-
# @return [Google::Cloud::
|
68
|
+
# @return [Google::Cloud::PubSub::Project]
|
462
69
|
#
|
463
70
|
# @example
|
464
71
|
# require "google/cloud/pubsub"
|
465
72
|
#
|
466
|
-
# pubsub = Google::Cloud.
|
73
|
+
# pubsub = Google::Cloud::PubSub.new
|
467
74
|
#
|
468
75
|
# topic = pubsub.topic "my-topic"
|
469
76
|
# topic.publish "task completed"
|
470
77
|
#
|
471
|
-
def self.new
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
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
|
476
91
|
|
477
|
-
emulator_host ||= ENV["PUBSUB_EMULATOR_HOST"]
|
478
92
|
if emulator_host
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
return
|
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
|
484
98
|
end
|
485
99
|
|
486
|
-
credentials
|
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?
|
487
108
|
|
488
|
-
|
489
|
-
|
490
|
-
project, credentials, timeout: timeout,
|
491
|
-
client_config: client_config))
|
109
|
+
service = PubSub::Service.new project_id, credentials, host: endpoint, timeout: timeout
|
110
|
+
PubSub::Project.new service
|
492
111
|
end
|
493
112
|
|
113
|
+
# rubocop:enable Metrics/AbcSize
|
114
|
+
|
494
115
|
##
|
495
|
-
#
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
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)
|
502
162
|
end
|
503
163
|
end
|
164
|
+
|
165
|
+
## Legacy veneer namespace
|
166
|
+
Pubsub = PubSub unless const_defined? :Pubsub
|
504
167
|
end
|
168
|
+
## Legacy generated client namespace
|
169
|
+
Pubsub = Cloud::PubSub unless const_defined? :Pubsub
|
505
170
|
end
|