google-cloud-pubsub 0.20.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +18 -0
  3. data/AUTHENTICATION.md +178 -0
  4. data/CHANGELOG.md +659 -0
  5. data/CODE_OF_CONDUCT.md +40 -0
  6. data/CONTRIBUTING.md +187 -0
  7. data/EMULATOR.md +37 -0
  8. data/LICENSE +201 -0
  9. data/LOGGING.md +32 -0
  10. data/OVERVIEW.md +528 -0
  11. data/TROUBLESHOOTING.md +31 -0
  12. data/lib/google/cloud/pubsub/async_publisher/batch.rb +310 -0
  13. data/lib/google/cloud/pubsub/async_publisher.rb +402 -0
  14. data/lib/google/cloud/pubsub/batch_publisher.rb +100 -0
  15. data/lib/google/cloud/pubsub/convert.rb +91 -0
  16. data/lib/google/cloud/pubsub/credentials.rb +26 -10
  17. data/lib/google/cloud/pubsub/errors.rb +85 -0
  18. data/lib/google/cloud/pubsub/message.rb +82 -20
  19. data/lib/google/cloud/pubsub/policy.rb +40 -61
  20. data/lib/google/cloud/pubsub/project.rb +405 -265
  21. data/lib/google/cloud/pubsub/publish_result.rb +103 -0
  22. data/lib/google/cloud/pubsub/received_message.rb +165 -30
  23. data/lib/google/cloud/pubsub/retry_policy.rb +88 -0
  24. data/lib/google/cloud/pubsub/schema/list.rb +180 -0
  25. data/lib/google/cloud/pubsub/schema.rb +310 -0
  26. data/lib/google/cloud/pubsub/service.rb +304 -162
  27. data/lib/google/cloud/pubsub/snapshot/list.rb +178 -0
  28. data/lib/google/cloud/pubsub/snapshot.rb +205 -0
  29. data/lib/google/cloud/pubsub/subscriber/enumerator_queue.rb +54 -0
  30. data/lib/google/cloud/pubsub/subscriber/inventory.rb +173 -0
  31. data/lib/google/cloud/pubsub/subscriber/sequencer.rb +115 -0
  32. data/lib/google/cloud/pubsub/subscriber/stream.rb +400 -0
  33. data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +230 -0
  34. data/lib/google/cloud/pubsub/subscriber.rb +417 -0
  35. data/lib/google/cloud/pubsub/subscription/list.rb +38 -43
  36. data/lib/google/cloud/pubsub/subscription/push_config.rb +268 -0
  37. data/lib/google/cloud/pubsub/subscription.rb +1040 -210
  38. data/lib/google/cloud/pubsub/topic/list.rb +32 -37
  39. data/lib/google/cloud/pubsub/topic.rb +726 -177
  40. data/lib/google/cloud/pubsub/version.rb +6 -4
  41. data/lib/google/cloud/pubsub.rb +138 -413
  42. data/lib/google-cloud-pubsub.rb +60 -42
  43. metadata +88 -39
  44. data/lib/google/cloud/pubsub/topic/publisher.rb +0 -87
  45. data/lib/google/iam/v1/iam_policy.rb +0 -33
  46. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  47. data/lib/google/iam/v1/policy.rb +0 -25
  48. data/lib/google/pubsub/v1/pubsub_pb.rb +0 -129
  49. data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -117
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
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
- # http://www.apache.org/licenses/LICENSE-2.0
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,
@@ -17,7 +17,7 @@ require "google/cloud/errors"
17
17
 
18
18
  module Google
19
19
  module Cloud
20
- module Pubsub
20
+ module PubSub
21
21
  ##
22
22
  # # Policy
23
23
  #
@@ -27,7 +27,7 @@ module Google
27
27
  # is to read the current data from the service, update the data locally,
28
28
  # and then send the modified data for writing. This pattern may result in
29
29
  # a conflict if two or more processes attempt the sequence simultaneously.
30
- # IAM solves this problem with the {Google::Cloud::Pubsub::Policy#etag}
30
+ # IAM solves this problem with the {Google::Cloud::PubSub::Policy#etag}
31
31
  # property, which is used to verify whether the policy has changed since
32
32
  # the last request. When you make a request to with an `etag` value, Cloud
33
33
  # IAM compares the `etag` value in the request with the existing `etag`
@@ -37,12 +37,12 @@ module Google
37
37
  # When you update a policy, first read the policy (and its current `etag`)
38
38
  # from the service, then modify the policy locally, and then write the
39
39
  # modified policy to the service. See
40
- # {Google::Cloud::Pubsub::Topic#policy} and
41
- # {Google::Cloud::Pubsub::Topic#policy=}.
40
+ # {Google::Cloud::PubSub::Topic#policy} and
41
+ # {Google::Cloud::PubSub::Topic#policy=}.
42
42
  #
43
43
  # @see https://cloud.google.com/iam/docs/managing-policies Managing
44
44
  # policies
45
- # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
45
+ # @see https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#iampolicy
46
46
  # google.iam.v1.IAMPolicy
47
47
  #
48
48
  # @attr [String] etag Used to verify whether the policy has changed since
@@ -52,26 +52,24 @@ module Google
52
52
  # roles with an array of members. See [Understanding
53
53
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
54
54
  # listing of primitive and curated roles.
55
- # See [Binding](https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#binding)
55
+ # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
56
56
  # for a listing of values and patterns for members.
57
57
  #
58
58
  # @example
59
- # require "google/cloud"
59
+ # require "google/cloud/pubsub"
60
60
  #
61
- # gcloud = Google::Cloud.new
62
- # pubsub = gcloud.pubsub
61
+ # pubsub = Google::Cloud::PubSub.new
63
62
  # topic = pubsub.topic "my-topic"
64
63
  #
