google-cloud-pubsub 1.0.2 → 2.19.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +16 -54
  3. data/CHANGELOG.md +464 -0
  4. data/CONTRIBUTING.md +328 -116
  5. data/EMULATOR.md +1 -1
  6. data/LOGGING.md +94 -2
  7. data/OVERVIEW.md +121 -68
  8. data/TROUBLESHOOTING.md +2 -8
  9. data/lib/google/cloud/pubsub/acknowledge_result.rb +79 -0
  10. data/lib/google/cloud/pubsub/async_publisher/batch.rb +319 -0
  11. data/lib/google/cloud/pubsub/async_publisher.rb +231 -156
  12. data/lib/google/cloud/pubsub/batch_publisher.rb +60 -30
  13. data/lib/google/cloud/pubsub/convert.rb +33 -7
  14. data/lib/google/cloud/pubsub/credentials.rb +2 -2
  15. data/lib/google/cloud/pubsub/errors.rb +93 -0
  16. data/lib/google/cloud/pubsub/flow_controller.rb +137 -0
  17. data/lib/google/cloud/pubsub/message.rb +45 -4
  18. data/lib/google/cloud/pubsub/policy.rb +3 -2
  19. data/lib/google/cloud/pubsub/project.rb +316 -49
  20. data/lib/google/cloud/pubsub/publish_result.rb +6 -1
  21. data/lib/google/cloud/pubsub/received_message.rb +171 -10
  22. data/lib/google/cloud/pubsub/retry_policy.rb +88 -0
  23. data/lib/google/cloud/pubsub/schema/list.rb +180 -0
  24. data/lib/google/cloud/pubsub/schema.rb +310 -0
  25. data/lib/google/cloud/pubsub/service.rb +285 -269
  26. data/lib/google/cloud/pubsub/snapshot/list.rb +4 -6
  27. data/lib/google/cloud/pubsub/snapshot.rb +5 -2
  28. data/lib/google/cloud/pubsub/subscriber/inventory.rb +69 -32
  29. data/lib/google/cloud/pubsub/subscriber/sequencer.rb +115 -0
  30. data/lib/google/cloud/pubsub/subscriber/stream.rb +108 -49
  31. data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +191 -30
  32. data/lib/google/cloud/pubsub/subscriber.rb +155 -45
  33. data/lib/google/cloud/pubsub/subscription/list.rb +4 -6
  34. data/lib/google/cloud/pubsub/subscription/push_config.rb +55 -31
  35. data/lib/google/cloud/pubsub/subscription.rb +561 -77
  36. data/lib/google/cloud/pubsub/topic/list.rb +4 -6
  37. data/lib/google/cloud/pubsub/topic.rb +372 -52
  38. data/lib/google/cloud/pubsub/version.rb +1 -1
  39. data/lib/google/cloud/pubsub.rb +35 -46
  40. data/lib/google-cloud-pubsub.rb +21 -27
  41. metadata +26 -189
  42. data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
  43. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
  44. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
  45. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
  46. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
  47. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
  48. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
  49. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
  50. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -744
  51. data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
  52. data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -786
  53. data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -105
  54. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1385
  55. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -138
  56. data/lib/google/cloud/pubsub/v1.rb +0 -17
  57. data/lib/google/pubsub/v1/pubsub_pb.rb +0 -249
  58. data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -211
@@ -18,11 +18,15 @@ require "google/cloud/pubsub/service"
18
18
  require "google/cloud/pubsub/credentials"
19
19
  require "google/cloud/pubsub/topic"
20
20
  require "google/cloud/pubsub/batch_publisher"
21
+ require "google/cloud/pubsub/schema"
21
22
  require "google/cloud/pubsub/snapshot"
22
23
 
23
24
  module Google
24
25
  module Cloud
25
26
  module PubSub
27
+ DEFAULT_COMPRESS = false
28
+ DEFAULT_COMPRESSION_BYTES_THRESHOLD = 240
29
+
26
30
  ##
27
31
  # # Project
28
32
  #
@@ -72,13 +76,26 @@ module Google
72
76
  end
73
77
  alias project project_id
74
78
 
79
+ ##
80
+ # The universe domain the client is connected to
81
+ #
82
+ # @return [String]
83
+ #
84
+ def universe_domain
85
+ service.universe_domain
86
+ end
87
+
75
88
  ##
76
89
  # Retrieves topic by name.
77
90
  #
