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
|
@@ -18,6 +18,8 @@ require "google/cloud/pubsub/credentials"
|
|
|
18
18
|
require "google/cloud/pubsub/convert"
|
|
19
19
|
require "google/cloud/pubsub/version"
|
|
20
20
|
require "google/cloud/pubsub/v1"
|
|
21
|
+
require "google/cloud/pubsub/admin_clients"
|
|
22
|
+
require "google/cloud/pubsub/internal_logger"
|
|
21
23
|
require "securerandom"
|
|
22
24
|
|
|
23
25
|
module Google
|
|
@@ -39,20 +41,25 @@ module Google
|
|
|
39
41
|
|
|
40
42
|
attr_reader :universe_domain
|
|
41
43
|
|
|
44
|
+
##
|
|
45
|
+
# @private The InternalLogger object.
|
|
46
|
+
attr_reader :logger
|
|
47
|
+
|
|
42
48
|
##
|
|
43
49
|
# Creates a new Service instance.
|
|
44
|
-
def initialize project, credentials, host: nil, timeout: nil, universe_domain: nil
|
|
50
|
+
def initialize project, credentials, host: nil, timeout: nil, universe_domain: nil, logger: nil
|
|
45
51
|
@project = project
|
|
46
52
|
@credentials = credentials
|
|
47
53
|
@host = host
|
|
48
54
|
@timeout = timeout
|
|
49
55
|
@client_id = SecureRandom.uuid.freeze
|
|
50
56
|
@universe_domain = universe_domain || ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] || "googleapis.com"
|
|
57
|
+
@logger = logger
|
|
51
58
|
end
|
|
52
59
|
|
|
53
|
-
def
|
|
54
|
-
return
|
|
55
|
-
@
|
|
60
|
+
def subscription_admin
|
|
61
|
+
return mocked_subscription_admin if mocked_subscription_admin
|
|
62
|
+
@subscription_admin ||= SubscriptionAdmin::Client.new do |config|
|
|
56
63
|
config.credentials = credentials if credentials
|
|
57
64
|
override_client_config_timeouts config if timeout
|
|
58
65
|
config.endpoint = host if host
|
|
@@ -62,11 +69,11 @@ module Google
|
|
|
62
69
|
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
|
63
70
|
end
|
|
64
71
|
end
|
|
65
|
-
attr_accessor :
|
|
72
|
+
attr_accessor :mocked_subscription_admin
|
|
66
73
|
|
|
67
|
-
def
|
|
68
|
-
return
|
|
69
|
-
@
|
|
74
|
+
def topic_admin
|
|
75
|
+
return mocked_topic_admin if mocked_topic_admin
|
|
76
|
+
@topic_admin ||= TopicAdmin::Client.new do |config|
|
|
70
77
|
config.credentials = credentials if credentials
|
|
71
78
|
override_client_config_timeouts config if timeout
|
|
72
79
|
config.endpoint = host if host
|
|
@@ -76,12 +83,12 @@ module Google
|
|
|
76
83
|
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
|
77
84
|
end
|
|
78
85
|
end
|
|
79
|
-
attr_accessor :
|
|
86
|
+
attr_accessor :mocked_topic_admin
|
|
80
87
|
|
|
81
88
|
def iam
|
|
82
89
|
return mocked_iam if mocked_iam
|
|
83
90
|
@iam ||= begin
|
|
84
|
-
iam = (@
|
|
91
|
+
iam = (@topic_admin || @subscription_admin || @schemas || topic_admin).iam_policy_client
|
|
85
92
|
iam.configure do |config|
|
|
86
93
|
override_client_config_timeouts config if timeout
|
|
87
94
|
config.lib_name = "gccl"
|
|
@@ -107,77 +114,6 @@ module Google
|
|
|
107
114
|
end
|
|
108
115
|
attr_accessor :mocked_schemas
|
|
109
116
|
|
|
110
|
-
##
|
|
111
|
-
# Gets the configuration of a topic.
|
|
112
|
-
# Since the topic only has the name attribute,
|
|
113
|
-
# this method is only useful to check the existence of a topic.
|
|
114
|
-
# If other attributes are added in the future,
|
|
115
|
-
# they will be returned here.
|
|
116
|
-
def get_topic topic_name, options = {}
|
|
117
|
-
publisher.get_topic topic: topic_path(topic_name, options)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
##
|
|
121
|
-
# Lists matching topics.
|
|
122
|
-
def list_topics options = {}
|
|
123
|
-
paged_enum = publisher.list_topics project: project_path(options),
|
|
124
|
-
page_size: options[:max],
|
|
125
|
-
page_token: options[:token]
|
|
126
|
-
|
|
127
|
-
paged_enum.response
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
##
|
|
131
|
-
# Creates the given topic with the given name.
|
|
132
|
-
def create_topic topic_name,
|
|
133
|
-
labels: nil,
|
|
134
|
-
kms_key_name: nil,
|
|
135
|
-
persistence_regions: nil,
|
|
136
|
-
schema_name: nil,
|
|
137
|
-
message_encoding: nil,
|
|
138
|
-
retention: nil,
|
|
139
|
-
ingestion_data_source_settings: nil,
|
|
140
|
-
options: {}
|
|
141
|
-
if persistence_regions
|
|
142
|
-
message_storage_policy = Google::Cloud::PubSub::V1::MessageStoragePolicy.new(
|
|
143
|
-
allowed_persistence_regions: Array(persistence_regions)
|
|
144
|
-
)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
if schema_name || message_encoding
|
|
148
|
-
unless schema_name && message_encoding
|
|
149
|
-
raise ArgumentError, "Schema settings must include both schema_name and message_encoding."
|
|
150
|
-
end
|
|
151
|
-
schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new(
|
|
152
|
-
schema: schema_path(schema_name),
|
|
153
|
-
encoding: message_encoding.to_s.upcase
|
|
154
|
-
)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
publisher.create_topic \
|
|
158
|
-
name: topic_path(topic_name, options),
|
|
159
|
-
labels: labels,
|
|
160
|
-
kms_key_name: kms_key_name,
|
|
161
|
-
message_storage_policy: message_storage_policy,
|
|
162
|
-
schema_settings: schema_settings,
|
|
163
|
-
message_retention_duration: Convert.number_to_duration(retention),
|
|
164
|
-
ingestion_data_source_settings: ingestion_data_source_settings
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def update_topic topic_obj, *fields
|
|
168
|
-
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
|
169
|
-
publisher.update_topic topic: topic_obj, update_mask: mask
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
##
|
|
173
|
-
# Deletes the topic with the given name. All subscriptions to this topic
|
|
174
|
-
# are also deleted. Raises GRPC status code 5 if the topic does not
|
|
175
|
-
# exist. After a topic is deleted, a new topic may be created with the
|
|
176
|
-
# same name.
|
|
177
|
-
def delete_topic topic_name
|
|
178
|
-
publisher.delete_topic topic: topic_path(topic_name)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
117
|
##
|
|
182
118
|
# Adds one or more messages to the topic.
|
|
183
119
|
# Raises GRPC status code 5 if the topic does not exist.
|
|
@@ -186,57 +122,11 @@ module Google
|
|
|
186
122
|
def publish topic, messages, compress: false
|
|
187
123
|
request = { topic: topic_path(topic), messages: messages }
|
|
188
124
|
compress_options = ::Gapic::CallOptions.new metadata: { "grpc-internal-encoding-request": "gzip" }
|
|
189
|
-
compress
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def get_subscription subscription_name, options = {}
|
|
195
|
-
subscriber.get_subscription subscription: subscription_path(subscription_name, options)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
##
|
|
199
|
-
# Lists matching subscriptions by project and topic.
|
|
200
|
-
def list_topics_subscriptions topic, options = {}
|
|
201
|
-
publisher.list_topic_subscriptions topic: topic_path(topic, options),
|
|
202
|
-
page_size: options[:max],
|
|
203
|
-
page_token: options[:token]
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
##
|
|
207
|
-
# Lists matching subscriptions by project.
|
|
208
|
-
def list_subscriptions options = {}
|
|
209
|
-
paged_enum = subscriber.list_subscriptions project: project_path(options),
|
|
210
|
-
page_size: options[:max],
|
|
211
|
-
page_token: options[:token]
|
|
212
|
-
|
|
213
|
-
paged_enum.response
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
##
|
|
217
|
-
# Creates a subscription on a given topic for a given subscriber.
|
|
218
|
-
def create_subscription topic, subscription_name, options = {}
|
|
219
|
-
updated_option = construct_create_subscription_options topic, subscription_name, options
|
|
220
|
-
subscriber.create_subscription(**updated_option)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def update_subscription subscription_obj, *fields
|
|
224
|
-
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
|
225
|
-
subscriber.update_subscription subscription: subscription_obj, update_mask: mask
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
##
|
|
229
|
-
# Deletes an existing subscription. All pending messages in the subscription are immediately dropped.
|
|
230
|
-
def delete_subscription subscription
|
|
231
|
-
subscriber.delete_subscription subscription: subscription_path(subscription)
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
##
|
|
235
|
-
# Detaches a subscription from its topic. All messages retained in the subscription are dropped. Subsequent
|
|
236
|
-
# `Pull` and `StreamingPull` requests will raise `FAILED_PRECONDITION`. If the subscription is a push
|
|
237
|
-
# subscription, pushes to the endpoint will stop.
|
|
238
|
-
def detach_subscription subscription
|
|
239
|
-
publisher.detach_subscription subscription: subscription_path(subscription)
|
|
125
|
+
if compress
|
|
126
|
+
(topic_admin.publish_internal request, compress_options)
|
|
127
|
+
else
|
|
128
|
+
(topic_admin.publish_internal request)
|
|
129
|
+
end
|
|
240
130
|
end
|
|
241
131
|
|
|
242
132
|
##
|
|
@@ -245,233 +135,36 @@ module Google
|
|
|
245
135
|
max_messages = options.fetch(:max, 100).to_i
|
|
246
136
|
return_immediately = !(!options.fetch(:immediate, true))
|
|
247
137
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
138
|
+
subscription_admin.pull_internal subscription: subscription_path(subscription, options),
|
|
139
|
+
max_messages: max_messages,
|
|
140
|
+
return_immediately: return_immediately
|
|
251
141
|
end
|
|
252
142
|
|
|
253
143
|
def streaming_pull request_enum, options = {}
|
|
254
|
-
|
|
144
|
+
subscription_admin.streaming_pull_internal request_enum, options
|
|
255
145
|
end
|
|
256
146
|
|
|
257
147
|
##
|
|
258
148
|
# Acknowledges receipt of a message.
|
|
259
149
|
def acknowledge subscription, *ack_ids
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
##
|
|
264
|
-
# Modifies the PushConfig for a specified subscription.
|
|
265
|
-
def modify_push_config subscription, endpoint, attributes
|
|
266
|
-
# Convert attributes to strings to match the protobuf definition
|
|
267
|
-
attributes = attributes.to_h { |k, v| [String(k), String(v)] }
|
|
268
|
-
push_config = Google::Cloud::PubSub::V1::PushConfig.new(
|
|
269
|
-
push_endpoint: endpoint,
|
|
270
|
-
attributes: attributes
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
subscriber.modify_push_config subscription: subscription_path(subscription),
|
|
274
|
-
push_config: push_config
|
|
150
|
+
logger.log_ack_nack ack_ids, "ack"
|
|
151
|
+
subscription_admin.acknowledge_internal subscription: subscription_path(subscription),
|
|
152
|
+
ack_ids: ack_ids
|
|
275
153
|
end
|
|
276
154
|
|
|
277
155
|
##
|
|
278
156
|
# Modifies the ack deadline for a specific message.
|
|
279
157
|
def modify_ack_deadline subscription, ids, deadline
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
ack_deadline_seconds: deadline
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
##
|
|
286
|
-
# Lists snapshots by project.
|
|
287
|
-
def list_snapshots options = {}
|
|
288
|
-
paged_enum = subscriber.list_snapshots project: project_path(options),
|
|
289
|
-
page_size: options[:max],
|
|
290
|
-
page_token: options[:token]
|
|
291
|
-
|
|
292
|
-
paged_enum.response
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
##
|
|
296
|
-
# Creates a snapshot on a given subscription.
|
|
297
|
-
def create_snapshot subscription, snapshot_name, labels: nil
|
|
298
|
-
subscriber.create_snapshot name: snapshot_path(snapshot_name),
|
|
299
|
-
subscription: subscription_path(subscription),
|
|
300
|
-
labels: labels
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
def update_snapshot snapshot_obj, *fields
|
|
304
|
-
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
|
305
|
-
subscriber.update_snapshot snapshot: snapshot_obj, update_mask: mask
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
##
|
|
309
|
-
# Deletes an existing snapshot.
|
|
310
|
-
# All pending messages in the snapshot are immediately dropped.
|
|
311
|
-
def delete_snapshot snapshot
|
|
312
|
-
subscriber.delete_snapshot snapshot: snapshot_path(snapshot)
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
##
|
|
316
|
-
# Adjusts the given subscription to a time or snapshot.
|
|
317
|
-
def seek subscription, time_or_snapshot
|
|
318
|
-
if a_time? time_or_snapshot
|
|
319
|
-
time = Convert.time_to_timestamp time_or_snapshot
|
|
320
|
-
subscriber.seek subscription: subscription, time: time
|
|
321
|
-
else
|
|
322
|
-
time_or_snapshot = time_or_snapshot.name if time_or_snapshot.is_a? Snapshot
|
|
323
|
-
subscriber.seek subscription: subscription_path(subscription),
|
|
324
|
-
snapshot: snapshot_path(time_or_snapshot)
|
|
158
|
+
if deadline.zero?
|
|
159
|
+
logger.log_ack_nack Array(ids), "nack"
|
|
325
160
|
end
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
# Lists schemas in the current (or given) project.
|
|
330
|
-
# @param view [String, Symbol, nil] Possible values:
|
|
331
|
-
# * `BASIC` - Include the name and type of the schema, but not the definition.
|
|
332
|
-
# * `FULL` - Include all Schema object fields.
|
|
333
|
-
#
|
|
334
|
-
def list_schemas view, options = {}
|
|
335
|
-
schema_view = Google::Cloud::PubSub::V1::SchemaView.const_get view.to_s.upcase
|
|
336
|
-
paged_enum = schemas.list_schemas parent: project_path(options),
|
|
337
|
-
view: schema_view,
|
|
338
|
-
page_size: options[:max],
|
|
339
|
-
page_token: options[:token]
|
|
340
|
-
|
|
341
|
-
paged_enum.response
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
##
|
|
345
|
-
# Lists all schema revisions for the named schema.
|
|
346
|
-
# @param name [String] The name of the schema to list revisions for.
|
|
347
|
-
# @param view [String, Symbol, nil] Possible values:
|
|
348
|
-
# * `BASIC` - Include the name and type of the schema, but not the definition.
|
|
349
|
-
# * `FULL` - Include all Schema object fields.
|
|
350
|
-
#
|
|
351
|
-
def list_schema_revisions name, view, page_size, page_token
|
|
352
|
-
schema_view = Google::Cloud::PubSub::V1::SchemaView.const_get view.to_s.upcase
|
|
353
|
-
schemas.list_schema_revisions name: name,
|
|
354
|
-
view: schema_view,
|
|
355
|
-
page_size: page_size,
|
|
356
|
-
page_token: page_token
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
##
|
|
360
|
-
# Creates a schema in the current (or given) project.
|
|
361
|
-
def create_schema schema_id, type, definition, options = {}
|
|
362
|
-
schema = Google::Cloud::PubSub::V1::Schema.new(
|
|
363
|
-
type: type,
|
|
364
|
-
definition: definition
|
|
365
|
-
)
|
|
366
|
-
schemas.create_schema parent: project_path(options),
|
|
367
|
-
schema: schema,
|
|
368
|
-
schema_id: schema_id
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
##
|
|
372
|
-
# Gets the details of a schema.
|
|
373
|
-
# @param view [String, Symbol, nil] The set of fields to return in the response. Possible values:
|
|
374
|
-
# * `BASIC` - Include the name and type of the schema, but not the definition.
|
|
375
|
-
# * `FULL` - Include all Schema object fields.
|
|
376
|
-
#
|
|
377
|
-
def get_schema schema_name, view, options = {}
|
|
378
|
-
schema_view = Google::Cloud::PubSub::V1::SchemaView.const_get view.to_s.upcase
|
|
379
|
-
schemas.get_schema name: schema_path(schema_name, options),
|
|
380
|
-
view: schema_view
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
##
|
|
384
|
-
# Delete a schema.
|
|
385
|
-
def delete_schema schema_name
|
|
386
|
-
schemas.delete_schema name: schema_path(schema_name)
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
##
|
|
390
|
-
# Commits a new schema revision to an existing schema.
|
|
391
|
-
#
|
|
392
|
-
# @param name [String] The name of the schema to revision.
|
|
393
|
-
# @param definition [String] The definition of the schema. This should
|
|
394
|
-
# contain a string representing the full definition of the schema that
|
|
395
|
-
# is a valid schema definition of the type specified in `type`. See
|
|
396
|
-
# https://cloud.google.com/pubsub/docs/schemas for details.
|
|
397
|
-
# @param type [String, Symbol] The type of the schema. Required. Possible
|
|
398
|
-
# values are case-insensitive and include:
|
|
399
|
-
#
|
|
400
|
-
# * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
|
|
401
|
-
# * `AVRO` - An Avro schema definition.
|
|
402
|
-
#
|
|
403
|
-
# @return [Google::Cloud::PubSub::V1::Schema]
|
|
404
|
-
#
|
|
405
|
-
def commit_schema name, definition, type
|
|
406
|
-
schema = Google::Cloud::PubSub::V1::Schema.new(
|
|
407
|
-
name: name,
|
|
408
|
-
definition: definition,
|
|
409
|
-
type: type
|
|
410
|
-
)
|
|
411
|
-
schemas.commit_schema name: name, schema: schema
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
##
|
|
415
|
-
# Validate the definition string intended for a schema.
|
|
416
|
-
def validate_schema type, definition, options = {}
|
|
417
|
-
schema = Google::Cloud::PubSub::V1::Schema.new(
|
|
418
|
-
type: type,
|
|
419
|
-
definition: definition
|
|
420
|
-
)
|
|
421
|
-
schemas.validate_schema parent: project_path(options),
|
|
422
|
-
schema: schema
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
##
|
|
426
|
-
# Validates a message against a schema.
|
|
427
|
-
#
|
|
428
|
-
# @param message_data [String] Message to validate against the provided `schema_spec`.
|
|
429
|
-
# @param message_encoding [Google::Cloud::PubSub::V1::Encoding] The encoding expected for messages.
|
|
430
|
-
# @param schema_name [String] Name of the schema against which to validate.
|
|
431
|
-
# @param project [String] Name of the project if not the default project.
|
|
432
|
-
# @param type [String] Ad-hoc schema type against which to validate.
|
|
433
|
-
# @param definition [String] Ad-hoc schema definition against which to validate.
|
|
434
|
-
#
|
|
435
|
-
def validate_message message_data, message_encoding, schema_name: nil, project: nil, type: nil, definition: nil
|
|
436
|
-
if type && definition
|
|
437
|
-
schema = Google::Cloud::PubSub::V1::Schema.new(
|
|
438
|
-
type: type,
|
|
439
|
-
definition: definition
|
|
440
|
-
)
|
|
441
|
-
end
|
|
442
|
-
schemas.validate_message parent: project_path(project: project),
|
|
443
|
-
name: schema_path(schema_name),
|
|
444
|
-
schema: schema,
|
|
445
|
-
message: message_data,
|
|
446
|
-
encoding: message_encoding
|
|
161
|
+
subscription_admin.modify_ack_deadline_internal subscription: subscription_path(subscription),
|
|
162
|
+
ack_ids: Array(ids),
|
|
163
|
+
ack_deadline_seconds: deadline
|
|
447
164
|
end
|
|
448
165
|
|
|
449
166
|
# Helper methods
|
|
450
167
|
|
|
451
|
-
def get_topic_policy topic_name, options = {}
|
|
452
|
-
iam.get_iam_policy resource: topic_path(topic_name, options)
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
def set_topic_policy topic_name, new_policy, options = {}
|
|
456
|
-
iam.set_iam_policy resource: topic_path(topic_name, options), policy: new_policy
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
def test_topic_permissions topic_name, permissions, options = {}
|
|
460
|
-
iam.test_iam_permissions resource: topic_path(topic_name, options), permissions: permissions
|
|
461
|
-
end
|
|
462
|
-
|
|
463
|
-
def get_subscription_policy subscription_name, options = {}
|
|
464
|
-
iam.get_iam_policy resource: subscription_path(subscription_name, options)
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
def set_subscription_policy subscription_name, new_policy, options = {}
|
|
468
|
-
iam.set_iam_policy resource: subscription_path(subscription_name, options), policy: new_policy
|
|
469
|
-
end
|
|
470
|
-
|
|
471
|
-
def test_subscription_permissions subscription_name, permissions, options = {}
|
|
472
|
-
iam.test_iam_permissions resource: subscription_path(subscription_name, options), permissions: permissions
|
|
473
|
-
end
|
|
474
|
-
|
|
475
168
|
def project_path options = {}
|
|
476
169
|
project_name = options[:project] || project
|
|
477
170
|
"projects/#{project_name}"
|
|
@@ -497,10 +190,6 @@ module Google
|
|
|
497
190
|
"#{project_path options}/schemas/#{schema_name}"
|
|
498
191
|
end
|
|
499
192
|
|
|
500
|
-
def inspect
|
|
501
|
-
"#<#{self.class.name} (#{@project})>"
|
|
502
|
-
end
|
|
503
|
-
|
|
504
193
|
protected
|
|
505
194
|
|
|
506
195
|
# Set the timeout in the client config.
|
|
@@ -515,48 +204,8 @@ module Google
|
|
|
515
204
|
end
|
|
516
205
|
end
|
|
517
206
|
|
|
518
|
-
def a_time? obj
|
|
519
|
-
return false unless obj.respond_to? :to_time
|
|
520
|
-
# Rails' String#to_time returns nil if the string doesn't parse.
|
|
521
|
-
return false if obj.to_time.nil?
|
|
522
|
-
true
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
def dead_letter_policy options
|
|
526
|
-
return nil unless options[:dead_letter_topic_name]
|
|
527
|
-
policy = Google::Cloud::PubSub::V1::DeadLetterPolicy.new dead_letter_topic: options[:dead_letter_topic_name]
|
|
528
|
-
if options[:dead_letter_max_delivery_attempts]
|
|
529
|
-
policy.max_delivery_attempts = options[:dead_letter_max_delivery_attempts]
|
|
530
|
-
end
|
|
531
|
-
policy
|
|
532
|
-
end
|
|
533
|
-
|
|
534
|
-
private
|
|
535
|
-
|
|
536
|
-
def construct_create_subscription_options topic, subscription_name, options
|
|
537
|
-
excess_options = [:deadline,
|
|
538
|
-
:retention,
|
|
539
|
-
:retain_acked,
|
|
540
|
-
:message_ordering,
|
|
541
|
-
:endpoint,
|
|
542
|
-
:dead_letter_topic_name,
|
|
543
|
-
:dead_letter_max_delivery_attempts,
|
|
544
|
-
:dead_letter_topic]
|
|
545
|
-
|
|
546
|
-
new_options = options.filter { |k, v| !v.nil? && !excess_options.include?(k) }
|
|
547
|
-
new_options[:name] = subscription_path subscription_name, options
|
|
548
|
-
new_options[:topic] = topic_path topic
|
|
549
|
-
new_options[:message_retention_duration] = Convert.number_to_duration options[:retention]
|
|
550
|
-
new_options[:dead_letter_policy] = dead_letter_policy options
|
|
551
|
-
new_options[:ack_deadline_seconds] = options[:deadline]
|
|
552
|
-
new_options[:retain_acked_messages] = options[:retain_acked]
|
|
553
|
-
new_options[:enable_message_ordering] = options[:message_ordering]
|
|
554
|
-
|
|
555
|
-
new_options.compact
|
|
556
|
-
end
|
|
557
207
|
end
|
|
558
208
|
end
|
|
559
|
-
|
|
560
209
|
Pubsub = PubSub unless const_defined? :Pubsub
|
|
561
210
|
end
|
|
562
211
|
end
|