65
- # policy = topic.policy # API call
66
- #
67
- # policy.remove "roles/owner", "user:owner@example.com" # Local call
68
- # policy.add "roles/owner", "user:newowner@example.com" # Local call
69
- # policy.roles["roles/viewer"] = ["allUsers"] # Local call
70
- #
71
- # topic.policy = policy # API call
64
+ # topic.policy do |p|
65
+ # p.remove "roles/owner", "user:owner@example.com"
66
+ # p.add "roles/owner", "user:newowner@example.com"
67
+ # p.roles["roles/viewer"] = ["allUsers"]
68
+ # end
72
69
  #
73
70
  class Policy
74
- attr_reader :etag, :roles
71
+ attr_reader :etag
72
+ attr_reader :roles
75
73
 
76
74
  ##
77
75
  # @private Creates a Policy object.
@@ -85,7 +83,7 @@ module Google
85
83
  # See [Understanding
86
84
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
87
85
  # listing of primitive and curated roles.
88
- # See [Binding](https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#binding)
86
+ # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
89
87
  # for a listing of values and patterns for members.
90
88
  #
91
89
  # @param [String] role_name A Cloud IAM role, such as
@@ -94,17 +92,14 @@ module Google
94
92
  # `"user:owner@example.com"`.
95
93
  #
96
94
  # @example
97
- # require "google/cloud"
95
+ # require "google/cloud/pubsub"
98
96
  #
99
- # gcloud = Google::Cloud.new
100
- # pubsub = gcloud.pubsub
97
+ # pubsub = Google::Cloud::PubSub.new
101
98
  # topic = pubsub.topic "my-topic"
102
99
  #
103
- # policy = topic.policy # API call
104
- #
105
- # policy.add "roles/owner", "user:newowner@example.com" # Local call
106
- #
107
- # topic.policy = policy # API call
100
+ # topic.policy do |p|
101
+ # p.add "roles/owner", "user:newowner@example.com"
102
+ # end
108
103
  #
109
104
  def add role_name, member
110
105
  role(role_name) << member
@@ -115,7 +110,7 @@ module Google
115
110
  # policy. See [Understanding
116
111
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
117
112
  # listing of primitive and curated roles. See
118
- # [Binding](https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#binding)
113
+ # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
119
114
  # for a listing of values and patterns for members.
120
115
  #
121
116
  # @param [String] role_name A Cloud IAM role, such as
@@ -124,17 +119,14 @@ module Google
124
119
  # `"user:owner@example.com"`.
125
120
  #
126
121
  # @example
127
- # require "google/cloud"
122
+ # require "google/cloud/pubsub"
128
123
  #
129
- # gcloud = Google::Cloud.new
130
- # pubsub = gcloud.pubsub
124
+ # pubsub = Google::Cloud::PubSub.new
131
125
  # topic = pubsub.topic "my-topic"
132
126
  #
133
- # policy = topic.policy # API call
134
- #
135
- # policy.remove "roles/owner", "user:owner@example.com" # Local call
136
- #
137
- # topic.policy = policy # API call
127
+ # topic.policy do |p|
128
+ # p.remove "roles/owner", "user:owner@example.com"
129
+ # end
138
130
  #
139
131
  def remove role_name, member
140
132
  role(role_name).delete member
@@ -146,52 +138,37 @@ module Google
146
138
  # {#roles}. See [Understanding
147
139
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
148
140
  # listing of primitive and curated roles. See
149
- # [Binding](https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#binding)
141
+ # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
150
142
  # for a listing of values and patterns for members.
151
143
  #
152
144
  # @return [Array<String>] The members strings, or an empty array.
153
145
  #
154
146
  # @example
155
- # require "google/cloud"
147
+ # require "google/cloud/pubsub"
156
148
  #
157
- # gcloud = Google::Cloud.new
158
- # pubsub = gcloud.pubsub
149
+ # pubsub = Google::Cloud::PubSub.new
159
150
  # topic = pubsub.topic "my-topic"
160
151
  #
161
- # policy = topic.policy
162
- #
163
- # policy.role("roles/viewer") << "user:viewer@example.com"
152
+ # topic.policy do |p|
153
+ # p.role("roles/viewer") << "user:viewer@example.com"
154
+ # end
164
155
  #
165
156
  def role role_name
166
157
  roles[role_name] ||= []
167
158
  end
168
159
 
169
- ##
170
- # Returns a deep copy of the policy.
171
- #
172
- # @return [Policy]
173
- #
174
- def deep_dup
175
- dup.tap do |p|
176
- roles_dup = p.roles.each_with_object({}) do |(k, v), memo|
177
- memo[k] = v.dup rescue value
178
- end
179
- p.instance_variable_set "@roles", roles_dup
180
- end
181
- end
182
-
183
160
  ##
184
161
  # @private Convert the Policy to a Google::Iam::V1::Policy object.
185
162
  def to_grpc
186
163
  Google::Iam::V1::Policy.new(
187
- etag: etag,
164
+ etag: etag,
188
165
  bindings: roles.keys.map do |role_name|
189
166
  next if roles[role_name].empty?
190
167
  Google::Iam::V1::Binding.new(
191
- role: role_name,
168
+ role: role_name,
192
169
  members: roles[role_name]
193
170
  )
194
- end
171
+ end.compact
195
172
  )
196
173
  end
197
174
 
@@ -205,5 +182,7 @@ module Google
205
182
  end
206
183
  end
207
184
  end
185
+
186
+ Pubsub = PubSub unless const_defined? :Pubsub
208
187
  end
209
188
  end
@@ -1,10 +1,10 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
- # http://www.apache.org/licenses/LICENSE-2.0
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,
@@ -14,14 +14,16 @@
14
14
 
15
15
 
16
16
  require "google/cloud/errors"
17
- require "google/cloud/core/gce"
18
17
  require "google/cloud/pubsub/service"
19
18
  require "google/cloud/pubsub/credentials"
20
19
  require "google/cloud/pubsub/topic"
20
+ require "google/cloud/pubsub/batch_publisher"
21
+ require "google/cloud/pubsub/schema"
22
+ require "google/cloud/pubsub/snapshot"
21
23
 
22
24
  module Google
23
25
  module Cloud
24
- module Pubsub
26
+ module PubSub
25
27
  ##
26
28
  # # Project
27
29
  #