78
- # @param [String] topic_name Name of a topic.
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}`.
79
95
  # @param [String] project If the topic belongs to a project other than
80
96
  # the one currently connected to, the alternate project ID can be
81
- # specified here. Optional.
97
+ # specified here. Optional. Not used if a fully-qualified topic name
98
+ # is provided for `topic_name`.
82
99
  # @param [Boolean] skip_lookup Optionally create a {Topic} object
83
100
  # without verifying the topic resource exists on the Pub/Sub service.
84
101
  # Calls made on this object will raise errors if the topic resource
@@ -89,19 +106,28 @@ module Google
89
106
  #
90
107
  # Hash keys and values may include the following:
91
108
  #
92
- # * `:max_bytes` (Integer) The maximum size of messages to be
93
- # collected before the batch is published. Default is 10,000,000
94
- # (10MB).
95
- # * `:max_messages` (Integer) The maximum number of messages to be
96
- # collected before the batch is published. Default is 1,000.
97
- # * `:interval` (Numeric) The number of seconds to collect messages
98
- # before the batch is published. Default is 0.25.
99
- # * `:threads` (Hash) The number of threads to create to handle
100
- # concurrent calls by the publisher:
101
- # * `:publish` (Integer) The number of threads used to publish
102
- # messages. Default is 4.
103
- # * `:callback` (Integer) The number of threads to handle the
104
- # published messages' callbacks. Default is 8.
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`.
105
131
  #
106
132
  # @return [Google::Cloud::PubSub::Topic, nil] Returns `nil` if topic
107
133
  # does not exist.
@@ -145,13 +171,13 @@ module Google
145
171
  # end
146
172
  # end
147
173
  #
148
- # topic.async_publisher.stop.wait!
174
+ # topic.async_publisher.stop!
149
175
  #
150
176
  def topic topic_name, project: nil, skip_lookup: nil, async: nil
151
177
  ensure_service!
152
- options = { project: project }
178
+ options = { project: project, async: async }
153
179
  return Topic.from_name topic_name, service, options if skip_lookup
154
- grpc = service.get_topic topic_name
180
+ grpc = service.get_topic topic_name, options
155
181
  Topic.from_grpc grpc, service, async: async
156
182
  rescue Google::Cloud::NotFoundError
157
183
  nil
@@ -162,7 +188,16 @@ module Google
162
188
  ##
163
189
  # Creates a new topic.
164
190
  #
