google-cloud-pubsub 2.22.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/OVERVIEW.md +188 -144
- data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
- data/lib/google/cloud/pubsub/async_publisher.rb +9 -9
- data/lib/google/cloud/pubsub/batch_publisher.rb +4 -4
- data/lib/google/cloud/pubsub/errors.rb +3 -3
- data/lib/google/cloud/pubsub/message.rb +8 -8
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +2 -4
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +10 -10
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +1 -1
- data/lib/google/cloud/pubsub/message_listener.rb +413 -0
- data/lib/google/cloud/pubsub/project.rb +98 -531
- data/lib/google/cloud/pubsub/publisher.rb +373 -0
- data/lib/google/cloud/pubsub/received_message.rb +50 -45
- data/lib/google/cloud/pubsub/service.rb +24 -386
- data/lib/google/cloud/pubsub/subscriber.rb +442 -279
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/cloud/pubsub.rb +8 -15
- data/lib/google-cloud-pubsub.rb +5 -4
- metadata +18 -26
- data/lib/google/cloud/pubsub/policy.rb +0 -188
- data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
- data/lib/google/cloud/pubsub/schema/list.rb +0 -180
- data/lib/google/cloud/pubsub/schema.rb +0 -378
- data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
- data/lib/google/cloud/pubsub/snapshot.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
- data/lib/google/cloud/pubsub/subscription.rb +0 -1467
- data/lib/google/cloud/pubsub/topic/list.rb +0 -171
- data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -0,0 +1,116 @@
|
|
1
|
+
# Copyright 2025 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "google/cloud/pubsub/v1/topic_admin/client"
|
16
|
+
require "google/cloud/pubsub/v1/subscription_admin/client"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module PubSub
|
21
|
+
module TopicAdmin
|
22
|
+
##
|
23
|
+
# The TopicAdmin client is used to manage topics.
|
24
|
+
#
|
25
|
+
# This client is a subclass of the auto-generated TopicAdmin client, and provides
|
26
|
+
# the same methods. However, it raises errors on data plane operations
|
27
|
+
# to prevent misuse.
|
28
|
+
#
|
29
|
+
class Client < Google::Cloud::PubSub::V1::TopicAdmin::Client
|
30
|
+
# @private
|
31
|
+
alias publish_internal publish
|
32
|
+
|
33
|
+
##
|
34
|
+
# The `publish` method is a data plane operation.
|
35
|
+
#
|
36
|
+
# @raise [NotImplementedError] This method is not implemented on the
|
37
|
+
# admin client. Use {Google::Cloud::PubSub::Publisher} instead.
|
38
|
+
#
|
39
|
+
def publish *args, **kwargs
|
40
|
+
raise NotImplementedError,
|
41
|
+
"The `publish` method is a data plane operation. " \
|
42
|
+
"Use Google::Cloud::PubSub::Publisher instead."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module SubscriptionAdmin
|
48
|
+
##
|
49
|
+
# The SubscriptionAdmin client is used to manage subscriptions.
|
50
|
+
#
|
51
|
+
# This client is a subclass of the auto-generated SubscriptionAdmin client, and
|
52
|
+
# provides the same methods. However, it raises errors on data plane
|
53
|
+
# operations to prevent misuse.
|
54
|
+
#
|
55
|
+
class Client < Google::Cloud::PubSub::V1::SubscriptionAdmin::Client
|
56
|
+
# @private
|
57
|
+
alias modify_ack_deadline_internal modify_ack_deadline
|
58
|
+
# @private
|
59
|
+
alias acknowledge_internal acknowledge
|
60
|
+
# @private
|
61
|
+
alias pull_internal pull
|
62
|
+
# @private
|
63
|
+
alias streaming_pull_internal streaming_pull
|
64
|
+
|
65
|
+
##
|
66
|
+
# The `modify_ack_deadline` method is a data plane operation.
|
67
|
+
#
|
68
|
+
# @raise [NotImplementedError] This method is not implemented on the
|
69
|
+
# admin client. Use {Google::Cloud::PubSub::Subscriber} instead.
|
70
|
+
#
|
71
|
+
def modify_ack_deadline *args, **kwargs
|
72
|
+
raise NotImplementedError,
|
73
|
+
"The `modify_ack_deadline` method is a data plane operation. " \
|
74
|
+
"Use Google::Cloud::PubSub::Subscriber instead."
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# The `acknowledge` method is a data plane operation.
|
79
|
+
#
|
80
|
+
# @raise [NotImplementedError] This method is not implemented on the
|
81
|
+
# admin client. Use {Google::Cloud::PubSub::Subscriber} instead.
|
82
|
+
#
|
83
|
+
def acknowledge *args, **kwargs
|
84
|
+
raise NotImplementedError,
|
85
|
+
"The `acknowledge` method is a data plane operation. " \
|
86
|
+
"Use Google::Cloud::PubSub::Subscriber instead."
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# The `pull` method is a data plane operation.
|
91
|
+
#
|
92
|
+
# @raise [NotImplementedError] This method is not implemented on the
|
93
|
+
# admin client. Use {Google::Cloud::PubSub::Subscriber} instead.
|
94
|
+
#
|
95
|
+
def pull *args, **kwargs
|
96
|
+
raise NotImplementedError,
|
97
|
+
"The `pull` method is a data plane operation. " \
|
98
|
+
"Use Google::Cloud::PubSub::Subscriber instead."
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# The `streaming_pull` method is a data plane operation.
|
103
|
+
#
|
104
|
+
# @raise [NotImplementedError] This method is not implemented on the
|
105
|
+
# admin client. Use {Google::Cloud::PubSub::Subscriber} instead.
|
106
|
+
#
|
107
|
+
def streaming_pull *args, **kwargs
|
108
|
+
raise NotImplementedError,
|
109
|
+
"The `streaming_pull` method is a data plane operation. " \
|
110
|
+
"Use Google::Cloud::PubSub::Subscriber instead."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -27,15 +27,15 @@ module Google
|
|
27
27
|
module PubSub
|
28
28
|
##
|
29
29
|
# Used to publish multiple messages in batches to a topic. See
|
30
|
-
# {Google::Cloud::PubSub::
|
30
|
+
# {Google::Cloud::PubSub::Publisher#async_publisher}
|
31
31
|
#
|
32
32
|
# @example
|
33
33
|
# require "google/cloud/pubsub"
|
34
34
|
#
|
35
35
|
# pubsub = Google::Cloud::PubSub.new
|
36
36
|
#
|
37
|
-
#
|
38
|
-
#
|
37
|
+
# publisher = pubsub.publisher "my-topic"
|
38
|
+
# publisher.publish_async "task completed" do |result|
|
39
39
|
# if result.succeeded?
|
40
40
|
# log_publish_success result.data
|
41
41
|
# else
|
@@ -43,7 +43,7 @@ module Google
|
|
43
43
|
# end
|
44
44
|
# end
|
45
45
|
#
|
46
|
-
#
|
46
|
+
# publisher.async_publisher.stop!
|
47
47
|
#
|
48
48
|
# @attr_reader [String] topic_name The name of the topic the messages are published to. The value is a
|
49
49
|
# fully-qualified topic name in the form `projects/{project_id}/topics/{topic_id}`.
|
@@ -116,7 +116,7 @@ module Google
|
|
116
116
|
##
|
117
117
|
# Add a message to the async publisher to be published to the topic.
|
118
118
|
# Messages will be collected in batches and published together.
|
119
|
-
# See {Google::Cloud::PubSub::
|
119
|
+
# See {Google::Cloud::PubSub::Publisher#publish_async}
|
120
120
|
#
|
121
121
|
# @param [String, File] data The message payload. This will be converted
|
122
122
|
# to bytes encoded as ASCII-8BIT.
|
@@ -262,8 +262,8 @@ module Google
|
|
262
262
|
# enabled, messages published with the same `ordering_key` will be
|
263
263
|
# delivered in the order they were published.
|
264
264
|
#
|
265
|
-
# See {#message_ordering?}. See {
|
266
|
-
# {
|
265
|
+
# See {#message_ordering?}. See {Publisher#publish_async},
|
266
|
+
# {Subscriber#listen}, and {Message#ordering_key}.
|
267
267
|
#
|
268
268
|
def enable_message_ordering!
|
269
269
|
synchronize { @ordered = true }
|
@@ -275,8 +275,8 @@ module Google
|
|
275
275
|
# will be delivered in the order they were published. When disabled,
|
276
276
|
# messages may be delivered in any order.
|
277
277
|
#
|
278
|
-
# See {#enable_message_ordering!}. See {
|
279
|
-
# {
|
278
|
+
# See {#enable_message_ordering!}. See {Publisher#publish_async},
|
279
|
+
# {Subscriber#listen}, and {Message#ordering_key}.
|
280
280
|
#
|
281
281
|
# @return [Boolean]
|
282
282
|
#
|
@@ -27,8 +27,8 @@ module Google
|
|
27
27
|
#
|
28
28
|
# pubsub = Google::Cloud::PubSub.new
|
29
29
|
#
|
30
|
-
#
|
31
|
-
# msgs =
|
30
|
+
# publisher = pubsub.publisher "my-topic"
|
31
|
+
# msgs = publisher.publish do |batch_publisher|
|
32
32
|
# batch_publisher.publish "task 1 completed", foo: :bar
|
33
33
|
# batch_publisher.publish "task 2 completed", foo: :baz
|
34
34
|
# batch_publisher.publish "task 3 completed", foo: :bif
|
@@ -86,8 +86,8 @@ module Google
|
|
86
86
|
#
|
87
87
|
# pubsub = Google::Cloud::PubSub.new
|
88
88
|
#
|
89
|
-
#
|
90
|
-
# msgs =
|
89
|
+
# publisher = pubsub.publisher "my-topic"
|
90
|
+
# msgs = publisher.publish do |batch_publisher|
|
91
91
|
# batch_publisher.publish "task 1 completed", foo: :bar
|
92
92
|
# batch_publisher.publish "task 2 completed", foo: :baz
|
93
93
|
# batch_publisher.publish "task 3 completed", foo: :bif
|
@@ -41,7 +41,7 @@ module Google
|
|
41
41
|
end
|
42
42
|
|
43
43
|
##
|
44
|
-
# Indicates that the {
|
44
|
+
# Indicates that the {MessageListener} for a {Subscriber} with message
|
45
45
|
# ordering enabled has observed that a message has been delivered out of
|
46
46
|
# order.
|
47
47
|
#
|
@@ -57,11 +57,11 @@ module Google
|
|
57
57
|
|
58
58
|
##
|
59
59
|
# Indicates that messages using the {#ordering_key} are not being
|
60
|
-
# published due to error. Future calls to {
|
60
|
+
# published due to error. Future calls to {Publisher#publish_async} with the
|
61
61
|
# {#ordering_key} will fail with this error.
|
62
62
|
#
|
63
63
|
# To allow future messages with the {#ordering_key} to be published, the
|
64
|
-
# {#ordering_key} must be passed to {
|
64
|
+
# {#ordering_key} must be passed to {Publisher#resume_publish}.
|
65
65
|
#
|
66
66
|
# If this error is retrieved from {PublishResult#error}, inspect `cause`
|
67
67
|
# for the error raised while publishing.
|
@@ -24,7 +24,7 @@ module Google
|
|
24
24
|
#
|
25
25
|
# Represents a Pub/Sub Message.
|
26
26
|
#
|
27
|
-
# Message objects are created by {
|
27
|
+
# Message objects are created by {Publisher#publish}. {Subscriber#pull}
|
28
28
|
# returns an array of {ReceivedMessage} objects, each of which contains a
|
29
29
|
# Message object. Each {ReceivedMessage} object can be acknowledged and/or
|
30
30
|
# delayed.
|
@@ -35,22 +35,22 @@ module Google
|
|
35
35
|
# pubsub = Google::Cloud::PubSub.new
|
36
36
|
#
|
37
37
|
# # Publish a message
|
38
|
-
#
|
39
|
-
# message =
|
38
|
+
# publisher = pubsub.publisher "my-topic"
|
39
|
+
# message = publisher.publish "task completed"
|
40
40
|
# message.data #=> "task completed"
|
41
41
|
#
|
42
42
|
# # Listen for messages
|
43
|
-
#
|
44
|
-
#
|
43
|
+
# subscriber = pubsub.subscriber "my-topic-sub"
|
44
|
+
# listener = subscriber.listen do |received_message|
|
45
45
|
# # process message
|
46
46
|
# received_message.acknowledge!
|
47
47
|
# end
|
48
48
|
#
|
49
49
|
# # Start background threads that will call the block passed to listen.
|
50
|
-
#
|
50
|
+
# listener.start
|
51
51
|
#
|
52
52
|
# # Shut down the subscriber when ready to stop receiving messages.
|
53
|
-
#
|
53
|
+
# listener.stop!
|
54
54
|
#
|
55
55
|
class Message
|
56
56
|
##
|
@@ -113,7 +113,7 @@ module Google
|
|
113
113
|
# or scalability, as the service automatically distributes messages for
|
114
114
|
# different ordering keys across subscribers.
|
115
115
|
#
|
116
|
-
# See {
|
116
|
+
# See {Publisher#publish_async} and {Subscriber#listen}.
|
117
117
|
#
|
118
118
|
# @return [String]
|
119
119
|
#
|
@@ -18,7 +18,7 @@ require "monitor"
|
|
18
18
|
module Google
|
19
19
|
module Cloud
|
20
20
|
module PubSub
|
21
|
-
class
|
21
|
+
class MessageListener
|
22
22
|
##
|
23
23
|
# @private
|
24
24
|
class Inventory
|
@@ -36,10 +36,9 @@ module Google
|
|
36
36
|
attr_reader :extension
|
37
37
|
attr_reader :max_duration_per_lease_extension
|
38
38
|
attr_accessor :min_duration_per_lease_extension
|
39
|
-
attr_reader :use_legacy_flow_control
|
40
39
|
|
41
40
|
def initialize stream, limit:, bytesize:, extension:, max_duration_per_lease_extension:,
|
42
|
-
min_duration_per_lease_extension
|
41
|
+
min_duration_per_lease_extension:
|
43
42
|
super()
|
44
43
|
@stream = stream
|
45
44
|
@limit = limit
|
@@ -47,7 +46,6 @@ module Google
|
|
47
46
|
@extension = extension
|
48
47
|
@max_duration_per_lease_extension = max_duration_per_lease_extension
|
49
48
|
@min_duration_per_lease_extension = min_duration_per_lease_extension
|
50
|
-
@use_legacy_flow_control = use_legacy_flow_control
|
51
49
|
@inventory = {}
|
52
50
|
@wait_cond = new_cond
|
53
51
|
end
|
@@ -13,9 +13,9 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
require "google/cloud/pubsub/
|
17
|
-
require "google/cloud/pubsub/
|
18
|
-
require "google/cloud/pubsub/
|
16
|
+
require "google/cloud/pubsub/message_listener/sequencer"
|
17
|
+
require "google/cloud/pubsub/message_listener/enumerator_queue"
|
18
|
+
require "google/cloud/pubsub/message_listener/inventory"
|
19
19
|
require "google/cloud/pubsub/service"
|
20
20
|
require "google/cloud/errors"
|
21
21
|
require "monitor"
|
@@ -24,7 +24,7 @@ require "concurrent"
|
|
24
24
|
module Google
|
25
25
|
module Cloud
|
26
26
|
module PubSub
|
27
|
-
class
|
27
|
+
class MessageListener
|
28
28
|
##
|
29
29
|
# @private
|
30
30
|
class Stream
|
@@ -372,8 +372,8 @@ module Google
|
|
372
372
|
end
|
373
373
|
|
374
374
|
def pause_streaming?
|
375
|
-
return if @stopped
|
376
|
-
return if @paused
|
375
|
+
return false if @stopped
|
376
|
+
return false if @paused
|
377
377
|
|
378
378
|
@inventory.full?
|
379
379
|
end
|
@@ -387,8 +387,8 @@ module Google
|
|
387
387
|
end
|
388
388
|
|
389
389
|
def unpause_streaming?
|
390
|
-
return if @stopped
|
391
|
-
return if @paused.nil?
|
390
|
+
return false if @stopped
|
391
|
+
return false if @paused.nil?
|
392
392
|
|
393
393
|
@inventory.count < @inventory.limit * 0.8
|
394
394
|
end
|
@@ -400,8 +400,8 @@ module Google
|
|
400
400
|
req.modify_deadline_ack_ids += @inventory.ack_ids
|
401
401
|
req.modify_deadline_seconds += @inventory.ack_ids.map { @subscriber.deadline }
|
402
402
|
req.client_id = @subscriber.service.client_id
|
403
|
-
req.max_outstanding_messages = @inventory.
|
404
|
-
req.max_outstanding_bytes = @inventory.
|
403
|
+
req.max_outstanding_messages = @inventory.limit
|
404
|
+
req.max_outstanding_bytes = @inventory.bytesize
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|