@@ -36,17 +38,16 @@ module Google
36
38
  # See {Google::Cloud#pubsub}
37
39
  #
38
40
  # @example
39
- # require "google/cloud"
41
+ # require "google/cloud/pubsub"
40
42
  #
41
- # gcloud = Google::Cloud.new
42
- # pubsub = gcloud.pubsub
43
+ # pubsub = Google::Cloud::PubSub.new
43
44
  #
44
45
  # topic = pubsub.topic "my-topic"
45
46
  # topic.publish "task completed"
46
47
  #
47
48
  class Project
48
49
  ##
49
- # @private The gRPC Service object.
50
+ # @private The Service object.
50
51
  attr_accessor :service
51
52
 
52
53
  ##
@@ -58,118 +59,191 @@ module Google
58
59
  # The Pub/Sub project connected to.
59
60
  #
60
61
  # @example
61
- # require "google/cloud"
62
+ # require "google/cloud/pubsub"
62
63
  #
63
- # gcloud = Google::Cloud.new "my-todo-project",
64
- # "/path/to/keyfile.json"
65
- # pubsub = gcloud.pubsub
64
+ # pubsub = Google::Cloud::PubSub.new(
65
+ # project_id: "my-project",
66
+ # credentials: "/path/to/keyfile.json"
67
+ # )
66
68
  #
67
- # pubsub.project #=> "my-todo-project"
69
+ # pubsub.project_id #=> "my-project"
68
70
  #
69
- def project
71
+ def project_id
70
72
  service.project
71
73
  end
72
-
73
- ##
74
- # @private Default project.
75
- def self.default_project
76
- ENV["PUBSUB_PROJECT"] ||
77
- ENV["GOOGLE_CLOUD_PROJECT"] ||
78
- ENV["GCLOUD_PROJECT"] ||
79
- Google::Cloud::Core::GCE.project_id
80
- end
74
+ alias project project_id
81
75
 
82
76
  ##
83
77
  # Retrieves topic by name.
84
78
  #
85
- # The topic will be created if the topic does not exist and the
86
- # `autocreate` option is set to true.
87
- #
88
- # @param [String] topic_name Name of a topic.
89
- # @param [Boolean] autocreate Flag to control whether the requested
90
- # topic will be created if it does not exist. Ignored if `skip_lookup`
91
- # is `true`. The default value is `false`.
79
+ # @param [String] topic_name Name of a topic. The value can be a simple
80
+ # topic ID (relative name), in which case the current project ID will
81
+ # be supplied, or a fully-qualified topic name in the form
82
+ # `projects/{project_id}/topics/{topic_id}`.
92
83
  # @param [String] project If the topic belongs to a project other than
93
84
  # the one currently connected to, the alternate project ID can be
94
- # specified here.
85
+ # specified here. Optional. Not used if a fully-qualified topic name
86
+ # is provided for `topic_name`.
95
87
  # @param [Boolean] skip_lookup Optionally create a {Topic} object
96
88
  # without verifying the topic resource exists on the Pub/Sub service.
97
89
  # Calls made on this object will raise errors if the topic resource
98
- # does not exist. Default is `false`.
99
- #
100
- # @return [Google::Cloud::Pubsub::Topic, nil] Returns `nil` if topic
101
- # does not exist. Will return a newly created{
102
- # Google::Cloud::Pubsub::Topic} if the topic does not exist and
103
- # `autocreate` is set to `true`.
90
+ # does not exist. Default is `false`. Optional.
91
+ # @param [Hash] async A hash of values to configure the topic's
92
+ # {AsyncPublisher} that is created when {Topic#publish_async}
93
+ # is called. Optional.
94
+ #
95
+ # Hash keys and values may include the following:
96
+ #
97
+ # * `:max_bytes` (Integer) The maximum size of messages to be collected before the batch is published. Default
98
+ # is 1,000,000 (1MB).
99
+ # * `:max_messages` (Integer) The maximum number of messages to be collected before the batch is published.
100
+ # Default is 100.
101
+ # * `:interval` (Numeric) The number of seconds to collect messages before the batch is published. Default is
102
+ # 0.01.
103
+ # * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
104
+ # * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
105
+ # * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
106
+ #
107
+ # @return [Google::Cloud::PubSub::Topic, nil] Returns `nil` if topic
108
+ # does not exist.
104
109
  #
105
110
  # @example
106
- # require "google/cloud"
111
+ # require "google/cloud/pubsub"
107
112
  #
108
- # gcloud = Google::Cloud.new
109
- # pubsub = gcloud.pubsub
113
+ # pubsub = Google::Cloud::PubSub.new
110
114
  # topic = pubsub.topic "existing-topic"
111
115
  #
112
116
  # @example By default `nil` will be returned if topic does not exist.
113
- # require "google/cloud"
114
- #
115
- # gcloud = Google::Cloud.new
116
- # pubsub = gcloud.pubsub
117
- # topic = pubsub.topic "non-existing-topic" #=> nil
118
- #
119
- # @example With the `autocreate` option set to `true`.
120
- # require "google/cloud"
117
+ # require "google/cloud/pubsub"
121
118
  #
122
- # gcloud = Google::Cloud.new
123
- # pubsub = gcloud.pubsub
124
- # topic = pubsub.topic "non-existing-topic", autocreate: true
119
+ # pubsub = Google::Cloud::PubSub.new
120
+ # topic = pubsub.topic "non-existing-topic" # nil
125
121
  #
126
122
  # @example Create topic in a different project with the `project` flag.
127
- # require "google/cloud"
123
+ # require "google/cloud/pubsub"
128
124
  #
129
- # gcloud = Google::Cloud.new
130
- # pubsub = gcloud.pubsub
125
+ # pubsub = Google::Cloud::PubSub.new
131
126
  # topic = pubsub.topic "another-topic", project: "another-project"
132
127
  #
133
128
  # @example Skip the lookup against the service with `skip_lookup`:
134
- # require "google/cloud"
129
+ # require "google/cloud/pubsub"
135
130
  #