165
- # @param [String] topic_name Name of a topic.
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`.
166
201
  # @param [Hash] labels A hash of user-provided labels associated with
167
202
  # the topic. You can use these to organize and group your topics.
168
203
  # Label keys and values can be no longer than 63 characters, can only
@@ -183,19 +218,53 @@ module Google
183
218
  #
184
219
  # Hash keys and values may include the following:
185
220
  #
186
- # * `:max_bytes` (Integer) The maximum size of messages to be
187
- # collected before the batch is published. Default is 10,000,000
188
- # (10MB).
221
+ # * `:max_bytes` (Integer) The maximum size of messages to be collected
222
+ # before the batch is published. Default is 1,000,000 (1MB).
189
223
  # * `:max_messages` (Integer) The maximum number of messages to be
190
- # collected before the batch is published. Default is 1,000.
191
- # * `:interval` (Numeric) The number of seconds to collect messages
192
- # before the batch is published. Default is 0.25.
193
- # * `:threads` (Hash) The number of threads to create to handle
194
- # concurrent calls by the publisher:
195
- # * `:publish` (Integer) The number of threads used to publish
196
- # messages. Default is 4.
197
- # * `:callback` (Integer) The number of threads to handle the
198
- # published messages' callbacks. Default is 8.
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.
199
268
  #
200
269
  # @return [Google::Cloud::PubSub::Topic]
201
270
  #
@@ -205,13 +274,24 @@ module Google
205
274
  # pubsub = Google::Cloud::PubSub.new
206
275
  # topic = pubsub.create_topic "my-topic"
207
276
  #
208
- def create_topic topic_name, labels: nil, kms_key: nil,
209
- persistence_regions: nil, async: nil
277
+ def create_topic topic_name,
278
+ labels: nil,
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
210
286
  ensure_service!
211
287
  grpc = service.create_topic topic_name,
212
- labels: labels,
213
- kms_key_name: kms_key,
214
- persistence_regions: persistence_regions
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
215
295
  Topic.from_grpc grpc, service, async: async
216
296
  end
217
297
  alias new_topic create_topic
@@ -259,10 +339,14 @@ module Google
259
339
  ##
260
340
  # Retrieves subscription by name.
261
341
  #
262
- # @param [String] subscription_name Name of a subscription.
342
+ # @param [String] subscription_name Name of a subscription. The value can
343
+ # be a simple subscription ID, in which case the current project ID
344
+ # will be supplied, or a fully-qualified subscription name in the form
345
+ # `projects/{project_id}/subscriptions/{subscription_id}`.
263
346
  # @param [String] project If the subscription belongs to a project other
264
347
  # than the one currently connected to, the alternate project ID can be
265
- # specified here.
348
+ # specified here. Not used if a fully-qualified subscription name is
349
+ # provided for `subscription_name`.
266
350
  # @param [Boolean] skip_lookup Optionally create a {Subscription} object
267
351
  # without verifying the subscription resource exists on the Pub/Sub
268
352
  # service. Calls made on this object will raise errors if the service
@@ -291,10 +375,8 @@ module Google
291
375
  def subscription subscription_name, project: nil, skip_lookup: nil
292
376
  ensure_service!
293
377
  options = { project: project }
294
- if skip_lookup
295
- return Subscription.from_name subscription_name, service, options
296
- end
297
- grpc = service.get_subscription subscription_name
378
+ return Subscription.from_name subscription_name, service, options if skip_lookup
379
+ grpc = service.get_subscription subscription_name, options
298
380
  Subscription.from_grpc grpc, service
299
381
  rescue Google::Cloud::NotFoundError
300
382
  nil
@@ -381,6 +463,198 @@ module Google
381
463
  alias find_snapshots snapshots
382
464
  alias list_snapshots snapshots
383
465
 
466
+ ##
467
+ # Retrieves schema by name.
468
+ #
469
+ # @param [String] schema_name Name of a schema. The value can
470
+ # be a simple schema ID, in which case the current project ID
471
+ # will be supplied, or a fully-qualified schema name in the form
472
+ # `projects/{project_id}/schemas/{schema_id}`.
473
+ # @param view [Symbol, String, nil] Possible values:
474
+ # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
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
531
+ end
532
+ alias get_schema schema
533
+ alias find_schema schema
534
+
535
+ ##
536
+ # Creates a new schema.
537
+ #
538
+ # @param [String] schema_id The ID to use for the schema, which will
539
+ # become the final component of the schema's resource name. Required.
540
+ #
541
+ # The schema ID (relative name) must start with a letter, and
542
+ # contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
543
+ # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
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
574
+ end
575
+ alias new_schema create_schema
576
+
577
+ ##
578
+ # Retrieves a list of schemas for the given project.
579
+ #
580
+ # @param view [String, Symbol, nil] The set of fields to return in the response. Possible values:
581
+ #
582
+ # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
583
+ # * `FULL` - Include all Schema object fields.
584
+ #
585
+ # The default value is `FULL`.
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
619
+ end
620
+ alias find_schemas schemas
621
+ alias list_schemas schemas
622
+
623
+ ##
624
+ # Validates a schema type and definition.
625
+ #
626
+ # @param [String, Symbol] type The type of the schema. Required. Possible
627
+ # values are case-insensitive and include:
628
+ #
629
+ # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
630
+ # * `AVRO` - An Avro schema definition.
631
+ # @param [String] definition The definition of the schema. Required. This
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
655
+ end
656
+ alias validate_schema valid_schema?
657
+
384
658
  protected
385
659
 
386
660
  ##
@@ -389,13 +663,6 @@ module Google
389
663
  def ensure_service!
390
664
  raise "Must have active connection to service" unless service
391
665
  end
392
-
393
- ##
394
- # Call the publish API with arrays of data data and attrs.
395
- def publish_batch_messages topic_name, batch
396
- grpc = service.publish topic_name, batch.messages
397
- batch.to_gcloud_messages Array(grpc.message_ids)
398
- end
399
666
  end
400
667
  end
401
668
 
@@ -17,7 +17,12 @@ module Google
17
17
  module Cloud
18
18
  module PubSub
19
19
  ##
20
- # # PublishResult
20
+ # The result of a publish operation. The message object is available on
21
+ # {#message} and will have {#message_id} assigned by the API.
22
+ #
23
+ # When the publish operation was successful the result will be marked
24
+ # {#succeeded?}. Otherwise, the result will be marked {#failed?} and the
25
+ # error raised will be availabe on {#error}.
21
26
  #
22
27
  class PublishResult
23
28
  ##