google-cloud-pubsub 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +47 -0
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google-cloud-pubsub.rb +13 -13
- data/lib/google/cloud/pubsub.rb +15 -18
- data/lib/google/cloud/pubsub/async_publisher.rb +1 -2
- data/lib/google/cloud/pubsub/credentials.rb +2 -2
- data/lib/google/cloud/pubsub/service.rb +110 -255
- data/lib/google/cloud/pubsub/subscriber/stream.rb +3 -2
- data/lib/google/cloud/pubsub/subscription.rb +70 -3
- data/lib/google/cloud/pubsub/topic.rb +7 -3
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +8 -79
- data/lib/google/cloud/pubsub/v1.rb +0 -17
- data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -796
- data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -869
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -114
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1463
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -153
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -259
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -210
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5faee5de29df83057422ad7029a047eb10e8408a9b4e87599d301bc1c907a06
|
4
|
+
data.tar.gz: bc9d9b75232d66b09b5d45310875fbbd734663cf226575e43656da47aa955204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59bc075932f2a592276a8e0472371a18a8cc6e835ccb6c36ece17f277528bf92813d978e06393cf384c54c282c8a04fa6ba1d2fcfab08214e3cb3a55d2724ac
|
7
|
+
data.tar.gz: 8a6fffc01ab630eaf960c3c87858f942fe6a0241cfdf024875d379f2a915be724ea209bcfdc07c7ab12a1299949785456c27f0725d6d4b4cac519749cbc6f1fc
|
data/AUTHENTICATION.md
CHANGED
@@ -76,7 +76,8 @@ The environment variables that google-cloud-pubsub checks for project ID are:
|
|
76
76
|
1. `PUBSUB_PROJECT`
|
77
77
|
2. `GOOGLE_CLOUD_PROJECT`
|
78
78
|
|
79
|
-
The environment variables that google-cloud-pubsub checks for credentials
|
79
|
+
The environment variables that google-cloud-pubsub checks for credentials
|
80
|
+
are configured on {Google::Cloud::PubSub::Credentials}:
|
80
81
|
|
81
82
|
1. `PUBSUB_CREDENTIALS` - Path to JSON file, or JSON contents
|
82
83
|
2. `PUBSUB_KEYFILE` - Path to JSON file, or JSON contents
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,52 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.0.0 / 2020-08-06
|
4
|
+
|
5
|
+
This is a major update that removes the "low-level" client interface code, and
|
6
|
+
instead adds the new `google-cloud-pubsub-v1` gem as a dependency.
|
7
|
+
The new dependency is a rewritten low-level client, produced by a next-
|
8
|
+
generation client code generator, with improved performance and stability.
|
9
|
+
|
10
|
+
This change should have no effect on the high-level interface that most users
|
11
|
+
will use. The one exception is that the (mostly undocumented) `client_config`
|
12
|
+
argument, for adjusting low-level parameters such as RPC retry settings on
|
13
|
+
client objects, has been removed. If you need to adjust these parameters, use
|
14
|
+
the configuration interface in `google-cloud-pubsub-v1`.
|
15
|
+
|
16
|
+
Substantial changes have been made in the low-level interfaces, however. If you
|
17
|
+
are using the low-level classes under the `Google::Cloud::PubSub::V1` module,
|
18
|
+
please review the docs for the new `google-cloud-pubsub-v1` gem. In
|
19
|
+
particular:
|
20
|
+
|
21
|
+
* Some classes have been renamed, notably the client classes themselves.
|
22
|
+
* The client constructor takes a configuration block instead of configuration
|
23
|
+
keyword arguments.
|
24
|
+
* All RPC method arguments are now keyword arguments.
|
25
|
+
|
26
|
+
### 1.10.0 / 2020-07-23
|
27
|
+
|
28
|
+
#### Features
|
29
|
+
|
30
|
+
* Add Subscription#detach and #detached?
|
31
|
+
|
32
|
+
### 1.9.0 / 2020-07-21
|
33
|
+
|
34
|
+
#### Features
|
35
|
+
|
36
|
+
* Add support for server-side flow control
|
37
|
+
|
38
|
+
### 1.8.0 / 2020-06-29
|
39
|
+
|
40
|
+
#### Features
|
41
|
+
|
42
|
+
* Add Subscription#filter
|
43
|
+
|
44
|
+
### 1.7.1 / 2020-05-28
|
45
|
+
|
46
|
+
#### Documentation
|
47
|
+
|
48
|
+
* Fix a few broken links
|
49
|
+
|
3
50
|
### 1.7.0 / 2020-05-21
|
4
51
|
|
5
52
|
#### Features
|
data/TROUBLESHOOTING.md
CHANGED
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
|
|
24
24
|
|
25
25
|
- [New issue][gh-ruby]
|
26
26
|
|
27
|
-
Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
|
28
|
-
can use the "ruby" channel for general Ruby questions, or use the
|
29
|
-
"google-cloud-ruby" channel if you have questions about this gem in particular.
|
30
|
-
|
31
27
|
[so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+pubsub
|
32
28
|
|
33
|
-
[gh-search-ruby]: https://github.com/
|
34
|
-
|
35
|
-
[gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
|
29
|
+
[gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+pubsub%22
|
36
30
|
|
37
|
-
[
|
31
|
+
[gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
|
data/lib/google-cloud-pubsub.rb
CHANGED
@@ -42,8 +42,6 @@ module Google
|
|
42
42
|
#
|
43
43
|
# * `https://www.googleapis.com/auth/pubsub`
|
44
44
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
45
|
-
# @param [Hash] client_config A hash of values to override the default
|
46
|
-
# behavior of the API client. Optional.
|
47
45
|
#
|
48
46
|
# @return [Google::Cloud::PubSub::Project]
|
49
47
|
#
|
@@ -62,9 +60,9 @@ module Google
|
|
62
60
|
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
63
61
|
# pubsub = gcloud.pubsub scope: platform_scope
|
64
62
|
#
|
65
|
-
def pubsub scope: nil, timeout: nil
|
63
|
+
def pubsub scope: nil, timeout: nil
|
66
64
|
timeout ||= @timeout
|
67
|
-
Google::Cloud.pubsub @project, @keyfile, scope: scope, timeout: timeout
|
65
|
+
Google::Cloud.pubsub @project, @keyfile, scope: scope, timeout: timeout
|
68
66
|
end
|
69
67
|
|
70
68
|
##
|
@@ -90,8 +88,6 @@ module Google
|
|
90
88
|
#
|
91
89
|
# * `https://www.googleapis.com/auth/pubsub`
|
92
90
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
93
|
-
# @param [Hash] client_config A hash of values to override the default
|
94
|
-
# behavior of the API client. Optional.
|
95
91
|
#
|
96
92
|
# @return [Google::Cloud::PubSub::Project]
|
97
93
|
#
|
@@ -103,11 +99,12 @@ module Google
|
|
103
99
|
# topic = pubsub.topic "my-topic"
|
104
100
|
# topic.publish "task completed"
|
105
101
|
#
|
106
|
-
def self.pubsub project_id = nil,
|
107
|
-
|
102
|
+
def self.pubsub project_id = nil,
|
103
|
+
credentials = nil,
|
104
|
+
scope: nil,
|
105
|
+
timeout: nil
|
108
106
|
require "google/cloud/pubsub"
|
109
|
-
Google::Cloud::PubSub.new project_id: project_id, credentials: credentials,
|
110
|
-
scope: scope, timeout: timeout, client_config: client_config
|
107
|
+
Google::Cloud::PubSub.new project_id: project_id, credentials: credentials, scope: scope, timeout: timeout
|
111
108
|
end
|
112
109
|
end
|
113
110
|
end
|
@@ -125,15 +122,18 @@ Google::Cloud.configure.add_config! :pubsub do |config|
|
|
125
122
|
default_emulator = Google::Cloud::Config.deferred do
|
126
123
|
ENV["PUBSUB_EMULATOR_HOST"]
|
127
124
|
end
|
125
|
+
default_scopes = [
|
126
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
127
|
+
"https://www.googleapis.com/auth/pubsub"
|
128
|
+
]
|
128
129
|
|
129
130
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
130
131
|
config.add_alias! :project, :project_id
|
131
132
|
config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
|
132
133
|
config.add_alias! :keyfile, :credentials
|
133
|
-
config.add_field! :scope,
|
134
|
+
config.add_field! :scope, default_scopes, match: [String, Array]
|
134
135
|
config.add_field! :timeout, nil, match: Integer
|
135
|
-
config.add_field! :client_config, nil, match: Hash
|
136
136
|
config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
|
137
137
|
config.add_field! :on_error, nil, match: Proc
|
138
|
-
config.add_field! :endpoint,
|
138
|
+
config.add_field! :endpoint, "pubsub.googleapis.com", match: String
|
139
139
|
end
|
data/lib/google/cloud/pubsub.rb
CHANGED
@@ -57,8 +57,6 @@ module Google
|
|
57
57
|
#
|
58
58
|
# * `https://www.googleapis.com/auth/pubsub`
|
59
59
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
60
|
-
# @param [Hash] client_config A hash of values to override the default
|
61
|
-
# behavior of the API client. Optional.
|
62
60
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
63
61
|
# If the param is nil, uses the default endpoint.
|
64
62
|
# @param [String] emulator_host Pub/Sub emulator host. Optional.
|
@@ -77,12 +75,17 @@ module Google
|
|
77
75
|
# topic = pubsub.topic "my-topic"
|
78
76
|
# topic.publish "task completed"
|
79
77
|
#
|
80
|
-
def self.new project_id: nil,
|
81
|
-
|
78
|
+
def self.new project_id: nil,
|
79
|
+
credentials: nil,
|
80
|
+
scope: nil,
|
81
|
+
timeout: nil,
|
82
|
+
endpoint: nil,
|
83
|
+
emulator_host: nil,
|
84
|
+
project: nil,
|
85
|
+
keyfile: nil
|
82
86
|
project_id ||= (project || default_project_id)
|
83
87
|
scope ||= configure.scope
|
84
88
|
timeout ||= configure.timeout
|
85
|
-
client_config ||= configure.client_config
|
86
89
|
endpoint ||= configure.endpoint
|
87
90
|
emulator_host ||= configure.emulator_host
|
88
91
|
|
@@ -90,11 +93,8 @@ module Google
|
|
90
93
|
project_id = project_id.to_s # Always cast to a string
|
91
94
|
raise ArgumentError, "project_id is missing" if project_id.empty?
|
92
95
|
|
93
|
-
|
94
|
-
|
95
|
-
project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout, client_config: client_config
|
96
|
-
)
|
97
|
-
)
|
96
|
+
service = PubSub::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
|
97
|
+
return PubSub::Project.new service
|
98
98
|
end
|
99
99
|
|
100
100
|
credentials ||= (keyfile || default_credentials(scope: scope))
|
@@ -106,11 +106,8 @@ module Google
|
|
106
106
|
project_id = project_id.to_s # Always cast to a string
|
107
107
|
raise ArgumentError, "project_id is missing" if project_id.empty?
|
108
108
|
|
109
|
-
PubSub::
|
110
|
-
|
111
|
-
project_id, credentials, timeout: timeout, host: endpoint, client_config: client_config
|
112
|
-
)
|
113
|
-
)
|
109
|
+
service = PubSub::Service.new project_id, credentials, host: endpoint, timeout: timeout
|
110
|
+
PubSub::Project.new service
|
114
111
|
end
|
115
112
|
|
116
113
|
# rubocop:enable Metrics/AbcSize
|
@@ -131,8 +128,6 @@ module Google
|
|
131
128
|
# * `retries` - (Integer) Number of times to retry requests on server
|
132
129
|
# error.
|
133
130
|
# * `timeout` - (Integer) Default timeout to use in requests.
|
134
|
-
# * `client_config` - (Hash) A hash of values to override the default
|
135
|
-
# behavior of the API client.
|
136
131
|
# * `endpoint` - (String) Override of the endpoint host name, or `nil`
|
137
132
|
# to use the default endpoint.
|
138
133
|
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
@@ -167,7 +162,9 @@ module Google
|
|
167
162
|
end
|
168
163
|
end
|
169
164
|
|
170
|
-
## Legacy namespace
|
165
|
+
## Legacy veneer namespace
|
171
166
|
Pubsub = PubSub unless const_defined? :Pubsub
|
172
167
|
end
|
168
|
+
## Legacy generated client namespace
|
169
|
+
Pubsub = Cloud::PubSub unless const_defined? :Pubsub
|
173
170
|
end
|
@@ -374,8 +374,7 @@ module Google
|
|
374
374
|
|
375
375
|
PUBLISH_RETRY_ERRORS = [
|
376
376
|
GRPC::Cancelled, GRPC::DeadlineExceeded, GRPC::Internal,
|
377
|
-
GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable
|
378
|
-
GRPC::Core::CallError
|
377
|
+
GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable
|
379
378
|
].freeze
|
380
379
|
|
381
380
|
def publish_batch_error_retryable? error
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "googleauth"
|
17
|
-
require "google/cloud/pubsub/v1/credentials.rb"
|
17
|
+
require "google/cloud/pubsub/v1/publisher/credentials.rb"
|
18
18
|
|
19
19
|
module Google
|
20
20
|
module Cloud
|
@@ -38,7 +38,7 @@ module Google
|
|
38
38
|
#
|
39
39
|
# pubsub.project_id #=> "my-project"
|
40
40
|
#
|
41
|
-
class Credentials < Google::Cloud::PubSub::V1::Credentials
|
41
|
+
class Credentials < Google::Cloud::PubSub::V1::Publisher::Credentials
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -18,17 +18,15 @@ require "google/cloud/pubsub/credentials"
|
|
18
18
|
require "google/cloud/pubsub/convert"
|
19
19
|
require "google/cloud/pubsub/version"
|
20
20
|
require "google/cloud/pubsub/v1"
|
21
|
-
require "google/gax/errors"
|
22
21
|
require "securerandom"
|
23
22
|
|
24
23
|
module Google
|
25
24
|
module Cloud
|
26
25
|
module PubSub
|
27
26
|
##
|
28
|
-
# @private Represents the
|
29
|
-
# methods.
|
27
|
+
# @private Represents the Pub/Sub service API, including IAM mixins.
|
30
28
|
class Service
|
31
|
-
attr_accessor :project, :credentials, :host, :timeout
|
29
|
+
attr_accessor :project, :credentials, :host, :timeout
|
32
30
|
###
|
33
31
|
# The same client_id is used across all streaming pull connections that are created by this client. This is
|
34
32
|
# intentional, as it indicates to the server that any guarantees, such as message ordering, made for a stream
|
@@ -38,44 +36,25 @@ module Google
|
|
38
36
|
|
39
37
|
##
|
40
38
|
# Creates a new Service instance.
|
41
|
-
def initialize project, credentials, host: nil, timeout: nil
|
42
|
-
client_config: nil
|
39
|
+
def initialize project, credentials, host: nil, timeout: nil
|
43
40
|
@project = project
|
44
41
|
@credentials = credentials
|
45
|
-
@host = host
|
42
|
+
@host = host
|
46
43
|
@timeout = timeout
|
47
|
-
@client_config = client_config || {}
|
48
44
|
@client_id = SecureRandom.uuid.freeze
|
49
45
|
end
|
50
46
|
|
51
|
-
def channel
|
52
|
-
require "grpc"
|
53
|
-
GRPC::Core::Channel.new host, chan_args, chan_creds
|
54
|
-
end
|
55
|
-
|
56
|
-
def chan_args
|
57
|
-
{ "grpc.max_send_message_length" => -1,
|
58
|
-
"grpc.max_receive_message_length" => -1,
|
59
|
-
"grpc.keepalive_time_ms" => 300_000,
|
60
|
-
"grpc.service_config_disable_resolution" => 1 }
|
61
|
-
end
|
62
|
-
|
63
|
-
def chan_creds
|
64
|
-
return credentials if insecure?
|
65
|
-
require "grpc"
|
66
|
-
GRPC::Core::ChannelCredentials.new.compose GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
67
|
-
end
|
68
|
-
|
69
47
|
def subscriber
|
70
48
|
return mocked_subscriber if mocked_subscriber
|
71
49
|
@subscriber ||= begin
|
72
|
-
V1::
|
73
|
-
credentials
|
74
|
-
timeout
|
75
|
-
|
76
|
-
lib_name
|
77
|
-
lib_version
|
78
|
-
|
50
|
+
V1::Subscriber::Client.new do |config|
|
51
|
+
config.credentials = credentials if credentials
|
52
|
+
config.timeout = timeout if timeout
|
53
|
+
config.endpoint = host if host
|
54
|
+
config.lib_name = "gccl"
|
55
|
+
config.lib_version = Google::Cloud::PubSub::VERSION
|
56
|
+
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
57
|
+
end
|
79
58
|
end
|
80
59
|
end
|
81
60
|
attr_accessor :mocked_subscriber
|
@@ -83,20 +62,32 @@ module Google
|
|
83
62
|
def publisher
|
84
63
|
return mocked_publisher if mocked_publisher
|
85
64
|
@publisher ||= begin
|
86
|
-
V1::
|
87
|
-
credentials
|
88
|
-
timeout
|
89
|
-
|
90
|
-
lib_name
|
91
|
-
lib_version
|
92
|
-
|
65
|
+
V1::Publisher::Client.new do |config|
|
66
|
+
config.credentials = credentials if credentials
|
67
|
+
config.timeout = timeout if timeout
|
68
|
+
config.endpoint = host if host
|
69
|
+
config.lib_name = "gccl"
|
70
|
+
config.lib_version = Google::Cloud::PubSub::VERSION
|
71
|
+
config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
|
72
|
+
end
|
93
73
|
end
|
94
74
|
end
|
95
75
|
attr_accessor :mocked_publisher
|
96
76
|
|
97
|
-
def
|
98
|
-
|
77
|
+
def iam
|
78
|
+
return mocked_iam if mocked_iam
|
79
|
+
@iam ||= begin
|
80
|
+
V1::IAMPolicy::Client.new do |config|
|
81
|
+
config.credentials = credentials if credentials
|
82
|
+
config.timeout = timeout if timeout
|
83
|
+
config.endpoint = host if host
|
84
|
+
config.lib_name = "gccl"
|
85
|
+
config.lib_version = Google::Cloud::PubSub::VERSION
|
86
|
+
config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
|
87
|
+
end
|
88
|
+
end
|
99
89
|
end
|
90
|
+
attr_accessor :mocked_iam
|
100
91
|
|
101
92
|
##
|
102
93
|
# Gets the configuration of a topic.
|
@@ -105,30 +96,17 @@ module Google
|
|
105
96
|
# If other attributes are added in the future,
|
106
97
|
# they will be returned here.
|
107
98
|
def get_topic topic_name, options = {}
|
108
|
-
|
109
|
-
publisher.get_topic topic_path(topic_name, options),
|
110
|
-
options: default_options
|
111
|
-
end
|
99
|
+
publisher.get_topic topic: topic_path(topic_name, options)
|
112
100
|
end
|
113
101
|
|
114
102
|
##
|
115
103
|
# Lists matching topics.
|
116
104
|
def list_topics options = {}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
kwargs: default_headers,
|
121
|
-
page_token: token
|
122
|
-
)
|
123
|
-
end
|
105
|
+
paged_enum = publisher.list_topics project: project_path(options),
|
106
|
+
page_size: options[:max],
|
107
|
+
page_token: options[:token]
|
124
108
|
|
125
|
-
|
126
|
-
paged_enum = publisher.list_topics project_path(options),
|
127
|
-
page_size: options[:max],
|
128
|
-
options: call_options
|
129
|
-
|
130
|
-
paged_enum.page.response
|
131
|
-
end
|
109
|
+
paged_enum.response
|
132
110
|
end
|
133
111
|
|
134
112
|
##
|
@@ -140,21 +118,16 @@ module Google
|
|
140
118
|
}
|
141
119
|
end
|
142
120
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
message_storage_policy: message_storage_policy,
|
149
|
-
options: default_options
|
150
|
-
end
|
121
|
+
publisher.create_topic \
|
122
|
+
name: topic_path(topic_name, options),
|
123
|
+
labels: labels,
|
124
|
+
kms_key_name: kms_key_name,
|
125
|
+
message_storage_policy: message_storage_policy
|
151
126
|
end
|
152
127
|
|
153
128
|
def update_topic topic_obj, *fields
|
154
129
|
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
155
|
-
|
156
|
-
publisher.update_topic topic_obj, mask, options: default_options
|
157
|
-
end
|
130
|
+
publisher.update_topic topic: topic_obj, update_mask: mask
|
158
131
|
end
|
159
132
|
|
160
133
|
##
|
@@ -163,10 +136,7 @@ module Google
|
|
163
136
|
# exist. After a topic is deleted, a new topic may be created with the
|
164
137
|
# same name.
|
165
138
|
def delete_topic topic_name
|
166
|
-
|
167
|
-
publisher.delete_topic topic_path(topic_name),
|
168
|
-
options: default_options
|
169
|
-
end
|
139
|
+
publisher.delete_topic topic: topic_path(topic_name)
|
170
140
|
end
|
171
141
|
|
172
142
|
##
|
@@ -175,143 +145,98 @@ module Google
|
|
175
145
|
# The messages parameter is an array of arrays.
|
176
146
|
# The first element is the data, second is attributes hash.
|
177
147
|
def publish topic, messages
|
178
|
-
|
179
|
-
publisher.publish topic_path(topic), messages,
|
180
|
-
options: default_options
|
181
|
-
end
|
148
|
+
publisher.publish topic: topic_path(topic), messages: messages
|
182
149
|
end
|
183
150
|
|
184
151
|
##
|
185
152
|
# Gets the details of a subscription.
|
186
153
|
def get_subscription subscription_name, options = {}
|
187
|
-
subscription
|
188
|
-
execute do
|
189
|
-
subscriber.get_subscription subscription, options: default_options
|
190
|
-
end
|
154
|
+
subscriber.get_subscription subscription: subscription_path(subscription_name, options)
|
191
155
|
end
|
192
156
|
|
193
157
|
##
|
194
158
|
# Lists matching subscriptions by project and topic.
|
195
159
|
def list_topics_subscriptions topic, options = {}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
kwargs: default_headers,
|
200
|
-
page_token: token
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
execute do
|
205
|
-
paged_enum = publisher.list_topic_subscriptions \
|
206
|
-
topic_path(topic, options),
|
207
|
-
page_size: options[:max],
|
208
|
-
options: call_options
|
209
|
-
|
210
|
-
paged_enum.page.response
|
211
|
-
end
|
160
|
+
publisher.list_topic_subscriptions topic: topic_path(topic, options),
|
161
|
+
page_size: options[:max],
|
162
|
+
page_token: options[:token]
|
212
163
|
end
|
213
164
|
|
214
165
|
##
|
215
166
|
# Lists matching subscriptions by project.
|
216
167
|
def list_subscriptions options = {}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
kwargs: default_headers,
|
221
|
-
page_token: token
|
222
|
-
)
|
223
|
-
end
|
168
|
+
paged_enum = subscriber.list_subscriptions project: project_path(options),
|
169
|
+
page_size: options[:max],
|
170
|
+
page_token: options[:token]
|
224
171
|
|
225
|
-
|
226
|
-
paged_enum = subscriber.list_subscriptions project_path(options),
|
227
|
-
page_size: options[:max],
|
228
|
-
options: call_options
|
229
|
-
|
230
|
-
paged_enum.page.response
|
231
|
-
end
|
172
|
+
paged_enum.response
|
232
173
|
end
|
233
174
|
|
234
175
|
##
|
235
176
|
# Creates a subscription on a given topic for a given subscriber.
|
236
177
|
def create_subscription topic, subscription_name, options = {}
|
237
|
-
name = subscription_path subscription_name, options
|
238
|
-
topic = topic_path topic
|
239
178
|
push_config = if options[:endpoint]
|
240
179
|
Google::Cloud::PubSub::V1::PushConfig.new \
|
241
180
|
push_endpoint: options[:endpoint],
|
242
181
|
attributes: (options[:attributes] || {}).to_h
|
243
182
|
end
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
labels: labels,
|
257
|
-
enable_message_ordering: message_ordering,
|
258
|
-
dead_letter_policy: dead_letter_policy(options),
|
259
|
-
retry_policy: options[:retry_policy],
|
260
|
-
options: default_options
|
261
|
-
end
|
183
|
+
subscriber.create_subscription \
|
184
|
+
name: subscription_path(subscription_name, options),
|
185
|
+
topic: topic_path(topic),
|
186
|
+
push_config: push_config,
|
187
|
+
ack_deadline_seconds: options[:deadline],
|
188
|
+
retain_acked_messages: options[:retain_acked],
|
189
|
+
message_retention_duration: Convert.number_to_duration(options[:retention]),
|
190
|
+
labels: options[:labels],
|
191
|
+
enable_message_ordering: options[:message_ordering],
|
192
|
+
filter: options[:filter],
|
193
|
+
dead_letter_policy: dead_letter_policy(options),
|
194
|
+
retry_policy: options[:retry_policy]
|
262
195
|
end
|
263
196
|
|
264
197
|
def update_subscription subscription_obj, *fields
|
265
198
|
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
266
|
-
|
267
|
-
subscriber.update_subscription subscription_obj, mask, options: default_options
|
268
|
-
end
|
199
|
+
subscriber.update_subscription subscription: subscription_obj, update_mask: mask
|
269
200
|
end
|
270
201
|
|
271
202
|
##
|
272
|
-
# Deletes an existing subscription.
|
273
|
-
# All pending messages in the subscription are immediately dropped.
|
203
|
+
# Deletes an existing subscription. All pending messages in the subscription are immediately dropped.
|
274
204
|
def delete_subscription subscription
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
205
|
+
subscriber.delete_subscription subscription: subscription_path(subscription)
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# Detaches a subscription from its topic. All messages retained in the subscription are dropped. Subsequent
|
210
|
+
# `Pull` and `StreamingPull` requests will raise `FAILED_PRECONDITION`. If the subscription is a push
|
211
|
+
# subscription, pushes to the endpoint will stop.
|
212
|
+
def detach_subscription subscription
|
213
|
+
publisher.detach_subscription subscription: subscription_path(subscription)
|
279
214
|
end
|
280
215
|
|
281
216
|
##
|
282
217
|
# Pulls a single message from the server.
|
283
218
|
def pull subscription, options = {}
|
284
|
-
subscription = subscription_path subscription, options
|
285
219
|
max_messages = options.fetch(:max, 100).to_i
|
286
220
|
return_immediately = !(!options.fetch(:immediate, true))
|
287
221
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
return_immediately: return_immediately,
|
292
|
-
options: default_options
|
293
|
-
end
|
222
|
+
subscriber.pull subscription: subscription_path(subscription, options),
|
223
|
+
max_messages: max_messages,
|
224
|
+
return_immediately: return_immediately
|
294
225
|
end
|
295
226
|
|
296
227
|
def streaming_pull request_enum
|
297
|
-
|
298
|
-
subscriber.streaming_pull request_enum, options: default_options
|
299
|
-
end
|
228
|
+
subscriber.streaming_pull request_enum
|
300
229
|
end
|
301
230
|
|
302
231
|
##
|
303
232
|
# Acknowledges receipt of a message.
|
304
233
|
def acknowledge subscription, *ack_ids
|
305
|
-
|
306
|
-
subscriber.acknowledge subscription_path(subscription), ack_ids,
|
307
|
-
options: default_options
|
308
|
-
end
|
234
|
+
subscriber.acknowledge subscription: subscription_path(subscription), ack_ids: ack_ids
|
309
235
|
end
|
310
236
|
|
311
237
|
##
|
312
238
|
# Modifies the PushConfig for a specified subscription.
|
313
239
|
def modify_push_config subscription, endpoint, attributes
|
314
|
-
subscription = subscription_path subscription
|
315
240
|
# Convert attributes to strings to match the protobuf definition
|
316
241
|
attributes = Hash[attributes.map { |k, v| [String(k), String(v)] }]
|
317
242
|
push_config = Google::Cloud::PubSub::V1::PushConfig.new(
|
@@ -319,138 +244,83 @@ module Google
|
|
319
244
|
attributes: attributes
|
320
245
|
)
|
321
246
|
|
322
|
-
|
323
|
-
|
324
|
-
options: default_options
|
325
|
-
end
|
247
|
+
subscriber.modify_push_config subscription: subscription_path(subscription),
|
248
|
+
push_config: push_config
|
326
249
|
end
|
327
250
|
|
328
251
|
##
|
329
252
|
# Modifies the ack deadline for a specific message.
|
330
253
|
def modify_ack_deadline subscription, ids, deadline
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
deadline, options: default_options
|
335
|
-
end
|
254
|
+
subscriber.modify_ack_deadline subscription: subscription_path(subscription),
|
255
|
+
ack_ids: Array(ids),
|
256
|
+
ack_deadline_seconds: deadline
|
336
257
|
end
|
337
258
|
|
338
259
|
##
|
339
260
|
# Lists snapshots by project.
|
340
261
|
def list_snapshots options = {}
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
kwargs: default_headers,
|
345
|
-
page_token: token
|
346
|
-
)
|
347
|
-
end
|
348
|
-
|
349
|
-
execute do
|
350
|
-
paged_enum = subscriber.list_snapshots project_path(options),
|
351
|
-
page_size: options[:max],
|
352
|
-
options: call_options
|
262
|
+
paged_enum = subscriber.list_snapshots project: project_path(options),
|
263
|
+
page_size: options[:max],
|
264
|
+
page_token: options[:token]
|
353
265
|
|
354
|
-
|
355
|
-
end
|
266
|
+
paged_enum.response
|
356
267
|
end
|
357
268
|
|
358
269
|
##
|
359
270
|
# Creates a snapshot on a given subscription.
|
360
271
|
def create_snapshot subscription, snapshot_name, labels: nil
|
361
|
-
name
|
362
|
-
|
363
|
-
|
364
|
-
subscription_path(subscription),
|
365
|
-
labels: labels,
|
366
|
-
options: default_options
|
367
|
-
end
|
272
|
+
subscriber.create_snapshot name: snapshot_path(snapshot_name),
|
273
|
+
subscription: subscription_path(subscription),
|
274
|
+
labels: labels
|
368
275
|
end
|
369
276
|
|
370
277
|
def update_snapshot snapshot_obj, *fields
|
371
278
|
mask = Google::Protobuf::FieldMask.new paths: fields.map(&:to_s)
|
372
|
-
|
373
|
-
subscriber.update_snapshot snapshot_obj, mask, options: default_options
|
374
|
-
end
|
279
|
+
subscriber.update_snapshot snapshot: snapshot_obj, update_mask: mask
|
375
280
|
end
|
376
281
|
|
377
282
|
##
|
378
283
|
# Deletes an existing snapshot.
|
379
284
|
# All pending messages in the snapshot are immediately dropped.
|
380
285
|
def delete_snapshot snapshot
|
381
|
-
|
382
|
-
subscriber.delete_snapshot snapshot_path(snapshot),
|
383
|
-
options: default_options
|
384
|
-
end
|
286
|
+
subscriber.delete_snapshot snapshot: snapshot_path(snapshot)
|
385
287
|
end
|
386
288
|
|
387
289
|
##
|
388
290
|
# Adjusts the given subscription to a time or snapshot.
|
389
291
|
def seek subscription, time_or_snapshot
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
subscriber.seek subscription,
|
398
|
-
snapshot: snapshot_path(time_or_snapshot),
|
399
|
-
options: default_options
|
400
|
-
end
|
292
|
+
if a_time? time_or_snapshot
|
293
|
+
time = Convert.time_to_timestamp time_or_snapshot
|
294
|
+
subscriber.seek subscription: subscription, time: time
|
295
|
+
else
|
296
|
+
time_or_snapshot = time_or_snapshot.name if time_or_snapshot.is_a? Snapshot
|
297
|
+
subscriber.seek subscription: subscription_path(subscription),
|
298
|
+
snapshot: snapshot_path(time_or_snapshot)
|
401
299
|
end
|
402
300
|
end
|
403
301
|
|
404
302
|
def get_topic_policy topic_name, options = {}
|
405
|
-
|
406
|
-
publisher.get_iam_policy topic_path(topic_name, options),
|
407
|
-
options: default_options
|
408
|
-
end
|
303
|
+
iam.get_iam_policy resource: topic_path(topic_name, options)
|
409
304
|
end
|
410
305
|
|
411
306
|
def set_topic_policy topic_name, new_policy, options = {}
|
412
|
-
resource
|
413
|
-
|
414
|
-
execute do
|
415
|
-
publisher.set_iam_policy resource, new_policy,
|
416
|
-
options: default_options
|
417
|
-
end
|
307
|
+
iam.set_iam_policy resource: topic_path(topic_name, options), policy: new_policy
|
418
308
|
end
|
419
309
|
|
420
310
|
def test_topic_permissions topic_name, permissions, options = {}
|
421
|
-
resource
|
422
|
-
|
423
|
-
execute do
|
424
|
-
publisher.test_iam_permissions resource, permissions,
|
425
|
-
options: default_options
|
426
|
-
end
|
311
|
+
iam.test_iam_permissions resource: topic_path(topic_name, options), permissions: permissions
|
427
312
|
end
|
428
313
|
|
429
314
|
def get_subscription_policy subscription_name, options = {}
|
430
|
-
resource
|
431
|
-
|
432
|
-
execute do
|
433
|
-
subscriber.get_iam_policy resource, options: default_options
|
434
|
-
end
|
315
|
+
iam.get_iam_policy resource: subscription_path(subscription_name, options)
|
435
316
|
end
|
436
317
|
|
437
318
|
def set_subscription_policy subscription_name, new_policy, options = {}
|
438
|
-
resource
|
439
|
-
|
440
|
-
execute do
|
441
|
-
subscriber.set_iam_policy resource, new_policy,
|
442
|
-
options: default_options
|
443
|
-
end
|
319
|
+
iam.set_iam_policy resource: subscription_path(subscription_name, options), policy: new_policy
|
444
320
|
end
|
445
321
|
|
446
|
-
def test_subscription_permissions subscription_name,
|
447
|
-
|
448
|
-
resource = subscription_path subscription_name, options
|
449
|
-
|
450
|
-
execute do
|
451
|
-
subscriber.test_iam_permissions resource, permissions,
|
452
|
-
options: default_options
|
453
|
-
end
|
322
|
+
def test_subscription_permissions subscription_name, permissions, options = {}
|
323
|
+
iam.test_iam_permissions resource: subscription_path(subscription_name, options), permissions: permissions
|
454
324
|
end
|
455
325
|
|
456
326
|
def project_path options = {}
|
@@ -494,21 +364,6 @@ module Google
|
|
494
364
|
end
|
495
365
|
policy
|
496
366
|
end
|
497
|
-
|
498
|
-
def default_headers
|
499
|
-
{ "google-cloud-resource-prefix" => "projects/#{@project}" }
|
500
|
-
end
|
501
|
-
|
502
|
-
def default_options
|
503
|
-
Google::Gax::CallOptions.new kwargs: default_headers
|
504
|
-
end
|
505
|
-
|
506
|
-
def execute
|
507
|
-
yield
|
508
|
-
rescue Google::Gax::GaxError => e
|
509
|
-
# GaxError wraps BadStatus, but exposes it as #cause
|
510
|
-
raise Google::Cloud::Error.from_error(e.cause)
|
511
|
-
end
|
512
367
|
end
|
513
368
|
end
|
514
369
|
|