google-cloud-pubsub 0.32.0 → 0.32.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +11 -2
- data/README.md +22 -12
- data/lib/google-cloud-pubsub.rb +5 -4
- data/lib/google/cloud/pubsub.rb +4 -490
- data/lib/google/cloud/pubsub/service.rb +1 -0
- data/lib/google/cloud/pubsub/topic.rb +2 -2
- data/lib/google/cloud/pubsub/v1/credentials.rb +1 -0
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +4 -3
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +5 -4
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +1 -0
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +1 -0
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +7 -0
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +9 -6
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +24 -23
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +11 -9
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +19 -17
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/pubsub/v1/pubsub_pb.rb +1 -0
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48356ab57faedf9942a2ad5d402c6f71297bc5a05f3b39e5479deb3f3be58546
|
4
|
+
data.tar.gz: a7e64b049fb79b6bc0adcc619ca98de9a7234c16be32c5e3a8dd601267df065b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2b484c364e220f79e2ae876614947731fa54a008703ce70ba9a78bea5462c20a2a05d236296cc3f44ebd0ef1b7a9408d7036016722eed922520a2bad3749065
|
7
|
+
data.tar.gz: bdca017d6084369de21feec4a31ed23c224b5526048d4f3f01a3d05559b5db5477fe71768080f15d0fa42cfaf3f7c26bec2b04bcd7b2d6af5c46a1380ea27f60
|
data/.yardopts
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
--no-private
|
2
2
|
--title=Google Cloud Pub/Sub
|
3
|
-
--exclude
|
3
|
+
--exclude _pb\.rb$
|
4
4
|
--markup markdown
|
5
5
|
--markup-provider redcarpet
|
6
|
+
--main OVERVIEW.md
|
6
7
|
|
7
8
|
./lib/**/*.rb
|
8
9
|
-
|
9
|
-
|
10
|
+
OVERVIEW.md
|
11
|
+
AUTHENTICATION.md
|
12
|
+
EMULATOR.md
|
13
|
+
LOGGING.md
|
14
|
+
CONTRIBUTING.md
|
15
|
+
TROUBLESHOOTING.md
|
16
|
+
CHANGELOG.md
|
17
|
+
CODE_OF_CONDUCT.md
|
18
|
+
LICENSE
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[Google Cloud Pub/Sub](https://cloud.google.com/pubsub/) ([docs](https://cloud.google.com/pubsub/docs/reference/rest/)) is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a “topic” and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.
|
4
4
|
|
5
|
-
- [google-cloud-pubsub API documentation](http://googlecloudplatform.github.io/google-cloud-ruby
|
5
|
+
- [google-cloud-pubsub API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest)
|
6
6
|
- [google-cloud-pubsub on RubyGems](https://rubygems.org/gems/google-cloud-pubsub)
|
7
7
|
- [Google Cloud Pub/Sub documentation](https://cloud.google.com/pubsub/docs)
|
8
8
|
|
@@ -16,7 +16,7 @@ $ gem install google-cloud-pubsub
|
|
16
16
|
|
17
17
|
This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
|
18
18
|
|
19
|
-
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby
|
19
|
+
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.AUTHENTICATION).
|
20
20
|
|
21
21
|
## Example
|
22
22
|
|
@@ -52,7 +52,7 @@ subscriber.stop.wait!
|
|
52
52
|
|
53
53
|
## Enabling Logging
|
54
54
|
|
55
|
-
To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby
|
55
|
+
To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
|
56
56
|
|
57
57
|
Configuring a Ruby stdlib logger:
|
58
58
|
|
@@ -77,9 +77,9 @@ end
|
|
77
77
|
This library is supported on Ruby 2.3+.
|
78
78
|
|
79
79
|
Google provides official support for Ruby versions that are actively supported
|
80
|
-
by Ruby Core—that is, Ruby versions that are either in normal maintenance or
|
81
|
-
|
82
|
-
|
80
|
+
by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
|
81
|
+
security maintenance, and not end of life. Currently, this means Ruby 2.3 and
|
82
|
+
later. Older versions of Ruby _may_ still work, but are unsupported and not
|
83
83
|
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
84
84
|
about the Ruby support schedule.
|
85
85
|
|
@@ -87,21 +87,31 @@ about the Ruby support schedule.
|
|
87
87
|
|
88
88
|
This library follows [Semantic Versioning](http://semver.org/).
|
89
89
|
|
90
|
-
It is currently in major version zero (0.y.z), which means that anything may
|
90
|
+
It is currently in major version zero (0.y.z), which means that anything may
|
91
|
+
change at any time and the public API should not be considered stable.
|
91
92
|
|
92
93
|
## Contributing
|
93
94
|
|
94
95
|
Contributions to this library are always welcome and highly encouraged.
|
95
96
|
|
96
|
-
See the [Contributing
|
97
|
+
See the [Contributing
|
98
|
+
Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.CONTRIBUTING)
|
99
|
+
for more information on how to get started.
|
97
100
|
|
98
|
-
Please note that this project is released with a Contributor Code of Conduct. By
|
101
|
+
Please note that this project is released with a Contributor Code of Conduct. By
|
102
|
+
participating in this project you agree to abide by its terms. See [Code of
|
103
|
+
Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.CODE_OF_CONDUCT)
|
104
|
+
for more information.
|
99
105
|
|
100
106
|
## License
|
101
107
|
|
102
|
-
This library is licensed under Apache 2.0. Full license text is available in
|
108
|
+
This library is licensed under Apache 2.0. Full license text is available in
|
109
|
+
[LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.LICENSE).
|
103
110
|
|
104
111
|
## Support
|
105
112
|
|
106
|
-
Please [report bugs at the project on
|
107
|
-
|
113
|
+
Please [report bugs at the project on
|
114
|
+
Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
|
115
|
+
hesitate to [ask
|
116
|
+
questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
|
117
|
+
about the client or APIs on [StackOverflow](http://stackoverflow.com).
|
data/lib/google-cloud-pubsub.rb
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
|
15
16
|
##
|
16
17
|
# This file is here to be autorequired by bundler, so that the
|
17
18
|
# Google::Cloud.pubsub and Google::Cloud#pubsub methods can be available, but
|
@@ -29,8 +30,8 @@ module Google
|
|
29
30
|
# Creates a new object for connecting to the Pub/Sub service.
|
30
31
|
# Each call creates a new connection.
|
31
32
|
#
|
32
|
-
# For more information on connecting to Google Cloud see the
|
33
|
-
# Guide
|
33
|
+
# For more information on connecting to Google Cloud see the
|
34
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
34
35
|
#
|
35
36
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
36
37
|
# set of resources and operations that the connection can access. See
|
@@ -71,8 +72,8 @@ module Google
|
|
71
72
|
# Creates a new object for connecting to the Pub/Sub service.
|
72
73
|
# Each call creates a new connection.
|
73
74
|
#
|
74
|
-
# For more information on connecting to Google Cloud see the
|
75
|
-
# Guide
|
75
|
+
# For more information on connecting to Google Cloud see the
|
76
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
76
77
|
#
|
77
78
|
# @param [String] project_id Project identifier for the Pub/Sub service you
|
78
79
|
# are connecting to. If not present, the default project for the
|
data/lib/google/cloud/pubsub.rb
CHANGED
@@ -30,493 +30,7 @@ module Google
|
|
30
30
|
# Cloud Pub/Sub allows developers to communicate between independently
|
31
31
|
# written applications.
|
32
32
|
#
|
33
|
-
#
|
34
|
-
# Rubyists. Your authentication credentials are detected automatically in
|
35
|
-
# Google Cloud Platform environments such as Google Compute Engine, Google
|
36
|
-
# App Engine and Google Kubernetes Engine. In other environments you can
|
37
|
-
# configure authentication easily, either directly in your code or via
|
38
|
-
# environment variables. Read more about the options for connecting in the
|
39
|
-
# [Authentication
|
40
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
41
|
-
#
|
42
|
-
# ```ruby
|
43
|
-
# require "google/cloud/pubsub"
|
44
|
-
#
|
45
|
-
# pubsub = Google::Cloud::Pubsub.new
|
46
|
-
#
|
47
|
-
# topic = pubsub.topic "my-topic"
|
48
|
-
# topic.publish "task completed"
|
49
|
-
# ```
|
50
|
-
#
|
51
|
-
# To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
|
52
|
-
# ](https://cloud.google.com/pubsub/overview).
|
53
|
-
#
|
54
|
-
# ## Enabling Logging
|
55
|
-
#
|
56
|
-
# To enable logging for this library, set the logger for the underlying
|
57
|
-
# [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The
|
58
|
-
# logger that you set may be a Ruby stdlib
|
59
|
-
# [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html)
|
60
|
-
# as shown below, or a
|
61
|
-
# [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
|
62
|
-
# that will write logs to [Stackdriver
|
63
|
-
# Logging](https://cloud.google.com/logging/). See
|
64
|
-
# [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
|
65
|
-
# and the gRPC
|
66
|
-
# [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
|
67
|
-
# for additional information.
|
68
|
-
#
|
69
|
-
# Configuring a Ruby stdlib logger:
|
70
|
-
#
|
71
|
-
# ```ruby
|
72
|
-
# require "logger"
|
73
|
-
#
|
74
|
-
# module MyLogger
|
75
|
-
# LOGGER = Logger.new $stderr, level: Logger::WARN
|
76
|
-
# def logger
|
77
|
-
# LOGGER
|
78
|
-
# end
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
# # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
82
|
-
# module GRPC
|
83
|
-
# extend MyLogger
|
84
|
-
# end
|
85
|
-
# ```
|
86
|
-
#
|
87
|
-
# ## Retrieving Topics
|
88
|
-
#
|
89
|
-
# A Topic is a named resource to which messages are sent by publishers.
|
90
|
-
# A Topic is found by its name. (See {Google::Cloud::Pubsub::Project#topic})
|
91
|
-
#
|
92
|
-
# ```ruby
|
93
|
-
# require "google/cloud/pubsub"
|
94
|
-
#
|
95
|
-
# pubsub = Google::Cloud::Pubsub.new
|
96
|
-
# topic = pubsub.topic "my-topic"
|
97
|
-
# ```
|
98
|
-
#
|
99
|
-
# ## Creating a Topic
|
100
|
-
#
|
101
|
-
# A Topic is created from a Project. (See
|
102
|
-
# {Google::Cloud::Pubsub::Project#create_topic})
|
103
|
-
#
|
104
|
-
# ```ruby
|
105
|
-
# require "google/cloud/pubsub"
|
106
|
-
#
|
107
|
-
# pubsub = Google::Cloud::Pubsub.new
|
108
|
-
# topic = pubsub.create_topic "my-topic"
|
109
|
-
# ```
|
110
|
-
#
|
111
|
-
# ## Retrieving Subscriptions
|
112
|
-
#
|
113
|
-
# A Subscription is a named resource representing the stream of messages
|
114
|
-
# from a single, specific Topic, to be delivered to the subscribing
|
115
|
-
# application. A Subscription is found by its name. (See
|
116
|
-
# {Google::Cloud::Pubsub::Topic#subscription})
|
117
|
-
#
|
118
|
-
# ```ruby
|
119
|
-
# require "google/cloud/pubsub"
|
120
|
-
#
|
121
|
-
# pubsub = Google::Cloud::Pubsub.new
|
122
|
-
#
|
123
|
-
# topic = pubsub.topic "my-topic"
|
124
|
-
# subscription = topic.subscription "my-topic-subscription"
|
125
|
-
# puts subscription.name
|
126
|
-
# ```
|
127
|
-
#
|
128
|
-
# ## Creating a Subscription
|
129
|
-
#
|
130
|
-
# A Subscription is created from a Topic. (See
|
131
|
-
# {Google::Cloud::Pubsub::Topic#subscribe} and
|
132
|
-
# {Google::Cloud::Pubsub::Project#subscribe})
|
133
|
-
#
|
134
|
-
# ```ruby
|
135
|
-
# require "google/cloud/pubsub"
|
136
|
-
#
|
137
|
-
# pubsub = Google::Cloud::Pubsub.new
|
138
|
-
#
|
139
|
-
# topic = pubsub.topic "my-topic"
|
140
|
-
# sub = topic.subscribe "my-topic-sub"
|
141
|
-
# puts sub.name # => "my-topic-sub"
|
142
|
-
# ```
|
143
|
-
#
|
144
|
-
# The subscription can be created that specifies the number of seconds to
|
145
|
-
# wait to be acknowledged as well as an endpoint URL to push the messages
|
146
|
-
# to:
|
147
|
-
#
|
148
|
-
# ```ruby
|
149
|
-
# require "google/cloud/pubsub"
|
150
|
-
#
|
151
|
-
# pubsub = Google::Cloud::Pubsub.new
|
152
|
-
#
|
153
|
-
# topic = pubsub.topic "my-topic"
|
154
|
-
# sub = topic.subscribe "my-topic-sub",
|
155
|
-
# deadline: 120,
|
156
|
-
# endpoint: "https://example.com/push"
|
157
|
-
# ```
|
158
|
-
#
|
159
|
-
# ## Publishing Messages
|
160
|
-
#
|
161
|
-
# Messages are published to a topic. Any message published to a topic
|
162
|
-
# without a subscription will be lost. Ensure the topic has a subscription
|
163
|
-
# before publishing. (See {Google::Cloud::Pubsub::Topic#publish} and
|
164
|
-
# {Google::Cloud::Pubsub::Project#publish})
|
165
|
-
#
|
166
|
-
# ```ruby
|
167
|
-
# require "google/cloud/pubsub"
|
168
|
-
#
|
169
|
-
# pubsub = Google::Cloud::Pubsub.new
|
170
|
-
#
|
171
|
-
# topic = pubsub.topic "my-topic"
|
172
|
-
# msg = topic.publish "task completed"
|
173
|
-
# ```
|
174
|
-
#
|
175
|
-
# Messages can also be published with attributes:
|
176
|
-
#
|
177
|
-
# ```ruby
|
178
|
-
# require "google/cloud/pubsub"
|
179
|
-
#
|
180
|
-
# pubsub = Google::Cloud::Pubsub.new
|
181
|
-
#
|
182
|
-
# topic = pubsub.topic "my-topic"
|
183
|
-
# msg = topic.publish "task completed",
|
184
|
-
# foo: :bar,
|
185
|
-
# this: :that
|
186
|
-
# ```
|
187
|
-
#
|
188
|
-
# Messages can also be published in batches asynchronously using
|
189
|
-
# `publish_async`. (See {Google::Cloud::Pubsub::Topic#publish_async} and
|
190
|
-
# {Google::Cloud::Pubsub::AsyncPublisher})
|
191
|
-
#
|
192
|
-
# ```ruby
|
193
|
-
# require "google/cloud/pubsub"
|
194
|
-
#
|
195
|
-
# pubsub = Google::Cloud::Pubsub.new
|
196
|
-
#
|
197
|
-
# topic = pubsub.topic "my-topic"
|
198
|
-
# topic.publish_async "task completed" do |result|
|
199
|
-
# if result.succeeded?
|
200
|
-
# log_publish_success result.data
|
201
|
-
# else
|
202
|
-
# log_publish_failure result.data, result.error
|
203
|
-
# end
|
204
|
-
# end
|
205
|
-
#
|
206
|
-
# topic.async_publisher.stop.wait!
|
207
|
-
# ```
|
208
|
-
#
|
209
|
-
# Or multiple messages can be published in batches at the same time by
|
210
|
-
# passing a block to `publish`. (See
|
211
|
-
# {Google::Cloud::Pubsub::BatchPublisher})
|
212
|
-
#
|
213
|
-
# ```ruby
|
214
|
-
# require "google/cloud/pubsub"
|
215
|
-
#
|
216
|
-
# pubsub = Google::Cloud::Pubsub.new
|
217
|
-
#
|
218
|
-
# topic = pubsub.topic "my-topic"
|
219
|
-
# msgs = topic.publish do |batch|
|
220
|
-
# batch.publish "task 1 completed", foo: :bar
|
221
|
-
# batch.publish "task 2 completed", foo: :baz
|
222
|
-
# batch.publish "task 3 completed", foo: :bif
|
223
|
-
# end
|
224
|
-
# ```
|
225
|
-
#
|
226
|
-
# ## Receiving messages
|
227
|
-
#
|
228
|
-
# Messages can be streamed from a subscription with a subscriber object
|
229
|
-
# that is created using `listen`. (See
|
230
|
-
# {Google::Cloud::Pubsub::Subscription#listen} and
|
231
|
-
# {Google::Cloud::Pubsub::Subscriber})
|
232
|
-
#
|
233
|
-
# ```ruby
|
234
|
-
# require "google/cloud/pubsub"
|
235
|
-
#
|
236
|
-
# pubsub = Google::Cloud::Pubsub.new
|
237
|
-
#
|
238
|
-
# sub = pubsub.subscription "my-topic-sub"
|
239
|
-
#
|
240
|
-
# subscriber = sub.listen do |received_message|
|
241
|
-
# # process message
|
242
|
-
# received_message.acknowledge!
|
243
|
-
# end
|
244
|
-
#
|
245
|
-
# # Start background threads that will call the block passed to listen.
|
246
|
-
# subscriber.start
|
247
|
-
#
|
248
|
-
# # Shut down the subscriber when ready to stop receiving messages.
|
249
|
-
# subscriber.stop.wait!
|
250
|
-
# ```
|
251
|
-
#
|
252
|
-
# Messages also can be pulled directly in a one-time operation. (See
|
253
|
-
# {Google::Cloud::Pubsub::Subscription#pull})
|
254
|
-
#
|
255
|
-
# ```ruby
|
256
|
-
# require "google/cloud/pubsub"
|
257
|
-
#
|
258
|
-
# pubsub = Google::Cloud::Pubsub.new
|
259
|
-
#
|
260
|
-
# sub = pubsub.subscription "my-topic-sub"
|
261
|
-
# received_messages = sub.pull
|
262
|
-
# ```
|
263
|
-
#
|
264
|
-
# A maximum number of messages to pull can be specified:
|
265
|
-
#
|
266
|
-
# ```ruby
|
267
|
-
# require "google/cloud/pubsub"
|
268
|
-
#
|
269
|
-
# pubsub = Google::Cloud::Pubsub.new
|
270
|
-
#
|
271
|
-
# sub = pubsub.subscription "my-topic-sub"
|
272
|
-
# received_messages = sub.pull max: 10
|
273
|
-
# ```
|
274
|
-
#
|
275
|
-
# ## Acknowledging a Message
|
276
|
-
#
|
277
|
-
# Messages that are received can be acknowledged in Pub/Sub, marking the
|
278
|
-
# message to be removed so it cannot be pulled again.
|
279
|
-
#
|
280
|
-
# A Message that can be acknowledged is called a ReceivedMessage.
|
281
|
-
# ReceivedMessages can be acknowledged one at a time:
|
282
|
-
# (See {Google::Cloud::Pubsub::ReceivedMessage#acknowledge!})
|
283
|
-
#
|
284
|
-
# ```ruby
|
285
|
-
# require "google/cloud/pubsub"
|
286
|
-
#
|
287
|
-
# pubsub = Google::Cloud::Pubsub.new
|
288
|
-
#
|
289
|
-
# sub = pubsub.subscription "my-topic-sub"
|
290
|
-
#
|
291
|
-
# subscriber = sub.listen do |received_message|
|
292
|
-
# # process message
|
293
|
-
# received_message.acknowledge!
|
294
|
-
# end
|
295
|
-
#
|
296
|
-
# # Start background threads that will call the block passed to listen.
|
297
|
-
# subscriber.start
|
298
|
-
#
|
299
|
-
# # Shut down the subscriber when ready to stop receiving messages.
|
300
|
-
# subscriber.stop.wait!
|
301
|
-
# ```
|
302
|
-
#
|
303
|
-
# Or, multiple messages can be acknowledged in a single API call:
|
304
|
-
# (See {Google::Cloud::Pubsub::Subscription#acknowledge})
|
305
|
-
#
|
306
|
-
# ```ruby
|
307
|
-
# require "google/cloud/pubsub"
|
308
|
-
#
|
309
|
-
# pubsub = Google::Cloud::Pubsub.new
|
310
|
-
#
|
311
|
-
# sub = pubsub.subscription "my-topic-sub"
|
312
|
-
# received_messages = sub.pull
|
313
|
-
# sub.acknowledge received_messages
|
314
|
-
# ```
|
315
|
-
#
|
316
|
-
# ## Modifying a Deadline
|
317
|
-
#
|
318
|
-
# A message must be acknowledged after it is pulled, or Pub/Sub will mark
|
319
|
-
# the message for redelivery. The message acknowledgement deadline can
|
320
|
-
# delayed if more time is needed. This will allow more time to process the
|
321
|
-
# message before the message is marked for redelivery. (See
|
322
|
-
# {Google::Cloud::Pubsub::ReceivedMessage#delay!})
|
323
|
-
#
|
324
|
-
# ```ruby
|
325
|
-
# require "google/cloud/pubsub"
|
326
|
-
#
|
327
|
-
# pubsub = Google::Cloud::Pubsub.new
|
328
|
-
#
|
329
|
-
# sub = pubsub.subscription "my-topic-sub"
|
330
|
-
# subscriber = sub.listen do |received_message|
|
331
|
-
# puts received_message.message.data
|
332
|
-
#
|
333
|
-
# # Delay for 2 minutes
|
334
|
-
# received_message.delay! 120
|
335
|
-
# end
|
336
|
-
#
|
337
|
-
# # Start background threads that will call the block passed to listen.
|
338
|
-
# subscriber.start
|
339
|
-
#
|
340
|
-
# # Shut down the subscriber when ready to stop receiving messages.
|
341
|
-
# subscriber.stop.wait!
|
342
|
-
# ```
|
343
|
-
#
|
344
|
-
# The message can also be made available for immediate redelivery:
|
345
|
-
#
|
346
|
-
# ```ruby
|
347
|
-
# require "google/cloud/pubsub"
|
348
|
-
#
|
349
|
-
# pubsub = Google::Cloud::Pubsub.new
|
350
|
-
#
|
351
|
-
# sub = pubsub.subscription "my-topic-sub"
|
352
|
-
# subscriber = sub.listen do |received_message|
|
353
|
-
# puts received_message.message.data
|
354
|
-
#
|
355
|
-
# # Mark for redelivery
|
356
|
-
# received_message.reject!
|
357
|
-
# end
|
358
|
-
#
|
359
|
-
# # Start background threads that will call the block passed to listen.
|
360
|
-
# subscriber.start
|
361
|
-
#
|
362
|
-
# # Shut down the subscriber when ready to stop receiving messages.
|
363
|
-
# subscriber.stop.wait!
|
364
|
-
# ```
|
365
|
-
#
|
366
|
-
# Multiple messages can be delayed or made available for immediate
|
367
|
-
# redelivery: (See {Google::Cloud::Pubsub::Subscription#delay})
|
368
|
-
#
|
369
|
-
# ```ruby
|
370
|
-
# require "google/cloud/pubsub"
|
371
|
-
#
|
372
|
-
# pubsub = Google::Cloud::Pubsub.new
|
373
|
-
#
|
374
|
-
# sub = pubsub.subscription "my-topic-sub"
|
375
|
-
# received_messages = sub.pull
|
376
|
-
# sub.delay 120, received_messages
|
377
|
-
# ```
|
378
|
-
#
|
379
|
-
# ## Creating a snapshot and using seek
|
380
|
-
#
|
381
|
-
# You can create a snapshot to retain the existing backlog on a
|
382
|
-
# subscription. The snapshot will hold the messages in the subscription's
|
383
|
-
# backlog that are unacknowledged upon the successful completion of the
|
384
|
-
# `create_snapshot` operation.
|
385
|
-
#
|
386
|
-
# Later, you can use `seek` to reset the subscription's backlog to the
|
387
|
-
# snapshot.
|
388
|
-
#
|
389
|
-
# (See {Google::Cloud::Pubsub::Subscription#create_snapshot} and
|
390
|
-
# {Google::Cloud::Pubsub::Subscription#seek})
|
391
|
-
#
|
392
|
-
# ```ruby
|
393
|
-
# require "google/cloud/pubsub"
|
394
|
-
#
|
395
|
-
# pubsub = Google::Cloud::Pubsub.new
|
396
|
-
#
|
397
|
-
# sub = pubsub.subscription "my-topic-sub"
|
398
|
-
#
|
399
|
-
# snapshot = sub.create_snapshot
|
400
|
-
#
|
401
|
-
# received_messages = sub.pull
|
402
|
-
# sub.acknowledge received_messages
|
403
|
-
#
|
404
|
-
# sub.seek snapshot
|
405
|
-
# ```
|
406
|
-
#
|
407
|
-
# ## Listening for Messages
|
408
|
-
#
|
409
|
-
# A subscriber object can be created using `listen`, which streams messages
|
410
|
-
# from the backend and processes them as they are received. (See
|
411
|
-
# {Google::Cloud::Pubsub::Subscription#listen} and
|
412
|
-
# {Google::Cloud::Pubsub::Subscriber})
|
413
|
-
#
|
414
|
-
# ```ruby
|
415
|
-
# require "google/cloud/pubsub"
|
416
|
-
#
|
417
|
-
# pubsub = Google::Cloud::Pubsub.new
|
418
|
-
#
|
419
|
-
# sub = pubsub.subscription "my-topic-sub"
|
420
|
-
#
|
421
|
-
# subscriber = sub.listen do |received_message|
|
422
|
-
# # process message
|
423
|
-
# received_message.acknowledge!
|
424
|
-
# end
|
425
|
-
#
|
426
|
-
# # Start background threads that will call the block passed to listen.
|
427
|
-
# subscriber.start
|
428
|
-
#
|
429
|
-
# # Shut down the subscriber when ready to stop receiving messages.
|
430
|
-
# subscriber.stop.wait!
|
431
|
-
# ```
|
432
|
-
#
|
433
|
-
# The subscriber object can be configured to control the number of
|
434
|
-
# concurrent streams to open, the number of received messages to be
|
435
|
-
# collected, and the number of threads each stream opens for concurrent
|
436
|
-
# calls made to handle the received messages.
|
437
|
-
#
|
438
|
-
# ```ruby
|
439
|
-
# require "google/cloud/pubsub"
|
440
|
-
#
|
441
|
-
# pubsub = Google::Cloud::Pubsub.new
|
442
|
-
#
|
443
|
-
# sub = pubsub.subscription "my-topic-sub"
|
444
|
-
#
|
445
|
-
# subscriber = sub.listen threads: { callback: 16 } do |received_message|
|
446
|
-
# # store the message somewhere before acknowledging
|
447
|
-
# store_in_backend received_message.data # takes a few seconds
|
448
|
-
# received_message.acknowledge!
|
449
|
-
# end
|
450
|
-
#
|
451
|
-
# # Start background threads that will call the block passed to listen.
|
452
|
-
# subscriber.start
|
453
|
-
# ```
|
454
|
-
#
|
455
|
-
# ## Working Across Projects
|
456
|
-
#
|
457
|
-
# All calls to the Pub/Sub service use the same project and credentials
|
458
|
-
# provided to the {Google::Cloud#pubsub} method. However, it is common to
|
459
|
-
# reference topics or subscriptions in other projects, which can be achieved
|
460
|
-
# by using the `project` option. The main credentials must have permissions
|
461
|
-
# to the topics and subscriptions in other projects.
|
462
|
-
#
|
463
|
-
# ```ruby
|
464
|
-
# require "google/cloud/pubsub"
|
465
|
-
#
|
466
|
-
# pubsub = Google::Cloud::Pubsub.new # my-project
|
467
|
-
#
|
468
|
-
# # Get a topic in the current project
|
469
|
-
# my_topic = pubsub.topic "my-topic"
|
470
|
-
# my_topic.name #=> "projects/my-project/topics/my-topic"
|
471
|
-
# # Get a topic in another project
|
472
|
-
# other_topic = pubsub.topic "other-topic", project: "other-project-id"
|
473
|
-
# other_topic.name #=> "projects/other-project-id/topics/other-topic"
|
474
|
-
# ```
|
475
|
-
#
|
476
|
-
# It is possible to create a subscription in the current project that pulls
|
477
|
-
# from a topic in another project:
|
478
|
-
#
|
479
|
-
# ```ruby
|
480
|
-
# require "google/cloud/pubsub"
|
481
|
-
#
|
482
|
-
# pubsub = Google::Cloud::Pubsub.new # my-project
|
483
|
-
#
|
484
|
-
# # Get a topic in another project
|
485
|
-
# topic = pubsub.topic "other-topic", project: "other-project-id"
|
486
|
-
# # Create a subscription in the current project that pulls from
|
487
|
-
# # the topic in another project
|
488
|
-
# sub = topic.subscribe "my-sub"
|
489
|
-
# sub.name #=> "projects/my-project/subscriptions/my-sub"
|
490
|
-
# sub.topic.name #=> "projects/other-project-id/topics/other-topic"
|
491
|
-
# ```
|
492
|
-
#
|
493
|
-
# ## Using the Google Cloud Pub/Sub Emulator
|
494
|
-
#
|
495
|
-
# To develop and test your application locally, you can use the [Google
|
496
|
-
# Cloud Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which
|
497
|
-
# provides [local
|
498
|
-
# emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/)
|
499
|
-
# of the production Google Cloud Pub/Sub environment. You can start the
|
500
|
-
# Google Cloud Pub/Sub emulator using the `gcloud` command-line tool.
|
501
|
-
#
|
502
|
-
# To configure your ruby code to use the emulator, set the
|
503
|
-
# `PUBSUB_EMULATOR_HOST` environment variable to the host and port where the
|
504
|
-
# emulator is running. The value can be set as an environment variable in
|
505
|
-
# the shell running the ruby code, or can be set directly in the ruby code
|
506
|
-
# as shown below.
|
507
|
-
#
|
508
|
-
# ```ruby
|
509
|
-
# require "google/cloud/pubsub"
|
510
|
-
#
|
511
|
-
# # Make Pub/Sub use the emulator
|
512
|
-
# ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
|
513
|
-
#
|
514
|
-
# pubsub = Google::Cloud::Pubsub.new "emulator-project-id"
|
515
|
-
#
|
516
|
-
# # Get a topic in the current project
|
517
|
-
# my_topic = pubsub.new_topic "my-topic"
|
518
|
-
# my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
|
519
|
-
# ```
|
33
|
+
# See {file:OVERVIEW.md Google Cloud Pub/Sub Overview}.
|
520
34
|
#
|
521
35
|
module Pubsub
|
522
36
|
##
|
@@ -524,8 +38,7 @@ module Google
|
|
524
38
|
# Each call creates a new connection.
|
525
39
|
#
|
526
40
|
# For more information on connecting to Google Cloud see the
|
527
|
-
#
|
528
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
41
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
529
42
|
#
|
530
43
|
# @param [String] project_id Project identifier for the Pub/Sub service
|
531
44
|
# you are connecting to. If not present, the default project for the
|
@@ -575,7 +88,8 @@ module Google
|
|
575
88
|
return Pubsub::Project.new(
|
576
89
|
Pubsub::Service.new(
|
577
90
|
project_id, :this_channel_is_insecure,
|
578
|
-
host: emulator_host
|
91
|
+
host: emulator_host, timeout: timeout,
|
92
|
+
client_config: client_config
|
579
93
|
)
|
580
94
|
)
|
581
95
|
end
|