google-cloud-pubsub 2.22.0 → 3.2.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 +4 -4
- data/AUTHENTICATION.md +12 -1
- data/CHANGELOG.md +69 -0
- data/OVERVIEW.md +189 -145
- data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
- data/lib/google/cloud/pubsub/async_publisher.rb +20 -19
- data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
- data/lib/google/cloud/pubsub/errors.rb +3 -3
- data/lib/google/cloud/pubsub/internal_logger.rb +76 -0
- data/lib/google/cloud/pubsub/message.rb +8 -8
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +13 -10
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +61 -18
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +29 -9
- data/lib/google/cloud/pubsub/message_listener.rb +414 -0
- data/lib/google/cloud/pubsub/project.rb +102 -530
- data/lib/google/cloud/pubsub/publisher.rb +424 -0
- data/lib/google/cloud/pubsub/received_message.rb +50 -45
- data/lib/google/cloud/pubsub/service.rb +34 -385
- data/lib/google/cloud/pubsub/subscriber.rb +442 -279
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/cloud/pubsub.rb +37 -19
- data/lib/google-cloud-pubsub.rb +27 -8
- metadata +19 -26
- data/lib/google/cloud/pubsub/policy.rb +0 -188
- data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
- data/lib/google/cloud/pubsub/schema/list.rb +0 -180
- data/lib/google/cloud/pubsub/schema.rb +0 -378
- data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
- data/lib/google/cloud/pubsub/snapshot.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
- data/lib/google/cloud/pubsub/subscription.rb +0 -1467
- data/lib/google/cloud/pubsub/topic/list.rb +0 -171
- data/lib/google/cloud/pubsub/topic.rb +0 -1100
|
@@ -16,10 +16,8 @@
|
|
|
16
16
|
require "google/cloud/errors"
|
|
17
17
|
require "google/cloud/pubsub/service"
|
|
18
18
|
require "google/cloud/pubsub/credentials"
|
|
19
|
-
require "google/cloud/pubsub/
|
|
20
|
-
require "google/cloud/pubsub/
|
|
21
|
-
require "google/cloud/pubsub/schema"
|
|
22
|
-
require "google/cloud/pubsub/snapshot"
|
|
19
|
+
require "google/cloud/pubsub/publisher"
|
|
20
|
+
require "google/cloud/pubsub/subscriber"
|
|
23
21
|
|
|
24
22
|
module Google
|
|
25
23
|
module Cloud
|
|
@@ -31,10 +29,13 @@ module Google
|
|
|
31
29
|
# # Project
|
|
32
30
|
#
|
|
33
31
|
# Represents the project that pubsub messages are pushed to and pulled
|
|
34
|
-
# from.
|
|
35
|
-
#
|
|
32
|
+
# from.
|
|
33
|
+
#
|
|
34
|
+
# {Google::Cloud::PubSub::V1::Topic} is a named resource to which
|
|
35
|
+
# messages are sent by using {Publisher}.
|
|
36
|
+
# {Google::Cloud::PubSub::V1::Subscription} is a named resource representing the stream
|
|
36
37
|
# of messages from a single, specific topic, to be delivered to the
|
|
37
|
-
# subscribing application. {Message} is a combination of data and
|
|
38
|
+
# subscribing application via {Subscriber}. {Message} is a combination of data and
|
|
38
39
|
# attributes that a publisher sends to a topic and is eventually delivered
|
|
39
40
|
# to subscribers.
|
|
40
41
|
#
|
|
@@ -45,8 +46,8 @@ module Google
|
|
|
45
46
|
#
|
|
46
47
|
# pubsub = Google::Cloud::PubSub.new
|
|
47
48
|
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
49
|
+
# publisher = pubsub.publisher "my-topic"
|
|
50
|
+
# publisher.publish "task completed"
|
|
50
51
|
#
|
|
51
52
|
class Project
|
|
52
53
|
##
|
|
@@ -86,574 +87,145 @@ module Google
|
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
##
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
# @param [String] topic_name Name of a topic. The value can be a simple
|
|
92
|
-
# topic ID (relative name), in which case the current project ID will
|
|
93
|
-
# be supplied, or a fully-qualified topic name in the form
|
|
94
|
-
# `projects/{project_id}/topics/{topic_id}`.
|
|
95
|
-
# @param [String] project If the topic belongs to a project other than
|
|
96
|
-
# the one currently connected to, the alternate project ID can be
|
|
97
|
-
# specified here. Optional. Not used if a fully-qualified topic name
|
|
98
|
-
# is provided for `topic_name`.
|
|
99
|
-
# @param [Boolean] skip_lookup Optionally create a {Topic} object
|
|
100
|
-
# without verifying the topic resource exists on the Pub/Sub service.
|
|
101
|
-
# Calls made on this object will raise errors if the topic resource
|
|
102
|
-
# does not exist. Default is `false`. Optional.
|
|
103
|
-
# @param [Hash] async A hash of values to configure the topic's
|
|
104
|
-
# {AsyncPublisher} that is created when {Topic#publish_async}
|
|
105
|
-
# is called. Optional.
|
|
106
|
-
#
|
|
107
|
-
# Hash keys and values may include the following:
|
|
108
|
-
#
|
|
109
|
-
# * `:max_bytes` (Integer) The maximum size of messages to be collected before the batch is published. Default
|
|
110
|
-
# is 1,000,000 (1MB).
|
|
111
|
-
# * `:max_messages` (Integer) The maximum number of messages to be collected before the batch is published.
|
|
112
|
-
# Default is 100.
|
|
113
|
-
# * `:interval` (Numeric) The number of seconds to collect messages before the batch is published. Default is
|
|
114
|
-
# 0.01.
|
|
115
|
-
# * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
|
|
116
|
-
# * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
|
|
117
|
-
# * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
|
|
118
|
-
# * `:compress` (Boolean) The flag that enables publisher compression. Default is false
|
|
119
|
-
# * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
|
|
120
|
-
# Default is 240.
|
|
121
|
-
# * `:flow_control` (Hash) The client flow control settings for message publishing:
|
|
122
|
-
# * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
|
|
123
|
-
# `10 * max_messages`.
|
|
124
|
-
# * `:byte_limit` (Integer) The maximum total size of messages allowed to wait to be published. Default is
|
|
125
|
-
# `10 * max_bytes`.
|
|
126
|
-
# * `:limit_exceeded_behavior` (Symbol) The action to take when publish flow control limits are exceeded.
|
|
127
|
-
# Possible values include: `:ignore` - Flow control is disabled. `:error` - Calls to {Topic#publish_async}
|
|
128
|
-
# will raise {FlowControlLimitError} when publish flow control limits are exceeded. `:block` - Calls to
|
|
129
|
-
# {Topic#publish_async} will block until capacity is available when publish flow control limits are
|
|
130
|
-
# exceeded. The default value is `:ignore`.
|
|
131
|
-
#
|
|
132
|
-
# @return [Google::Cloud::PubSub::Topic, nil] Returns `nil` if topic
|
|
133
|
-
# does not exist.
|
|
134
|
-
#
|
|
135
|
-
# @example
|
|
136
|
-
# require "google/cloud/pubsub"
|
|
137
|
-
#
|
|
138
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
139
|
-
# topic = pubsub.topic "existing-topic"
|
|
140
|
-
#
|
|
141
|
-
# @example By default `nil` will be returned if topic does not exist.
|
|
142
|
-
# require "google/cloud/pubsub"
|
|
143
|
-
#
|
|
144
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
145
|
-
# topic = pubsub.topic "non-existing-topic" # nil
|
|
146
|
-
#
|
|
147
|
-
# @example Create topic in a different project with the `project` flag.
|
|
148
|
-
# require "google/cloud/pubsub"
|
|
149
|
-
#
|
|
150
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
151
|
-
# topic = pubsub.topic "another-topic", project: "another-project"
|
|
152
|
-
#
|
|
153
|
-
# @example Skip the lookup against the service with `skip_lookup`:
|
|
154
|
-
# require "google/cloud/pubsub"
|
|
155
|
-
#
|
|
156
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
157
|
-
# topic = pubsub.topic "another-topic", skip_lookup: true
|
|
158
|
-
#
|
|
159
|
-
# @example Configuring AsyncPublisher to increase concurrent callbacks:
|
|
160
|
-
# require "google/cloud/pubsub"
|
|
161
|
-
#
|
|
162
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
163
|
-
# topic = pubsub.topic "my-topic",
|
|
164
|
-
# async: { threads: { callback: 16 } }
|
|
90
|
+
# Retrieve a client for managing subscriptions.
|
|
165
91
|
#
|
|
166
|
-
#
|
|
167
|
-
# if result.succeeded?
|
|
168
|
-
# log_publish_success result.data
|
|
169
|
-
# else
|
|
170
|
-
# log_publish_failure result.data, result.error
|
|
171
|
-
# end
|
|
172
|
-
# end
|
|
92
|
+
# @return [Google::Cloud::PubSub::SubscriptionAdmin::Client]
|
|
173
93
|
#
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def topic topic_name, project: nil, skip_lookup: nil, async: nil
|
|
177
|
-
ensure_service!
|
|
178
|
-
options = { project: project, async: async }
|
|
179
|
-
return Topic.from_name topic_name, service, options if skip_lookup
|
|
180
|
-
grpc = service.get_topic topic_name, options
|
|
181
|
-
Topic.from_grpc grpc, service, async: async
|
|
182
|
-
rescue Google::Cloud::NotFoundError
|
|
183
|
-
nil
|
|
94
|
+
def subscription_admin
|
|
95
|
+
service.subscription_admin
|
|
184
96
|
end
|
|
185
|
-
alias get_topic topic
|
|
186
|
-
alias find_topic topic
|
|
187
97
|
|
|
188
98
|
##
|
|
189
|
-
#
|
|
190
|
-
#
|
|
191
|
-
# @param [String] topic_name Name of a topic. Required.
|
|
192
|
-
# The value can be a simple topic ID (relative name), in which
|
|
193
|
-
# case the current project ID will be supplied, or a fully-qualified
|
|
194
|
-
# topic name in the form `projects/{project_id}/topics/{topic_id}`.
|
|
195
|
-
#
|
|
196
|
-
# The topic ID (relative name) must start with a letter, and
|
|
197
|
-
# contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
|
|
198
|
-
# underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
|
|
199
|
-
# signs (`%`). It must be between 3 and 255 characters in length, and
|
|
200
|
-
# it must not start with `goog`.
|
|
201
|
-
# @param [Hash] labels A hash of user-provided labels associated with
|
|
202
|
-
# the topic. You can use these to organize and group your topics.
|
|
203
|
-
# Label keys and values can be no longer than 63 characters, can only
|
|
204
|
-
# contain lowercase letters, numeric characters, underscores and
|
|
205
|
-
# dashes. International characters are allowed. Label values are
|
|
206
|
-
# optional. Label keys must start with a letter and each label in the
|
|
207
|
-
# list must have a different key. See [Creating and Managing
|
|
208
|
-
# Labels](https://cloud.google.com/pubsub/docs/labels).
|
|
209
|
-
# @param [String] kms_key The Cloud KMS encryption key that will be used
|
|
210
|
-
# to protect access to messages published on this topic. Optional.
|
|
211
|
-
# For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
|
|
212
|
-
# @param [Array<String>] persistence_regions The list of GCP region IDs
|
|
213
|
-
# where messages that are published to the topic may be persisted in
|
|
214
|
-
# storage. Optional.
|
|
215
|
-
# @param [Hash] async A hash of values to configure the topic's
|
|
216
|
-
# {AsyncPublisher} that is created when {Topic#publish_async}
|
|
217
|
-
# is called. Optional.
|
|
218
|
-
#
|
|
219
|
-
# Hash keys and values may include the following:
|
|
220
|
-
#
|
|
221
|
-
# * `:max_bytes` (Integer) The maximum size of messages to be collected
|
|
222
|
-
# before the batch is published. Default is 1,000,000 (1MB).
|
|
223
|
-
# * `:max_messages` (Integer) The maximum number of messages to be
|
|
224
|
-
# collected before the batch is published. Default is 100.
|
|
225
|
-
# * `:interval` (Numeric) The number of seconds to collect messages before
|
|
226
|
-
# the batch is published. Default is 0.01.
|
|
227
|
-
# * `:threads` (Hash) The number of threads to create to handle concurrent
|
|
228
|
-
# calls by the publisher:
|
|
229
|
-
# * `:publish` (Integer) The number of threads used to publish messages.
|
|
230
|
-
# Default is 2.
|
|
231
|
-
# * `:callback` (Integer) The number of threads to handle the published
|
|
232
|
-
# messages' callbacks. Default is 4.
|
|
233
|
-
# * `:compress` (Boolean) The flag that enables publisher compression. Default is false
|
|
234
|
-
# * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
|
|
235
|
-
# Default is 240.
|
|
236
|
-
# * `:flow_control` (Hash) The client flow control settings for message publishing:
|
|
237
|
-
# * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
|
|
238
|
-
# `10 * max_messages`.
|
|
239
|
-
# * `:byte_limit` (Integer) The maximum total size of messages allowed to wait to be published. Default is
|
|
240
|
-
# `10 * max_bytes`.
|
|
241
|
-
# * `:limit_exceeded_behavior` (Symbol) The action to take when publish flow control limits are exceeded.
|
|
242
|
-
# Possible values include: `:ignore` - Flow control is disabled. `:error` - Calls to {Topic#publish_async}
|
|
243
|
-
# will raise {FlowControlLimitError} when publish flow control limits are exceeded. `:block` - Calls to
|
|
244
|
-
# {Topic#publish_async} will block until capacity is available when publish flow control limits are
|
|
245
|
-
# exceeded. The default value is `:ignore`.
|
|
246
|
-
# @param [String] schema_name The name of the schema that messages
|
|
247
|
-
# published should be validated against. Optional. The value can be a
|
|
248
|
-
# simple schema ID (relative name), in which case the current project
|
|
249
|
-
# ID will be supplied, or a fully-qualified schema name in the form
|
|
250
|
-
# `projects/{project_id}/schemas/{schema_id}`. If provided,
|
|
251
|
-
# `message_encoding` must also be provided.
|
|
252
|
-
# @param [String, Symbol] message_encoding The encoding of messages validated
|
|
253
|
-
# against the schema identified by `schema_name`. Optional. Values include:
|
|
254
|
-
#
|
|
255
|
-
# * `JSON` - JSON encoding.
|
|
256
|
-
# * `BINARY` - Binary encoding, as defined by the schema type. For some
|
|
257
|
-
# schema types, binary encoding may not be available.
|
|
258
|
-
# @param [Numeric] retention Indicates the minimum number of seconds to retain a message
|
|
259
|
-
# after it is published to the topic. If this field is set, messages published
|
|
260
|
-
# to the topic within the `retention` number of seconds are always available to
|
|
261
|
-
# subscribers. For instance, it allows any attached subscription to [seek to a
|
|
262
|
-
# timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time)
|
|
263
|
-
# that is up to `retention` number of seconds in the past. If this field is
|
|
264
|
-
# not set, message retention is controlled by settings on individual
|
|
265
|
-
# subscriptions. Cannot be less than 600 (10 minutes) or more than 604,800 (7 days).
|
|
266
|
-
# @param ingestion_data_source_settings [::Google::Cloud::PubSub::V1::IngestionDataSourceSettings, ::Hash]
|
|
267
|
-
# Optional. Settings for ingestion from a data source into this topic.
|
|
268
|
-
#
|
|
269
|
-
# @return [Google::Cloud::PubSub::Topic]
|
|
270
|
-
#
|
|
271
|
-
# @example
|
|
272
|
-
# require "google/cloud/pubsub"
|
|
99
|
+
# Retrieve a client for managing topics.
|
|
273
100
|
#
|
|
274
|
-
#
|
|
275
|
-
# topic = pubsub.create_topic "my-topic"
|
|
101
|
+
# @return [Google::Cloud::PubSub::TopicAdmin::Client]
|
|
276
102
|
#
|
|
277
|
-
def
|
|
278
|
-
|
|
279
|
-
kms_key: nil,
|
|
280
|
-
persistence_regions: nil,
|
|
281
|
-
async: nil,
|
|
282
|
-
schema_name: nil,
|
|
283
|
-
message_encoding: nil,
|
|
284
|
-
retention: nil,
|
|
285
|
-
ingestion_data_source_settings: nil
|
|
286
|
-
ensure_service!
|
|
287
|
-
grpc = service.create_topic topic_name,
|
|
288
|
-
labels: labels,
|
|
289
|
-
kms_key_name: kms_key,
|
|
290
|
-
persistence_regions: persistence_regions,
|
|
291
|
-
schema_name: schema_name,
|
|
292
|
-
message_encoding: message_encoding,
|
|
293
|
-
retention: retention,
|
|
294
|
-
ingestion_data_source_settings: ingestion_data_source_settings
|
|
295
|
-
Topic.from_grpc grpc, service, async: async
|
|
103
|
+
def topic_admin
|
|
104
|
+
service.topic_admin
|
|
296
105
|
end
|
|
297
|
-
alias new_topic create_topic
|
|
298
106
|
|
|
299
107
|
##
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
# @param [String] token The `token` value returned by the last call to
|
|
303
|
-
# `topics`; indicates that this is a continuation of a call, and that
|
|
304
|
-
# the system should return the next page of data.
|
|
305
|
-
# @param [Integer] max Maximum number of topics to return.
|
|
306
|
-
#
|
|
307
|
-
# @return [Array<Google::Cloud::PubSub::Topic>] (See
|
|
308
|
-
# {Google::Cloud::PubSub::Topic::List})
|
|
309
|
-
#
|
|
310
|
-
# @example
|
|
311
|
-
# require "google/cloud/pubsub"
|
|
312
|
-
#
|
|
313
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
108
|
+
# Retrieve a client for managing schemas.
|
|
314
109
|
#
|
|
315
|
-
#
|
|
316
|
-
# topics.each do |topic|
|
|
317
|
-
# puts topic.name
|
|
318
|
-
# end
|
|
110
|
+
# @return [Google::Cloud::PubSub::V1::SchemaService::Client]
|
|
319
111
|
#
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
112
|
+
def schemas
|
|
113
|
+
service.schemas
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
##
|
|
117
|
+
# Retrieve a client specific for Iam Policy related functions.
|
|
324
118
|
#
|
|
325
|
-
#
|
|
326
|
-
# topics.all do |topic|
|
|
327
|
-
# puts topic.name
|
|
328
|
-
# end
|
|
119
|
+
# @return [Google::Iam::V1::IAMPolicy::Client]
|
|
329
120
|
#
|
|
330
|
-
def
|
|
331
|
-
|
|
332
|
-
options = { token: token, max: max }
|
|
333
|
-
grpc = service.list_topics options
|
|
334
|
-
Topic::List.from_grpc grpc, service, max
|
|
121
|
+
def iam
|
|
122
|
+
service.iam
|
|
335
123
|
end
|
|
336
|
-
alias find_topics topics
|
|
337
|
-
alias list_topics topics
|
|
338
124
|
|
|
339
125
|
##
|
|
340
|
-
# Retrieves
|
|
126
|
+
# Retrieves a Publisher by topic name or full project path.
|
|
341
127
|
#
|
|
342
|
-
# @param [String]
|
|
343
|
-
#
|
|
344
|
-
#
|
|
345
|
-
#
|
|
346
|
-
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
350
|
-
# @param [Boolean] skip_lookup Optionally create a {
|
|
351
|
-
# without verifying the
|
|
128
|
+
# @param [String] topic_name Name of a topic. The value can be a simple
|
|
129
|
+
# topic ID (relative name) or a fully-qualified topic name.
|
|
130
|
+
# @param [String] project The alternate project ID can be specified here.
|
|
131
|
+
# Optional. Not used if a fully-qualified topic name is provided
|
|
132
|
+
# for `topic_name`.
|
|
133
|
+
# @param [Hash] async A hash of values to configure the topic's
|
|
134
|
+
# {AsyncPublisher} that is created when {Publisher#publish_async}
|
|
135
|
+
# is called. Optional.
|
|
136
|
+
# @param [Boolean] skip_lookup Optionally create a {Publisher} object
|
|
137
|
+
# without verifying the topic resource exists on the Pub/Sub
|
|
352
138
|
# service. Calls made on this object will raise errors if the service
|
|
353
139
|
# resource does not exist. Default is `false`.
|
|
354
140
|
#
|
|
355
|
-
# @return [Google::Cloud::PubSub::
|
|
356
|
-
# the subscription does not exist
|
|
141
|
+
# @return [Google::Cloud::PubSub::Publisher]
|
|
357
142
|
#
|
|
358
|
-
|
|
359
|
-
# require "google/cloud/pubsub"
|
|
360
|
-
#
|
|
361
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
362
|
-
#
|
|
363
|
-
# sub = pubsub.subscription "my-sub"
|
|
364
|
-
# sub.name #=> "projects/my-project/subscriptions/my-sub"
|
|
365
|
-
#
|
|
366
|
-
# @example Skip the lookup against the service with `skip_lookup`:
|
|
367
|
-
# require "google/cloud/pubsub"
|
|
368
|
-
#
|
|
369
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
370
|
-
#
|
|
371
|
-
# # No API call is made to retrieve the subscription information.
|
|
372
|
-
# sub = pubsub.subscription "my-sub", skip_lookup: true
|
|
373
|
-
# sub.name #=> "projects/my-project/subscriptions/my-sub"
|
|
374
|
-
#
|
|
375
|
-
def subscription subscription_name, project: nil, skip_lookup: nil
|
|
143
|
+
def publisher topic_name, project: nil, async: nil, skip_lookup: nil
|
|
376
144
|
ensure_service!
|
|
377
|
-
options = { project: project }
|
|
378
|
-
return
|
|
379
|
-
grpc = service.
|
|
380
|
-
|
|
381
|
-
rescue Google::Cloud::NotFoundError
|
|
382
|
-
nil
|
|
145
|
+
options = { project: project, async: async }
|
|
146
|
+
return Publisher.from_name topic_name, service, options if skip_lookup
|
|
147
|
+
grpc = topic_admin.get_topic topic: service.topic_path(topic_name, options)
|
|
148
|
+
Publisher.from_grpc grpc, service, async: async
|
|
383
149
|
end
|
|
384
|
-
alias get_subscription subscription
|
|
385
|
-
alias find_subscription subscription
|
|
386
150
|
|
|
387
151
|
##
|
|
388
|
-
# Retrieves a
|
|
389
|
-
#
|
|
390
|
-
# @param [String] token A previously-returned page token representing
|
|
391
|
-
# part of the larger set of results to view.
|
|
392
|
-
# @param [Integer] max Maximum number of subscriptions to return.
|
|
393
|
-
#
|
|
394
|
-
# @return [Array<Google::Cloud::PubSub::Subscription>] (See
|
|
395
|
-
# {Google::Cloud::PubSub::Subscription::List})
|
|
396
|
-
#
|
|
397
|
-
# @example
|
|
398
|
-
# require "google/cloud/pubsub"
|
|
399
|
-
#
|
|
400
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
401
|
-
#
|
|
402
|
-
# subs = pubsub.subscriptions
|
|
403
|
-
# subs.each do |sub|
|
|
404
|
-
# puts sub.name
|
|
405
|
-
# end
|
|
406
|
-
#
|
|
407
|
-
# @example Retrieve all subscriptions: (See {Subscription::List#all})
|
|
408
|
-
# require "google/cloud/pubsub"
|
|
152
|
+
# Retrieves a Subscriber by subscription name or full project path.
|
|
409
153
|
#
|
|
410
|
-
#
|
|
154
|
+
# @param [String] subscription_name Name of a subscription. The value can
|
|
155
|
+
# be a simple subscription ID (relative name) or a fully-qualified
|
|
156
|
+
# subscription name.
|
|
157
|
+
# @param [String] project The alternate project ID can be specified here.
|
|
158
|
+
# Optional. Not used if a fully-qualified topic name is provided
|
|
159
|
+
# for `topic_name`.
|
|
160
|
+
# @param [Boolean] skip_lookup Optionally create a {Google::Cloud::PubSub::V1::Subscription}
|
|
161
|
+
# object without verifying the subscription resource exists on the Pub/Sub
|
|
162
|
+
# service. Calls made on this object will raise errors if the service
|
|
163
|
+
# resource does not exist. Default is `false`.
|
|
411
164
|
#
|
|
412
|
-
#
|
|
413
|
-
#
|
|
414
|
-
# puts sub.name
|
|
415
|
-
# end
|
|
165
|
+
# @return [Google::Cloud::PubSub::Subscriber, nil] Returns `nil` if
|
|
166
|
+
# the subscription does not exist.
|
|
416
167
|
#
|
|
417
|
-
def
|
|
168
|
+
def subscriber subscription_name, project: nil, skip_lookup: nil
|
|
418
169
|
ensure_service!
|
|
419
|
-
options = {
|
|
420
|
-
|
|
421
|
-
|
|
170
|
+
options = { project: project }
|
|
171
|
+
return Subscriber.from_name subscription_name, service, options if skip_lookup
|
|
172
|
+
grpc = subscription_admin.get_subscription subscription: service.subscription_path(subscription_name, options)
|
|
173
|
+
Subscriber.from_grpc grpc, service
|
|
422
174
|
end
|
|
423
|
-
alias find_subscriptions subscriptions
|
|
424
|
-
alias list_subscriptions subscriptions
|
|
425
|
-
|
|
426
175
|
|
|
427
176
|
##
|
|
428
|
-
#
|
|
429
|
-
#
|
|
430
|
-
# @param [String]
|
|
431
|
-
#
|
|
432
|
-
# @param [Integer] max Maximum number of snapshots to return.
|
|
433
|
-
#
|
|
434
|
-
# @return [Array<Google::Cloud::PubSub::Snapshot>] (See
|
|
435
|
-
# {Google::Cloud::PubSub::Snapshot::List})
|
|
436
|
-
#
|
|
437
|
-
# @example
|
|
438
|
-
# require "google/cloud/pubsub"
|
|
177
|
+
# Returns a fully-qualified project path in the form of
|
|
178
|
+
# `projects/{project_id}`
|
|
179
|
+
# @param [String] project_name A project name. Optional.
|
|
180
|
+
# If provided, this will be used in place of the default `project_id`.
|
|
439
181
|
#
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
# snapshots = pubsub.snapshots
|
|
443
|
-
# snapshots.each do |snapshot|
|
|
444
|
-
# puts snapshot.name
|
|
445
|
-
# end
|
|
446
|
-
#
|
|
447
|
-
# @example Retrieve all snapshots: (See {Snapshot::List#all})
|
|
448
|
-
# require "google/cloud/pubsub"
|
|
449
|
-
#
|
|
450
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
451
|
-
#
|
|
452
|
-
# snapshots = pubsub.snapshots
|
|
453
|
-
# snapshots.all do |snapshot|
|
|
454
|
-
# puts snapshot.name
|
|
455
|
-
# end
|
|
456
|
-
#
|
|
457
|
-
def snapshots token: nil, max: nil
|
|
458
|
-
ensure_service!
|
|
459
|
-
options = { token: token, max: max }
|
|
460
|
-
grpc = service.list_snapshots options
|
|
461
|
-
Snapshot::List.from_grpc grpc, service, max
|
|
182
|
+
def project_path project_name: nil
|
|
183
|
+
service.project_path options: { "project" => project_name }.compact
|
|
462
184
|
end
|
|
463
|
-
alias find_snapshots snapshots
|
|
464
|
-
alias list_snapshots snapshots
|
|
465
185
|
|
|
466
186
|
##
|
|
467
|
-
#
|
|
468
|
-
#
|
|
469
|
-
# @param [String]
|
|
470
|
-
#
|
|
471
|
-
#
|
|
472
|
-
#
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
# * `FULL` - Include all Schema object fields.
|
|
476
|
-
#
|
|
477
|
-
# The default value is `FULL`.
|
|
478
|
-
# @param [String] project If the schema belongs to a project other
|
|
479
|
-
# than the one currently connected to, the alternate project ID can be
|
|
480
|
-
# specified here. Not used if a fully-qualified schema name is
|
|
481
|
-
# provided for `schema_name`.
|
|
482
|
-
# @param [Boolean] skip_lookup Optionally create a {Schema} object
|
|
483
|
-
# without verifying the schema resource exists on the Pub/Sub
|
|
484
|
-
# service. Calls made on this object will raise errors if the service
|
|
485
|
-
# resource does not exist. Default is `false`.
|
|
486
|
-
#
|
|
487
|
-
# @return [Google::Cloud::PubSub::Schema, nil] Returns `nil` if
|
|
488
|
-
# the schema does not exist.
|
|
489
|
-
#
|
|
490
|
-
# @example
|
|
491
|
-
# require "google/cloud/pubsub"
|
|
492
|
-
#
|
|
493
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
494
|
-
#
|
|
495
|
-
# schema = pubsub.schema "my-schema"
|
|
496
|
-
# schema.name #=> "projects/my-project/schemas/my-schema"
|
|
497
|
-
# schema.type #=> :PROTOCOL_BUFFER
|
|
498
|
-
# schema.definition # The schema definition
|
|
499
|
-
#
|
|
500
|
-
# @example Skip the lookup against the service with `skip_lookup`:
|
|
501
|
-
# require "google/cloud/pubsub"
|
|
502
|
-
#
|
|
503
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
504
|
-
#
|
|
505
|
-
# # No API call is made to retrieve the schema information.
|
|
506
|
-
# # The default project is used in the name.
|
|
507
|
-
# schema = pubsub.schema "my-schema", skip_lookup: true
|
|
508
|
-
# schema.name #=> "projects/my-project/schemas/my-schema"
|
|
509
|
-
# schema.type #=> nil
|
|
510
|
-
# schema.definition #=> nil
|
|
511
|
-
#
|
|
512
|
-
# @example Omit the schema definition with `view: :basic`:
|
|
513
|
-
# require "google/cloud/pubsub"
|
|
514
|
-
#
|
|
515
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
516
|
-
#
|
|
517
|
-
# schema = pubsub.schema "my-schema", view: :basic
|
|
518
|
-
# schema.name #=> "projects/my-project/schemas/my-schema"
|
|
519
|
-
# schema.type #=> :PROTOCOL_BUFFER
|
|
520
|
-
# schema.definition #=> nil
|
|
521
|
-
#
|
|
522
|
-
def schema schema_name, view: nil, project: nil, skip_lookup: nil
|
|
523
|
-
ensure_service!
|
|
524
|
-
options = { project: project }
|
|
525
|
-
return Schema.from_name schema_name, view, service, options if skip_lookup
|
|
526
|
-
view ||= :FULL
|
|
527
|
-
grpc = service.get_schema schema_name, view, options
|
|
528
|
-
Schema.from_grpc grpc, service
|
|
529
|
-
rescue Google::Cloud::NotFoundError
|
|
530
|
-
nil
|
|
187
|
+
# Returns a fully-qualified topic path in the form of
|
|
188
|
+
# `projects/{project_id}/topics/{topic_name}`
|
|
189
|
+
# @param [String] topic_name A topic name.
|
|
190
|
+
# @param [String] project_name A project name. Optional.
|
|
191
|
+
# If provided, this will be used in place of the default `project_id`.
|
|
192
|
+
#
|
|
193
|
+
def topic_path topic_name, project_name: nil
|
|
194
|
+
service.topic_path topic_name, options: { "project" => project_name }.compact
|
|
531
195
|
end
|
|
532
|
-
alias get_schema schema
|
|
533
|
-
alias find_schema schema
|
|
534
196
|
|
|
535
197
|
##
|
|
536
|
-
#
|
|
537
|
-
#
|
|
538
|
-
# @param [String]
|
|
539
|
-
#
|
|
540
|
-
#
|
|
541
|
-
#
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
# signs (`%`). It must be between 3 and 255 characters in length, and
|
|
545
|
-
# it must not start with `goog`.
|
|
546
|
-
# @param [String, Symbol] type The type of the schema. Required. Possible
|
|
547
|
-
# values are case-insensitive and include:
|
|
548
|
-
#
|
|
549
|
-
# * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
|
|
550
|
-
# * `AVRO` - An Avro schema definition.
|
|
551
|
-
# @param [String] definition The definition of the schema. Required. This
|
|
552
|
-
# should be a string representing the full definition of the schema that
|
|
553
|
-
# is a valid schema definition of the type specified in `type`.
|
|
554
|
-
# @param [String] project If the schema belongs to a project other
|
|
555
|
-
# than the one currently connected to, the alternate project ID can be
|
|
556
|
-
# specified here. Optional.
|
|
557
|
-
#
|
|
558
|
-
# @return [Google::Cloud::PubSub::Schema]
|
|
559
|
-
#
|
|
560
|
-
# @example
|
|
561
|
-
# require "google/cloud/pubsub"
|
|
562
|
-
#
|
|
563
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
564
|
-
#
|
|
565
|
-
# definition = "..."
|
|
566
|
-
# schema = pubsub.create_schema "my-schema", :avro, definition
|
|
567
|
-
# schema.name #=> "projects/my-project/schemas/my-schema"
|
|
568
|
-
#
|
|
569
|
-
def create_schema schema_id, type, definition, project: nil
|
|
570
|
-
ensure_service!
|
|
571
|
-
type = type.to_s.upcase
|
|
572
|
-
grpc = service.create_schema schema_id, type, definition, project: project
|
|
573
|
-
Schema.from_grpc grpc, service
|
|
198
|
+
# Returns a fully-qualified subscription path in the form of
|
|
199
|
+
# `projects/{project_id}/subscriptions/{subscription_name}`
|
|
200
|
+
# @param [String] subscription_name A subscription name.
|
|
201
|
+
# @param [String] project_name A project name. Optional.
|
|
202
|
+
# If provided, this will be used in place of the default `project_id`.
|
|
203
|
+
#
|
|
204
|
+
def subscription_path subscription_name, project_name: nil
|
|
205
|
+
service.subscription_path subscription_name, options: { "project" => project_name }.compact
|
|
574
206
|
end
|
|
575
|
-
alias new_schema create_schema
|
|
576
207
|
|
|
577
208
|
##
|
|
578
|
-
#
|
|
579
|
-
#
|
|
580
|
-
# @param
|
|
581
|
-
#
|
|
582
|
-
#
|
|
583
|
-
#
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
# @param [String] token A previously-returned page token representing
|
|
587
|
-
# part of the larger set of results to view.
|
|
588
|
-
# @param [Integer] max Maximum number of schemas to return.
|
|
589
|
-
#
|
|
590
|
-
# @return [Array<Google::Cloud::PubSub::Schema>] (See
|
|
591
|
-
# {Google::Cloud::PubSub::Schema::List})
|
|
592
|
-
#
|
|
593
|
-
# @example
|
|
594
|
-
# require "google/cloud/pubsub"
|
|
595
|
-
#
|
|
596
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
597
|
-
#
|
|
598
|
-
# schemas = pubsub.schemas
|
|
599
|
-
# schemas.each do |schema|
|
|
600
|
-
# puts schema.name
|
|
601
|
-
# end
|
|
602
|
-
#
|
|
603
|
-
# @example Retrieve all schemas: (See {Schema::List#all})
|
|
604
|
-
# require "google/cloud/pubsub"
|
|
605
|
-
#
|
|
606
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
607
|
-
#
|
|
608
|
-
# schemas = pubsub.schemas
|
|
609
|
-
# schemas.all do |schema|
|
|
610
|
-
# puts schema.name
|
|
611
|
-
# end
|
|
612
|
-
#
|
|
613
|
-
def schemas view: nil, token: nil, max: nil
|
|
614
|
-
ensure_service!
|
|
615
|
-
view ||= :FULL
|
|
616
|
-
options = { token: token, max: max }
|
|
617
|
-
grpc = service.list_schemas view, options
|
|
618
|
-
Schema::List.from_grpc grpc, service, view, max
|
|
209
|
+
# Returns a fully-qualified snapshot path in the form of
|
|
210
|
+
# `projects/{project_id}/snapshots/{snapshot_name}`
|
|
211
|
+
# @param [String] snapshot_name A snapshot name.
|
|
212
|
+
# @param [String] project_name A project name. Optional.
|
|
213
|
+
# If provided, this will be used in place of the default `project_id`.
|
|
214
|
+
#
|
|
215
|
+
def snapshot_path snapshot_name, project_name: nil
|
|
216
|
+
service.snapshot_path snapshot_name, options: { "project" => project_name }.compact
|
|
619
217
|
end
|
|
620
|
-
alias find_schemas schemas
|
|
621
|
-
alias list_schemas schemas
|
|
622
218
|
|
|
623
219
|
##
|
|
624
|
-
#
|
|
625
|
-
#
|
|
626
|
-
# @param [String
|
|
627
|
-
#
|
|
628
|
-
#
|
|
629
|
-
#
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
# should be a string representing the full definition of the schema that
|
|
633
|
-
# is a valid schema definition of the type specified in `type`.
|
|
634
|
-
# @param [String] project If the schema belongs to a project other
|
|
635
|
-
# than the one currently connected to, the alternate project ID can be
|
|
636
|
-
# specified here. Optional.
|
|
637
|
-
#
|
|
638
|
-
# @return [Boolean] `true` if the schema is valid, `false` otherwise.
|
|
639
|
-
#
|
|
640
|
-
# @example
|
|
641
|
-
# require "google/cloud/pubsub"
|
|
642
|
-
#
|
|
643
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
644
|
-
#
|
|
645
|
-
# definition = "..."
|
|
646
|
-
# pubsub.validate_schema :avro, definition #=> true
|
|
647
|
-
#
|
|
648
|
-
def valid_schema? type, definition, project: nil
|
|
649
|
-
ensure_service!
|
|
650
|
-
type = type.to_s.upcase
|
|
651
|
-
service.validate_schema type, definition, project: project # return type is empty
|
|
652
|
-
true
|
|
653
|
-
rescue Google::Cloud::InvalidArgumentError
|
|
654
|
-
false
|
|
220
|
+
# Returns a fully-qualified schema path in the form of
|
|
221
|
+
# `projects/{project_id}/schemas/{schema_name}`
|
|
222
|
+
# @param [String] schema_name A schema name.
|
|
223
|
+
# @param [String] project_name A project name. Optional.
|
|
224
|
+
# If provided, this will be used in place of the default `project_id`.
|
|
225
|
+
#
|
|
226
|
+
def schema_path schema_name, project_name: nil
|
|
227
|
+
service.schema_path schema_name, options: { "project" => project_name }.compact
|
|
655
228
|
end
|
|
656
|
-
alias validate_schema valid_schema?
|
|
657
229
|
|
|
658
230
|
protected
|
|
659
231
|
|