136
- # gcloud = Google::Cloud.new
137
- # pubsub = gcloud.pubsub
131
+ # pubsub = Google::Cloud::PubSub.new
138
132
  # topic = pubsub.topic "another-topic", skip_lookup: true
139
133
  #
140
- def topic topic_name, autocreate: nil, project: nil, skip_lookup: nil
134
+ # @example Configuring AsyncPublisher to increase concurrent callbacks:
135
+ # require "google/cloud/pubsub"
136
+ #
137
+ # pubsub = Google::Cloud::PubSub.new
138
+ # topic = pubsub.topic "my-topic",
139
+ # async: { threads: { callback: 16 } }
140
+ #
141
+ # topic.publish_async "task completed" do |result|
142
+ # if result.succeeded?
143
+ # log_publish_success result.data
144
+ # else
145
+ # log_publish_failure result.data, result.error
146
+ # end
147
+ # end
148
+ #
149
+ # topic.async_publisher.stop!
150
+ #
151
+ def topic topic_name, project: nil, skip_lookup: nil, async: nil
141
152
  ensure_service!
142
153
  options = { project: project }
143
- return Topic.new_lazy(topic_name, service, options) if skip_lookup
144
- grpc = service.get_topic topic_name
145
- Topic.from_grpc grpc, service
154
+ return Topic.from_name topic_name, service, options if skip_lookup
155
+ grpc = service.get_topic topic_name, options
156
+ Topic.from_grpc grpc, service, async: async
146
157
  rescue Google::Cloud::NotFoundError
147
- return create_topic(topic_name) if autocreate
148
158
  nil
149
159
  end
150
- alias_method :get_topic, :topic
151
- alias_method :find_topic, :topic
160
+ alias get_topic topic
161
+ alias find_topic topic
152
162
 
153
163
  ##
154
164
  # Creates a new topic.
155
165
  #
156
- # @param [String] topic_name Name of a topic.
157
- #
158
- # @return [Google::Cloud::Pubsub::Topic]
166
+ # @param [String] topic_name Name of a topic. Required.
167
+ # The value can be a simple topic ID (relative name), in which
168
+ # case the current project ID will be supplied, or a fully-qualified
169
+ # topic name in the form `projects/{project_id}/topics/{topic_id}`.
170
+ #
171
+ # The topic ID (relative name) must start with a letter, and
172
+ # contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
173
+ # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
174
+ # signs (`%`). It must be between 3 and 255 characters in length, and
175
+ # it must not start with `goog`.
176
+ # @param [Hash] labels A hash of user-provided labels associated with
177
+ # the topic. You can use these to organize and group your topics.
178
+ # Label keys and values can be no longer than 63 characters, can only
179
+ # contain lowercase letters, numeric characters, underscores and
180
+ # dashes. International characters are allowed. Label values are
181
+ # optional. Label keys must start with a letter and each label in the
182
+ # list must have a different key. See [Creating and Managing
183
+ # Labels](https://cloud.google.com/pubsub/docs/labels).
184
+ # @param [String] kms_key The Cloud KMS encryption key that will be used
185
+ # to protect access to messages published on this topic. Optional.
186
+ # For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
187
+ # @param [Array<String>] persistence_regions The list of GCP region IDs
188
+ # where messages that are published to the topic may be persisted in
189
+ # storage. Optional.
190
+ # @param [Hash] async A hash of values to configure the topic's
191
+ # {AsyncPublisher} that is created when {Topic#publish_async}
192
+ # is called. Optional.
193
+ #
194
+ # Hash keys and values may include the following:
195
+ #
196
+ # * `:max_bytes` (Integer) The maximum size of messages to be collected
197
+ # before the batch is published. Default is 1,000,000 (1MB).
198
+ # * `:max_messages` (Integer) The maximum number of messages to be
199
+ # collected before the batch is published. Default is 100.
200
+ # * `:interval` (Numeric) The number of seconds to collect messages before
201
+ # the batch is published. Default is 0.01.
202
+ # * `:threads` (Hash) The number of threads to create to handle concurrent
203
+ # calls by the publisher:
204
+ #
205
+ # * `:publish` (Integer) The number of threads used to publish messages.
206
+ # Default is 2.
207
+ # * `:callback` (Integer) The number of threads to handle the published
208
+ # messages' callbacks. Default is 4.
209
+ # @param [String] schema_name The name of the schema that messages
210
+ # published should be validated against. Optional. The value can be a
211
+ # simple schema ID (relative name), in which case the current project
212
+ # ID will be supplied, or a fully-qualified schema name in the form
213
+ # `projects/{project_id}/schemas/{schema_id}`. If provided,
214
+ # `message_encoding` must also be provided.
215
+ # @param [String, Symbol] message_encoding The encoding of messages validated
216
+ # against the schema identified by `schema_name`. Optional. Values include:
217
+ #
218
+ # * `JSON` - JSON encoding.
219
+ # * `BINARY` - Binary encoding, as defined by the schema type. For some
220
+ # schema types, binary encoding may not be available.
221
+ #
222
+ # @return [Google::Cloud::PubSub::Topic]
159
223
  #
160
224
  # @example
161
- # require "google/cloud"
225
+ # require "google/cloud/pubsub"
162
226
  #
163
- # gcloud = Google::Cloud.new
164
- # pubsub = gcloud.pubsub
227
+ # pubsub = Google::Cloud::PubSub.new
165
228
  # topic = pubsub.create_topic "my-topic"
166
229
  #
167
- def create_topic topic_name
230
+ def create_topic topic_name,
231
+ labels: nil,
232
+ kms_key: nil,
233
+ persistence_regions: nil,
234
+ async: nil,
235
+ schema_name: nil,
236
+ message_encoding: nil
168
237
  ensure_service!
169
- grpc = service.create_topic topic_name
170
- Topic.from_grpc grpc, service
238
+ grpc = service.create_topic topic_name,
239
+ labels: labels,
240
+ kms_key_name: kms_key,
241
+ persistence_regions: persistence_regions,
242
+ schema_name: schema_name,
243
+ message_encoding: message_encoding
244
+ Topic.from_grpc grpc, service, async: async
171
245
  end
