gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
data/lib/gcloud/pubsub.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
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.
|
@@ -14,478 +14,4 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "gcloud"
|
17
|
-
require "
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
##
|
21
|
-
# Creates a new object for connecting to the Pub/Sub service.
|
22
|
-
# Each call creates a new connection.
|
23
|
-
#
|
24
|
-
# For more information on connecting to Google Cloud see the [Authentication
|
25
|
-
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
26
|
-
#
|
27
|
-
# @param [String] project Project identifier for the Pub/Sub service you are
|
28
|
-
# connecting to.
|
29
|
-
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If file
|
30
|
-
# path the file must be readable.
|
31
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
32
|
-
# set of resources and operations that the connection can access. See [Using
|
33
|
-
# OAuth 2.0 to Access Google
|
34
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
35
|
-
#
|
36
|
-
# The default scope is:
|
37
|
-
#
|
38
|
-
# * `https://www.googleapis.com/auth/pubsub`
|
39
|
-
# @param [Integer] retries Number of times to retry requests on server error.
|
40
|
-
# The default value is `3`. Optional.
|
41
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
42
|
-
#
|
43
|
-
# @return [Gcloud::Pubsub::Project]
|
44
|
-
#
|
45
|
-
# @example
|
46
|
-
# require "gcloud/pubsub"
|
47
|
-
#
|
48
|
-
# pubsub = Gcloud.pubsub
|
49
|
-
#
|
50
|
-
# topic = pubsub.topic "my-topic"
|
51
|
-
# topic.publish "task completed"
|
52
|
-
#
|
53
|
-
def self.pubsub project = nil, keyfile = nil, scope: nil, retries: nil,
|
54
|
-
timeout: nil
|
55
|
-
project ||= Gcloud::Pubsub::Project.default_project
|
56
|
-
if ENV["PUBSUB_EMULATOR_HOST"]
|
57
|
-
ps = Gcloud::Pubsub::Project.new project, :this_channel_is_insecure
|
58
|
-
ps.service.host = ENV["PUBSUB_EMULATOR_HOST"]
|
59
|
-
return ps
|
60
|
-
end
|
61
|
-
if keyfile.nil?
|
62
|
-
credentials = Gcloud::Pubsub::Credentials.default scope: scope
|
63
|
-
else
|
64
|
-
credentials = Gcloud::Pubsub::Credentials.new keyfile, scope: scope
|
65
|
-
end
|
66
|
-
Gcloud::Pubsub::Project.new(
|
67
|
-
Gcloud::Pubsub::Service.new(
|
68
|
-
project, credentials, retries: retries, timeout: timeout))
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# # Google Cloud Pub/Sub
|
73
|
-
#
|
74
|
-
# Google Cloud Pub/Sub is designed to provide reliable, many-to-many,
|
75
|
-
# asynchronous messaging between applications. Publisher applications can
|
76
|
-
# send messages to a "topic" and other applications can subscribe to that
|
77
|
-
# topic to receive the messages. By decoupling senders and receivers, Google
|
78
|
-
# Cloud Pub/Sub allows developers to communicate between independently written
|
79
|
-
# applications.
|
80
|
-
#
|
81
|
-
# The goal of gcloud-ruby is to provide a API that is comfortable to
|
82
|
-
# Rubyists. Authentication is handled by {Gcloud#pubsub}. You can provide the
|
83
|
-
# project and credential information to connect to the Pub/Sub service, or if
|
84
|
-
# you are running on Google Compute Engine this configuration is taken care
|
85
|
-
# of for you.
|
86
|
-
#
|
87
|
-
# ```ruby
|
88
|
-
# require "gcloud"
|
89
|
-
#
|
90
|
-
# gcloud = Gcloud.new
|
91
|
-
# pubsub = gcloud.pubsub
|
92
|
-
#
|
93
|
-
# topic = pubsub.topic "my-topic"
|
94
|
-
# topic.publish "task completed"
|
95
|
-
# ```
|
96
|
-
#
|
97
|
-
# To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
|
98
|
-
# ](https://cloud.google.com/pubsub/overview).
|
99
|
-
#
|
100
|
-
# ## Retrieving Topics
|
101
|
-
#
|
102
|
-
# A Topic is a named resource to which messages are sent by publishers.
|
103
|
-
# A Topic is found by its name. (See {Gcloud::Pubsub::Project#topic})
|
104
|
-
#
|
105
|
-
# ```ruby
|
106
|
-
# require "gcloud"
|
107
|
-
#
|
108
|
-
# gcloud = Gcloud.new
|
109
|
-
# pubsub = gcloud.pubsub
|
110
|
-
# topic = pubsub.topic "my-topic"
|
111
|
-
# ```
|
112
|
-
#
|
113
|
-
# ## Creating a Topic
|
114
|
-
#
|
115
|
-
# A Topic is created from a Project. (See
|
116
|
-
# {Gcloud::Pubsub::Project#create_topic})
|
117
|
-
#
|
118
|
-
# ```ruby
|
119
|
-
# require "gcloud"
|
120
|
-
#
|
121
|
-
# gcloud = Gcloud.new
|
122
|
-
# pubsub = gcloud.pubsub
|
123
|
-
# topic = pubsub.create_topic "my-topic"
|
124
|
-
# ```
|
125
|
-
#
|
126
|
-
# ## Retrieving Subscriptions
|
127
|
-
#
|
128
|
-
# A Subscription is a named resource representing the stream of messages from
|
129
|
-
# a single, specific Topic, to be delivered to the subscribing application. A
|
130
|
-
# Subscription is found by its name. (See
|
131
|
-
# {Gcloud::Pubsub::Topic#subscription})
|
132
|
-
#
|
133
|
-
# ```ruby
|
134
|
-
# require "gcloud"
|
135
|
-
#
|
136
|
-
# gcloud = Gcloud.new
|
137
|
-
# pubsub = gcloud.pubsub
|
138
|
-
#
|
139
|
-
# topic = pubsub.topic "my-topic"
|
140
|
-
# subscription = topic.subscription "my-topic-subscription"
|
141
|
-
# puts subscription.name
|
142
|
-
# ```
|
143
|
-
#
|
144
|
-
# ## Creating a Subscription
|
145
|
-
#
|
146
|
-
# A Subscription is created from a Topic. (See
|
147
|
-
# {Gcloud::Pubsub::Topic#subscribe} and {Gcloud::Pubsub::Project#subscribe})
|
148
|
-
#
|
149
|
-
# ```ruby
|
150
|
-
# require "gcloud"
|
151
|
-
#
|
152
|
-
# gcloud = Gcloud.new
|
153
|
-
# pubsub = gcloud.pubsub
|
154
|
-
#
|
155
|
-
# topic = pubsub.topic "my-topic"
|
156
|
-
# sub = topic.subscribe "my-topic-sub"
|
157
|
-
# puts sub.name # => "my-topic-sub"
|
158
|
-
# ```
|
159
|
-
#
|
160
|
-
# The subscription can be created that specifies the number of seconds to
|
161
|
-
# wait to be acknowledged as well as an endpoint URL to push the messages to:
|
162
|
-
#
|
163
|
-
# ```ruby
|
164
|
-
# require "gcloud"
|
165
|
-
#
|
166
|
-
# gcloud = Gcloud.new
|
167
|
-
# pubsub = gcloud.pubsub
|
168
|
-
#
|
169
|
-
# topic = pubsub.topic "my-topic"
|
170
|
-
# sub = topic.subscribe "my-topic-sub",
|
171
|
-
# deadline: 120,
|
172
|
-
# endpoint: "https://example.com/push"
|
173
|
-
# ```
|
174
|
-
#
|
175
|
-
# ## Publishing Messages
|
176
|
-
#
|
177
|
-
# Messages are published to a topic. Any message published to a topic without
|
178
|
-
# a subscription will be lost. Ensure the topic has a subscription before
|
179
|
-
# publishing. (See {Gcloud::Pubsub::Topic#publish} and
|
180
|
-
# {Gcloud::Pubsub::Project#publish})
|
181
|
-
#
|
182
|
-
# ```ruby
|
183
|
-
# require "gcloud"
|
184
|
-
#
|
185
|
-
# gcloud = Gcloud.new
|
186
|
-
# pubsub = gcloud.pubsub
|
187
|
-
#
|
188
|
-
# topic = pubsub.topic "my-topic"
|
189
|
-
# msg = topic.publish "new-message"
|
190
|
-
# ```
|
191
|
-
#
|
192
|
-
# Messages can also be published with attributes:
|
193
|
-
#
|
194
|
-
# ```ruby
|
195
|
-
# require "gcloud"
|
196
|
-
#
|
197
|
-
# gcloud = Gcloud.new
|
198
|
-
# pubsub = gcloud.pubsub
|
199
|
-
#
|
200
|
-
# topic = pubsub.topic "my-topic"
|
201
|
-
# msg = topic.publish "new-message",
|
202
|
-
# foo: :bar,
|
203
|
-
# this: :that
|
204
|
-
# ```
|
205
|
-
#
|
206
|
-
# Multiple messages can be published at the same time by passing a block:
|
207
|
-
#
|
208
|
-
# ```ruby
|
209
|
-
# require "gcloud"
|
210
|
-
#
|
211
|
-
# gcloud = Gcloud.new
|
212
|
-
# pubsub = gcloud.pubsub
|
213
|
-
#
|
214
|
-
# topic = pubsub.topic "my-topic"
|
215
|
-
# msgs = topic.publish do |batch|
|
216
|
-
# batch.publish "new-message-1", foo: :bar
|
217
|
-
# batch.publish "new-message-2", foo: :baz
|
218
|
-
# batch.publish "new-message-3", foo: :bif
|
219
|
-
# end
|
220
|
-
# ```
|
221
|
-
#
|
222
|
-
# ## Pulling Messages
|
223
|
-
#
|
224
|
-
# Messages are pulled from a Subscription. (See
|
225
|
-
# {Gcloud::Pubsub::Subscription#pull})
|
226
|
-
#
|
227
|
-
# ```ruby
|
228
|
-
# require "gcloud"
|
229
|
-
#
|
230
|
-
# gcloud = Gcloud.new
|
231
|
-
# pubsub = gcloud.pubsub
|
232
|
-
#
|
233
|
-
# sub = pubsub.subscription "my-topic-sub"
|
234
|
-
# msgs = sub.pull
|
235
|
-
# ```
|
236
|
-
#
|
237
|
-
# A maximum number of messages returned can also be specified:
|
238
|
-
#
|
239
|
-
# ```ruby
|
240
|
-
# require "gcloud"
|
241
|
-
#
|
242
|
-
# gcloud = Gcloud.new
|
243
|
-
# pubsub = gcloud.pubsub
|
244
|
-
#
|
245
|
-
# sub = pubsub.subscription "my-topic-sub", max: 10
|
246
|
-
# msgs = sub.pull
|
247
|
-
# ```
|
248
|
-
#
|
249
|
-
# The request for messages can also block until messages are available.
|
250
|
-
# (See {Gcloud::Pubsub::Subscription#wait_for_messages})
|
251
|
-
#
|
252
|
-
# ```ruby
|
253
|
-
# require "gcloud"
|
254
|
-
#
|
255
|
-
# gcloud = Gcloud.new
|
256
|
-
# pubsub = gcloud.pubsub
|
257
|
-
#
|
258
|
-
# sub = pubsub.subscription "my-topic-sub"
|
259
|
-
# msgs = sub.wait_for_messages
|
260
|
-
# ```
|
261
|
-
#
|
262
|
-
# ## Acknowledging a Message
|
263
|
-
#
|
264
|
-
# Messages that are received can be acknowledged in Pub/Sub, marking the
|
265
|
-
# message to be removed so it cannot be pulled again.
|
266
|
-
#
|
267
|
-
# A Message that can be acknowledged is called a ReceivedMessage.
|
268
|
-
# ReceivedMessages can be acknowledged one at a time:
|
269
|
-
# (See {Gcloud::Pubsub::ReceivedMessage#acknowledge!})
|
270
|
-
#
|
271
|
-
# ```ruby
|
272
|
-
# require "gcloud"
|
273
|
-
#
|
274
|
-
# gcloud = Gcloud.new
|
275
|
-
# pubsub = gcloud.pubsub
|
276
|
-
#
|
277
|
-
# sub = pubsub.subscription "my-topic-sub"
|
278
|
-
# sub.pull.each { |msg| msg.acknowledge! }
|
279
|
-
# ```
|
280
|
-
#
|
281
|
-
# Or, multiple messages can be acknowledged in a single API call:
|
282
|
-
# (See {Gcloud::Pubsub::Subscription#acknowledge})
|
283
|
-
#
|
284
|
-
# ```ruby
|
285
|
-
# require "gcloud"
|
286
|
-
#
|
287
|
-
# gcloud = Gcloud.new
|
288
|
-
# pubsub = gcloud.pubsub
|
289
|
-
#
|
290
|
-
# sub = pubsub.subscription "my-topic-sub"
|
291
|
-
# received_messages = sub.pull
|
292
|
-
# sub.acknowledge received_messages
|
293
|
-
# ```
|
294
|
-
#
|
295
|
-
# ## Modifying a Deadline
|
296
|
-
#
|
297
|
-
# A message must be acknowledged after it is pulled, or Pub/Sub will mark the
|
298
|
-
# message for redelivery. The message acknowledgement deadline can delayed if
|
299
|
-
# more time is needed. This will allow more time to process the message before
|
300
|
-
# the message is marked for redelivery. (See
|
301
|
-
# {Gcloud::Pubsub::ReceivedMessage#delay!})
|
302
|
-
#
|
303
|
-
# ```ruby
|
304
|
-
# require "gcloud"
|
305
|
-
#
|
306
|
-
# gcloud = Gcloud.new
|
307
|
-
# pubsub = gcloud.pubsub
|
308
|
-
#
|
309
|
-
# sub = pubsub.subscription "my-topic-sub"
|
310
|
-
# received_message = sub.pull.first
|
311
|
-
# if received_message
|
312
|
-
# puts received_message.message.data
|
313
|
-
# # Delay for 2 minutes
|
314
|
-
# received_message.delay! 120
|
315
|
-
# end
|
316
|
-
# ```
|
317
|
-
#
|
318
|
-
# The message can also be made available for immediate redelivery:
|
319
|
-
#
|
320
|
-
# ```ruby
|
321
|
-
# require "gcloud"
|
322
|
-
#
|
323
|
-
# gcloud = Gcloud.new
|
324
|
-
# pubsub = gcloud.pubsub
|
325
|
-
#
|
326
|
-
# sub = pubsub.subscription "my-topic-sub"
|
327
|
-
# received_message = sub.pull.first
|
328
|
-
# if received_message
|
329
|
-
# puts received_message.message.data
|
330
|
-
# # Mark for redelivery by setting the deadline to now
|
331
|
-
# received_message.delay! 0
|
332
|
-
# end
|
333
|
-
# ```
|
334
|
-
#
|
335
|
-
# Multiple messages can be delayed or made available for immediate redelivery:
|
336
|
-
# (See {Gcloud::Pubsub::Subscription#delay})
|
337
|
-
#
|
338
|
-
# ```ruby
|
339
|
-
# require "gcloud"
|
340
|
-
#
|
341
|
-
# gcloud = Gcloud.new
|
342
|
-
# pubsub = gcloud.pubsub
|
343
|
-
#
|
344
|
-
# sub = pubsub.subscription "my-topic-sub"
|
345
|
-
# received_messages = sub.pull
|
346
|
-
# sub.delay 120, received_messages
|
347
|
-
# ```
|
348
|
-
#
|
349
|
-
# ## Listening for Messages
|
350
|
-
#
|
351
|
-
# Long running workers are easy to create with `listen`, which runs an
|
352
|
-
# infinitely blocking loop to process messages as they are received. (See
|
353
|
-
# {Gcloud::Pubsub::Subscription#listen})
|
354
|
-
#
|
355
|
-
# ```ruby
|
356
|
-
# require "gcloud"
|
357
|
-
#
|
358
|
-
# gcloud = Gcloud.new
|
359
|
-
# pubsub = gcloud.pubsub
|
360
|
-
#
|
361
|
-
# sub = pubsub.subscription "my-topic-sub"
|
362
|
-
# sub.listen do |msg|
|
363
|
-
# # process msg
|
364
|
-
# end
|
365
|
-
# ```
|
366
|
-
#
|
367
|
-
# Messages are retrieved in batches for efficiency. The number of messages
|
368
|
-
# pulled per batch can be limited with the `max` option:
|
369
|
-
#
|
370
|
-
# ```ruby
|
371
|
-
# require "gcloud"
|
372
|
-
#
|
373
|
-
# gcloud = Gcloud.new
|
374
|
-
# pubsub = gcloud.pubsub
|
375
|
-
#
|
376
|
-
# sub = pubsub.subscription "my-topic-sub"
|
377
|
-
# sub.listen max: 20 do |msg|
|
378
|
-
# # process msg
|
379
|
-
# end
|
380
|
-
# ```
|
381
|
-
#
|
382
|
-
# When processing time and the acknowledgement deadline are a concern,
|
383
|
-
# messages can be automatically acknowledged as they are pulled with the
|
384
|
-
# `autoack` option:
|
385
|
-
#
|
386
|
-
# ```ruby
|
387
|
-
# require "gcloud"
|
388
|
-
#
|
389
|
-
# gcloud = Gcloud.new
|
390
|
-
# pubsub = gcloud.pubsub
|
391
|
-
#
|
392
|
-
# sub = pubsub.subscription "my-topic-sub"
|
393
|
-
# sub.listen autoack: true do |msg|
|
394
|
-
# # process msg
|
395
|
-
# end
|
396
|
-
# ```
|
397
|
-
#
|
398
|
-
# ## Configuring retries and timeout
|
399
|
-
#
|
400
|
-
# You can configure how many times API requests may be automatically retried.
|
401
|
-
# When an API request fails, the response will be inspected to see if the
|
402
|
-
# request meets criteria indicating that it may succeed on retry, such as
|
403
|
-
# `500` and `503` status codes or a specific internal error code such as
|
404
|
-
# `rateLimitExceeded`. If it meets the criteria, the request will be retried
|
405
|
-
# after a delay. If another error occurs, the delay will be increased before a
|
406
|
-
# subsequent attempt, until the `retries` limit is reached.
|
407
|
-
#
|
408
|
-
# You can also set the request `timeout` value in seconds.
|
409
|
-
#
|
410
|
-
# ```ruby
|
411
|
-
# require "gcloud"
|
412
|
-
#
|
413
|
-
# gcloud = Gcloud.new
|
414
|
-
# pubsub = gcloud.pubsub retries: 10, timeout: 120
|
415
|
-
# ```
|
416
|
-
#
|
417
|
-
# See the [Pub/Sub error codes](https://cloud.google.com/pubsub/error-codes)
|
418
|
-
# for a list of error conditions.
|
419
|
-
#
|
420
|
-
# ## Working Across Projects
|
421
|
-
#
|
422
|
-
# All calls to the Pub/Sub service use the same project and credentials
|
423
|
-
# provided to the {Gcloud#pubsub} method. However, it is common to reference
|
424
|
-
# topics or subscriptions in other projects, which can be achieved by using
|
425
|
-
# the `project` option. The main credentials must have permissions to the
|
426
|
-
# topics and subscriptions in other projects.
|
427
|
-
#
|
428
|
-
# ```ruby
|
429
|
-
# require "gcloud"
|
430
|
-
#
|
431
|
-
# gcloud = Gcloud.new # my-project-id
|
432
|
-
# pubsub = gcloud.pubsub
|
433
|
-
#
|
434
|
-
# # Get a topic in the current project
|
435
|
-
# my_topic = pubsub.topic "my-topic"
|
436
|
-
# my_topic.name #=> "projects/my-project-id/topics/my-topic"
|
437
|
-
# # Get a topic in another project
|
438
|
-
# other_topic = pubsub.topic "other-topic", project: "other-project-id"
|
439
|
-
# other_topic.name #=> "projects/other-project-id/topics/other-topic"
|
440
|
-
# ```
|
441
|
-
#
|
442
|
-
# It is possible to create a subscription in the current project that pulls
|
443
|
-
# from a topic in another project:
|
444
|
-
#
|
445
|
-
# ```ruby
|
446
|
-
# require "gcloud"
|
447
|
-
#
|
448
|
-
# gcloud = Gcloud.new # my-project-id
|
449
|
-
# pubsub = gcloud.pubsub
|
450
|
-
#
|
451
|
-
# # Get a topic in another project
|
452
|
-
# topic = pubsub.topic "other-topic", project: "other-project-id"
|
453
|
-
# # Create a subscription in the current project that pulls from
|
454
|
-
# # the topic in another project
|
455
|
-
# sub = topic.subscribe "my-sub"
|
456
|
-
# sub.name #=> "projects/my-project-id/subscriptions/my-sub"
|
457
|
-
# sub.topic.name #=> "projects/other-project-id/topics/other-topic"
|
458
|
-
# ```
|
459
|
-
#
|
460
|
-
# ## Using the Google Cloud Pub/Sub Emulator
|
461
|
-
#
|
462
|
-
# To develop and test your application locally, you can use the [Google Cloud
|
463
|
-
# Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which provides
|
464
|
-
# [local
|
465
|
-
# emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/) of
|
466
|
-
# the production Google Cloud Pub/Sub environment. You can start the Google
|
467
|
-
# Cloud Pub/Sub emulator using the `gcloud` command-line tool.
|
468
|
-
#
|
469
|
-
# To configure your ruby code to use the emulator, set the
|
470
|
-
# `PUBSUB_EMULATOR_HOST` environment variable to the host and port where the
|
471
|
-
# emulator is running. The value can be set as an environment variable in the
|
472
|
-
# shell running the ruby code, or can be set directly in the ruby code as
|
473
|
-
# shown below.
|
474
|
-
#
|
475
|
-
# ```ruby
|
476
|
-
# require "gcloud"
|
477
|
-
#
|
478
|
-
# # Make Pub/Sub use the emulator
|
479
|
-
# ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
|
480
|
-
#
|
481
|
-
# gcloud = Gcloud.new "emulator-project-id"
|
482
|
-
# pubsub = gcloud.pubsub
|
483
|
-
#
|
484
|
-
# # Get a topic in the current project
|
485
|
-
# my_topic = pubsub.new_topic "my-topic"
|
486
|
-
# my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
|
487
|
-
# ```
|
488
|
-
#
|
489
|
-
module Pubsub
|
490
|
-
end
|
491
|
-
end
|
17
|
+
require "google/cloud/pubsub"
|