172
- alias_method :new_topic, :create_topic
246
+ alias new_topic create_topic
173
247
 
174
248
  ##
175
249
  # Retrieves a list of topics for the given project.
@@ -179,14 +253,13 @@ module Google
179
253
  # the system should return the next page of data.
180
254
  # @param [Integer] max Maximum number of topics to return.
181
255
  #
182
- # @return [Array<Google::Cloud::Pubsub::Topic>] (See
183
- # {Google::Cloud::Pubsub::Topic::List})
256
+ # @return [Array<Google::Cloud::PubSub::Topic>] (See
257
+ # {Google::Cloud::PubSub::Topic::List})
184
258
  #
185
259
  # @example
186
- # require "google/cloud"
260
+ # require "google/cloud/pubsub"
187
261
  #
188
- # gcloud = Google::Cloud.new
189
- # pubsub = gcloud.pubsub
262
+ # pubsub = Google::Cloud::PubSub.new
190
263
  #
191
264
  # topics = pubsub.topics
192
265
  # topics.each do |topic|
@@ -194,10 +267,9 @@ module Google
194
267
  # end
195
268
  #
196
269
  # @example Retrieve all topics: (See {Topic::List#all})
197
- # require "google/cloud"
270
+ # require "google/cloud/pubsub"
198
271
  #
199
- # gcloud = Google::Cloud.new
200
- # pubsub = gcloud.pubsub
272
+ # pubsub = Google::Cloud::PubSub.new
201
273
  #
202
274
  # topics = pubsub.topics
203
275
  # topics.all do |topic|
@@ -210,255 +282,327 @@ module Google
210
282
  grpc = service.list_topics options
211
283
  Topic::List.from_grpc grpc, service, max
212
284
  end
213
- alias_method :find_topics, :topics
214
- alias_method :list_topics, :topics
285
+ alias find_topics topics
286
+ alias list_topics topics
215
287
 
216
288
  ##
217
- # Publishes one or more messages to the given topic. The topic will be
218
- # created if the topic does previously not exist and the `autocreate`
219
- # option is provided.
220
- #
221
- # A note about auto-creating the topic: Any message published to a topic
222
- # without a subscription will be lost.
223
- #
224
- # @param [String] topic_name Name of a topic.
225
- # @param [String, File] data The message data.
226
- # @param [Hash] attributes Optional attributes for the message.
227
- # @option attributes [Boolean] :autocreate Flag to control whether the
228
- # provided topic will be created if it does not exist.
229
- # @yield [publisher] a block for publishing multiple messages in one
230
- # request
231
- # @yieldparam [Topic::Publisher] publisher the topic publisher object
232
- #
233
- # @return [Message, Array<Message>] Returns the published message when
234
- # called without a block, or an array of messages when called with a
235
- # block.
289
+ # Retrieves subscription by name.
290
+ #
291
+ # @param [String] subscription_name Name of a subscription. The value can
292
+ # be a simple subscription ID, in which case the current project ID
293
+ # will be supplied, or a fully-qualified subscription name in the form
294
+ # `projects/{project_id}/subscriptions/{subscription_id}`.
295
+ # @param [String] project If the subscription belongs to a project other
296
+ # than the one currently connected to, the alternate project ID can be
297
+ # specified here. Not used if a fully-qualified subscription name is
298
+ # provided for `subscription_name`.
299
+ # @param [Boolean] skip_lookup Optionally create a {Subscription} object
300
+ # without verifying the subscription resource exists on the Pub/Sub
301
+ # service. Calls made on this object will raise errors if the service
302
+ # resource does not exist. Default is `false`.
303
+ #
304
+ # @return [Google::Cloud::PubSub::Subscription, nil] Returns `nil` if
305
+ # the subscription does not exist
236
306
  #
237
307
  # @example
238
- # require "google/cloud"
308
+ # require "google/cloud/pubsub"
239
309
  #
240
- # gcloud = Google::Cloud.new
241
- # pubsub = gcloud.pubsub
310
+ # pubsub = Google::Cloud::PubSub.new
242
311
  #
243
- # msg = pubsub.publish "my-topic", "new-message"
312
+ # sub = pubsub.subscription "my-sub"
313
+ # sub.name #=> "projects/my-project/subscriptions/my-sub"
244
314
  #
245
- # @example A message can be published using a File object:
246
- # require "google/cloud"
315
+ # @example Skip the lookup against the service with `skip_lookup`:
316
+ # require "google/cloud/pubsub"
247
317
  #
248
- # gcloud = Google::Cloud.new
249
- # pubsub = gcloud.pubsub
318
+ # pubsub = Google::Cloud::PubSub.new
250
319
  #
251
- # msg = pubsub.publish "my-topic", File.open("message.txt")
320
+ # # No API call is made to retrieve the subscription information.
321
+ # sub = pubsub.subscription "my-sub", skip_lookup: true
322
+ # sub.name #=> "projects/my-project/subscriptions/my-sub"
252
323
  #
253
- # @example Additionally, a message can be published with attributes:
254
- # require "google/cloud"
324
+ def subscription subscription_name, project: nil, skip_lookup: nil
325
+ ensure_service!
326
+ options = { project: project }
327
+ return Subscription.from_name subscription_name, service, options if skip_lookup
328
+ grpc = service.get_subscription subscription_name, options
329
+ Subscription.from_grpc grpc, service
330
+ rescue Google::Cloud::NotFoundError
331
+ nil
332
+ end
333
+ alias get_subscription subscription
334
+ alias find_subscription subscription
335
+
336
+ ##
337
+ # Retrieves a list of subscriptions for the given project.
255
338
  #
256
- # gcloud = Google::Cloud.new
257
- # pubsub = gcloud.pubsub
339
+ # @param [String] token A previously-returned page token representing
340
+ # part of the larger set of results to view.
341
+ # @param [Integer] max Maximum number of subscriptions to return.
258
342
  #
259
- # msg = pubsub.publish "my-topic", "new-message", foo: :bar,
260
- # this: :that
343
+ # @return [Array<Google::Cloud::PubSub::Subscription>] (See
344
+ # {Google::Cloud::PubSub::Subscription::List})
261
345
  #
262
- # @example Multiple messages can be sent at the same time using a block:
263
- # require "google/cloud"
346
+ # @example
347
+ # require "google/cloud/pubsub"
264
348
  #
265
- # gcloud = Google::Cloud.new
266
- # pubsub = gcloud.pubsub
349
+ # pubsub = Google::Cloud::PubSub.new
267
350
  #
268
- # msgs = pubsub.publish "my-topic" do |p|
269
- # p.publish "new-message-1", foo: :bar
270
- # p.publish "new-message-2", foo: :baz
271
- # p.publish "new-message-3", foo: :bif
351
+ # subs = pubsub.subscriptions
352
+ # subs.each do |sub|
353
+ # puts sub.name
272
354
  # end
273
355
  #
274
- # @example With `autocreate`:
275
- # require "google/cloud"
356
+ # @example Retrieve all subscriptions: (See {Subscription::List#all})
357
+ # require "google/cloud/pubsub"
276
358
  #
277
- # gcloud = Google::Cloud.new
278
- # pubsub = gcloud.pubsub
359
+ # pubsub = Google::Cloud::PubSub.new
279
360
  #
280
- # msg = pubsub.publish "new-topic", "new-message", autocreate: true
361
+ # subs = pubsub.subscriptions
362
+ # subs.all do |sub|
363
+ # puts sub.name
364
+ # end
281
365
  #
282
- def publish topic_name, data = nil, attributes = {}
283
- # Fix parameters
284
- if data.is_a?(::Hash) && attributes.empty?
285
- attributes = data
286
- data = nil
287
- end
288
- # extract autocreate option
289
- autocreate = attributes.delete :autocreate
366
+ def subscriptions token: nil, max: nil
290
367
  ensure_service!
291
- publisher = Topic::Publisher.new data, attributes
292
- yield publisher if block_given?
293
- return nil if publisher.messages.count.zero?
294
- publish_batch_messages topic_name, publisher, autocreate
368
+ options = { token: token, max: max }
369
+ grpc = service.list_subscriptions options
370
+ Subscription::List.from_grpc grpc, service, max
295
371
  end
372
+ alias find_subscriptions subscriptions
373
+ alias list_subscriptions subscriptions
374
+
296
375
 
297
376
  ##
298
- # Creates a new {Subscription} object for the provided topic. The topic
299
- # will be created if the topic does previously not exist and the
300
- # `autocreate` option is provided.
301
- #
302
- # @param [String] topic_name Name of a topic.
303
- # @param [String] subscription_name Name of the new subscription. Must
304
- # start with a letter, and contain only letters ([A-Za-z]), numbers
305
- # ([0-9], dashes (-), underscores (_), periods (.), tildes (~), plus
306
- # (+) or percent signs (%). It must be between 3 and 255 characters in
307
- # length, and it must not start with "goog".
308
- # @param [Integer] deadline The maximum number of seconds after a
309
- # subscriber receives a message before the subscriber should
310
- # acknowledge the message.
311
- # @param [String] endpoint A URL locating the endpoint to which messages
312
- # should be pushed.
313
- # @param [String] autocreate Flag to control whether the topic will be
314
- # created if it does not exist.
315
- #
316
- # @return [Google::Cloud::Pubsub::Subscription]
377
+ # Retrieves a list of snapshots for the given project.
317
378
  #
318
- # @example
319
- # require "google/cloud"
320
- #
321
- # gcloud = Google::Cloud.new
322
- # pubsub = gcloud.pubsub
323
- #
324
- # sub = pubsub.subscribe "my-topic", "my-topic-sub"
325
- # puts sub.name # => "my-topic-sub"
326
- #
327
- # @example The name is optional, and will be generated if not given.
328
- # require "google/cloud"
329
- #
330
- # gcloud = Google::Cloud.new
331
- # pubsub = gcloud.pubsub
379
+ # @param [String] token A previously-returned page token representing
380
+ # part of the larger set of results to view.
381
+ # @param [Integer] max Maximum number of snapshots to return.
332
382
  #
333
- # sub = pubsub.subscribe "my-topic"
334
- # puts sub.name # => "generated-sub-name"
383
+ # @return [Array<Google::Cloud::PubSub::Snapshot>] (See
384
+ # {Google::Cloud::PubSub::Snapshot::List})
335
385
  #
336
- # @example Wait 2 minutes for acknowledgement and push all to endpoint:
337
- # require "google/cloud"
386
+ # @example
387
+ # require "google/cloud/pubsub"
338
388
  #
339
- # gcloud = Google::Cloud.new
340
- # pubsub = gcloud.pubsub
389
+ # pubsub = Google::Cloud::PubSub.new
341
390
  #
342
- # sub = pubsub.subscribe "my-topic", "my-topic-sub",
343
- # deadline: 120,
344
- # endpoint: "https://example.com/push"
391
+ # snapshots = pubsub.snapshots
392
+ # snapshots.each do |snapshot|
393
+ # puts snapshot.name
394
+ # end
345
395
  #
346
- # @example With `autocreate`:
347
- # require "google/cloud"
396
+ # @example Retrieve all snapshots: (See {Snapshot::List#all})
397
+ # require "google/cloud/pubsub"
348
398
  #
349
- # gcloud = Google::Cloud.new
350
- # pubsub = gcloud.pubsub
399
+ # pubsub = Google::Cloud::PubSub.new
351
400
  #
352
- # sub = pubsub.subscribe "new-topic", "new-topic-sub",
353
- # autocreate: true
401
+ # snapshots = pubsub.snapshots
402
+ # snapshots.all do |snapshot|
403
+ # puts snapshot.name
404
+ # end
354
405
  #
355
- def subscribe topic_name, subscription_name, deadline: nil,
356
- endpoint: nil, autocreate: nil
406
+ def snapshots token: nil, max: nil
357
407
  ensure_service!
358
- options = { deadline: deadline, endpoint: endpoint }
359
- grpc = service.create_subscription topic_name,
360
- subscription_name, options
361
- Subscription.from_grpc grpc, service
362
- rescue Google::Cloud::NotFoundError => e
363
- if autocreate
364
- create_topic topic_name
365
- return subscribe(topic_name, subscription_name,
366
- deadline: deadline, endpoint: endpoint,
367
- autocreate: false)
368
- end
369
- raise e
408
+ options = { token: token, max: max }
409
+ grpc = service.list_snapshots options
410
+ Snapshot::List.from_grpc grpc, service, max
370
411
  end
371
- alias_method :create_subscription, :subscribe
372
- alias_method :new_subscription, :subscribe
412
+ alias find_snapshots snapshots
413
+ alias list_snapshots snapshots
373
414
 
374
415
  ##
375
- # Retrieves subscription by name.
376
- #
377
- # @param [String] subscription_name Name of a subscription.
378
- # @param [String] project If the subscription belongs to a project other
416
+ # Retrieves schema by name.
417
+ #
418
+ # @param [String] schema_name Name of a schema. The value can
419
+ # be a simple schema ID, in which case the current project ID
420
+ # will be supplied, or a fully-qualified schema name in the form
421
+ # `projects/{project_id}/schemas/{schema_id}`.
422
+ # @param view [Symbol, String, nil] Possible values:
423
+ # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
424
+ # * `FULL` - Include all Schema object fields.
425
+ #
426
+ # The default value is `BASIC`.
427
+ # @param [String] project If the schema belongs to a project other
379
428
  # than the one currently connected to, the alternate project ID can be
380
- # specified here.
381
- # @param [Boolean] skip_lookup Optionally create a {Subscription} object
382
- # without verifying the subscription resource exists on the Pub/Sub
429
+ # specified here. Not used if a fully-qualified schema name is
430
+ # provided for `schema_name`.
431
+ # @param [Boolean] skip_lookup Optionally create a {Schema} object
432
+ # without verifying the schema resource exists on the Pub/Sub
383
433
  # service. Calls made on this object will raise errors if the service
384
434
  # resource does not exist. Default is `false`.
385
435
  #
386
- # @return [Google::Cloud::Pubsub::Subscription, nil] Returns `nil` if
387
- # the subscription does not exist
436
+ # @return [Google::Cloud::PubSub::Schema, nil] Returns `nil` if
437
+ # the schema does not exist.
388
438
  #
389
439
  # @example
390
- # require "google/cloud"
440
+ # require "google/cloud/pubsub"
391
441
  #
392
- # gcloud = Google::Cloud.new
393
- # pubsub = gcloud.pubsub
442
+ # pubsub = Google::Cloud::PubSub.new
394
443
  #
395
- # subscription = pubsub.subscription "my-sub"
396
- # puts subscription.name
444
+ # schema = pubsub.schema "my-schema"
445
+ # schema.name #=> "projects/my-project/schemas/my-schema"
446
+ # schema.type #=> :PROTOCOL_BUFFER
447
+ # # schema.definition # nil - Use view: :full to load complete resource.
397
448
  #
398
449
  # @example Skip the lookup against the service with `skip_lookup`:
399
- # require "google/cloud"
450
+ # require "google/cloud/pubsub"
400
451
  #
401
- # gcloud = Google::Cloud.new
402
- # pubsub = gcloud.pubsub
452
+ # pubsub = Google::Cloud::PubSub.new
403
453
  #
404
- # # No API call is made to retrieve the subscription information.
405
- # subscription = pubsub.subscription "my-sub", skip_lookup: true
406
- # puts subscription.name
454
+ # # No API call is made to retrieve the schema information.
455
+ # # The default project is used in the name.
456
+ # schema = pubsub.schema "my-schema", skip_lookup: true
457
+ # schema.name #=> "projects/my-project/schemas/my-schema"
458
+ # schema.type #=> nil
459
+ # schema.definition #=> nil
407
460
  #
408
- def subscription subscription_name, project: nil, skip_lookup: nil
461
+ # @example Get the schema definition with `view: :full`:
462
+ # require "google/cloud/pubsub"
463
+ #
464
+ # pubsub = Google::Cloud::PubSub.new
465
+ #
466
+ # schema = pubsub.schema "my-schema", view: :full
467
+ # schema.name #=> "projects/my-project/schemas/my-schema"
468
+ # schema.type #=> :PROTOCOL_BUFFER
469
+ # schema.definition # The schema definition
470
+ #
471
+ def schema schema_name, view: nil, project: nil, skip_lookup: nil
409
472
  ensure_service!
410
473
  options = { project: project }
411
- if skip_lookup
412
- return Subscription.new_lazy subscription_name, service, options
413
- end
414
- grpc = service.get_subscription subscription_name
415
- Subscription.from_grpc grpc, service
474
+ return Schema.from_name schema_name, view, service, options if skip_lookup
475
+ view ||= :BASIC
476
+ grpc = service.get_schema schema_name, view, options
477
+ Schema.from_grpc grpc, service
416
478
  rescue Google::Cloud::NotFoundError
417
479
  nil
418
480
  end
419
- alias_method :get_subscription, :subscription
420
- alias_method :find_subscription, :subscription
481
+ alias get_schema schema
482
+ alias find_schema schema
421
483
 
422
484
  ##
423
- # Retrieves a list of subscriptions for the given project.
485
+ # Creates a new schema.
486
+ #
487
+ # @param [String] schema_id The ID to use for the schema, which will
488
+ # become the final component of the schema's resource name. Required.
489
+ #
490
+ # The schema ID (relative name) must start with a letter, and
491
+ # contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
492
+ # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
493
+ # signs (`%`). It must be between 3 and 255 characters in length, and
494
+ # it must not start with `goog`.
495
+ # @param [String, Symbol] type The type of the schema. Required. Possible
496
+ # values are case-insensitive and include:
497
+ #
498
+ # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
499
+ # * `AVRO` - An Avro schema definition.
500
+ # @param [String] definition The definition of the schema. Required. This
501
+ # should be a string representing the full definition of the schema that
502
+ # is a valid schema definition of the type specified in `type`.
503
+ # @param [String] project If the schema belongs to a project other
504
+ # than the one currently connected to, the alternate project ID can be
505
+ # specified here. Optional.
424
506
  #
507
+ # @return [Google::Cloud::PubSub::Schema]
508
+ #
509
+ # @example
510
+ # require "google/cloud/pubsub"
511
+ #
512
+ # pubsub = Google::Cloud::PubSub.new
513
+ #
514
+ # definition = "..."
515
+ # schema = pubsub.create_schema "my-schema", :avro, definition
516
+ # schema.name #=> "projects/my-project/schemas/my-schema"
517
+ #
518
+ def create_schema schema_id, type, definition, project: nil
519
+ ensure_service!
520
+ type = type.to_s.upcase
521
+ grpc = service.create_schema schema_id, type, definition, project: project
522
+ Schema.from_grpc grpc, service
523
+ end
524
+ alias new_schema create_schema
525
+
526
+ ##
527
+ # Retrieves a list of schemas for the given project.
528
+ #
529
+ # @param view [String, Symbol, nil] The set of fields to return in the response. Possible values:
530
+ #
531
+ # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
532
+ # * `FULL` - Include all Schema object fields.
533
+ #
534
+ # The default value is `BASIC`.
425
535
  # @param [String] token A previously-returned page token representing
426
536
  # part of the larger set of results to view.
427
- # @param [Integer] max Maximum number of subscriptions to return.
537
+ # @param [Integer] max Maximum number of schemas to return.
428
538
  #
429
- # @return [Array<Google::Cloud::Pubsub::Subscription>] (See
430
- # {Google::Cloud::Pubsub::Subscription::List})
539
+ # @return [Array<Google::Cloud::PubSub::Schema>] (See
540
+ # {Google::Cloud::PubSub::Schema::List})
431
541
  #
432
542
  # @example
433
- # require "google/cloud"
543
+ # require "google/cloud/pubsub"
434
544
  #
435
- # gcloud = Google::Cloud.new
436
- # pubsub = gcloud.pubsub
545
+ # pubsub = Google::Cloud::PubSub.new
437
546
  #
438
- # subscriptions = pubsub.subscriptions
439
- # subscriptions.each do |subscription|
440
- # puts subscription.name
547
+ # schemas = pubsub.schemas
548
+ # schemas.each do |schema|
549
+ # puts schema.name
441
550
  # end
442
551
  #
443
- # @example Retrieve all subscriptions: (See {Subscription::List#all})
444
- # require "google/cloud"
552
+ # @example Retrieve all schemas: (See {Schema::List#all})
553
+ # require "google/cloud/pubsub"
445
554
  #
446
- # gcloud = Google::Cloud.new
447
- # pubsub = gcloud.pubsub
555
+ # pubsub = Google::Cloud::PubSub.new
448
556
  #
449
- # subscriptions = pubsub.subscriptions
450
- # subscriptions.all do |subscription|
451
- # puts subscription.name
557
+ # schemas = pubsub.schemas
558
+ # schemas.all do |schema|
559
+ # puts schema.name
452
560
  # end
453
561
  #
454
- def subscriptions token: nil, max: nil
562
+ def schemas view: nil, token: nil, max: nil
455
563
  ensure_service!
564
+ view ||= :BASIC
456
565
  options = { token: token, max: max }
457
- grpc = service.list_subscriptions options
458
- Subscription::List.from_grpc grpc, service, max
566
+ grpc = service.list_schemas view, options
567
+ Schema::List.from_grpc grpc, service, view, max
459
568
  end
460
- alias_method :find_subscriptions, :subscriptions
461
- alias_method :list_subscriptions, :subscriptions
569
+ alias find_schemas schemas
570
+ alias list_schemas schemas
571
+
572
+ ##
573
+ # Validates a schema type and definition.
574
+ #
575
+ # @param [String, Symbol] type The type of the schema. Required. Possible
576
+ # values are case-insensitive and include:
577
+ #
578
+ # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
579
+ # * `AVRO` - An Avro schema definition.
580
+ # @param [String] definition The definition of the schema. Required. This
581
+ # should be a string representing the full definition of the schema that
582
+ # is a valid schema definition of the type specified in `type`.
583
+ # @param [String] project If the schema belongs to a project other
584
+ # than the one currently connected to, the alternate project ID can be
585
+ # specified here. Optional.
586
+ #
587
+ # @return [Boolean] `true` if the schema is valid, `false` otherwise.
588
+ #
589
+ # @example
590
+ # require "google/cloud/pubsub"
591
+ #
592
+ # pubsub = Google::Cloud::PubSub.new
593
+ #
594
+ # definition = "..."
595
+ # pubsub.validate_schema :avro, definition #=> true
596
+ #
597
+ def valid_schema? type, definition, project: nil
598
+ ensure_service!
599
+ type = type.to_s.upcase
600
+ service.validate_schema type, definition, project: project # return type is empty
601
+ true
602
+ rescue Google::Cloud::InvalidArgumentError
603
+ false
604
+ end
605
+ alias validate_schema valid_schema?
462
606
 
463
607
  protected
464
608
 
@@ -466,22 +610,18 @@ module Google
466
610
  # @private Raise an error unless an active connection to the service is
467
611
  # available.
468
612
  def ensure_service!
469
- fail "Must have active connection to service" unless service
613
+ raise "Must have active connection to service" unless service
470
614
  end
471
615
 
472
616
  ##
473
617
  # Call the publish API with arrays of data data and attrs.
474
- def publish_batch_messages topic_name, batch, autocreate = false
618
+ def publish_batch_messages topic_name, batch
475
619
  grpc = service.publish topic_name, batch.messages
476
620
  batch.to_gcloud_messages Array(grpc.message_ids)
477
- rescue Google::Cloud::NotFoundError => e
478
- if autocreate
479
- create_topic topic_name
480
- return publish_batch_messages topic_name, batch, false
481
- end
482
- raise e
483
621
  end
484
622
  end
485
623
  end
624
+
625
+ Pubsub = PubSub unless const_defined? :Pubsub
486
626
  end
487
627
  end