google-cloud-pubsub 2.11.0 → 2.15.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +8 -26
- data/CHANGELOG.md +69 -0
- data/LOGGING.md +1 -1
- data/lib/google/cloud/pubsub/async_publisher/batch.rb +31 -18
- data/lib/google/cloud/pubsub/async_publisher.rb +11 -3
- data/lib/google/cloud/pubsub/batch_publisher.rb +32 -1
- data/lib/google/cloud/pubsub/project.rb +10 -9
- data/lib/google/cloud/pubsub/received_message.rb +12 -2
- data/lib/google/cloud/pubsub/service.rb +6 -4
- data/lib/google/cloud/pubsub/subscriber/stream.rb +27 -8
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +8 -8
- data/lib/google/cloud/pubsub/subscriber.rb +1 -1
- data/lib/google/cloud/pubsub/subscription.rb +51 -1
- data/lib/google/cloud/pubsub/topic.rb +11 -11
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2a4108df2f16d93f03bb560375274bb816a5958c8c0ad22ca061943ef40ee24
|
4
|
+
data.tar.gz: 8efa65c9aed030d0b1832aa8d0aec7ef4e9d8605a427bef6517cf77d9e363d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1599c8a8adac4fdde84b5782cfa4f4f8c236528452966496a9fce7343b05076772a6c071f99114d7bb93813d0707975e892c262a30616ed13232ce85dfe1b63d
|
7
|
+
data.tar.gz: 1c661569d004bfc3abd20e60938cad744faa5b474a8df6a67f0b6c36e6c428744e76703fc25e73d20298372894880a40a963a923e21059cd9f4f5454c4b65c01
|
data/AUTHENTICATION.md
CHANGED
@@ -125,15 +125,6 @@ To configure your system for this, simply:
|
|
125
125
|
**NOTE:** This is _not_ recommended for running in production. The Cloud SDK
|
126
126
|
*should* only be used during development.
|
127
127
|
|
128
|
-
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
|
129
|
-
[dev-console]: https://console.cloud.google.com/project
|
130
|
-
|
131
|
-
[enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
|
132
|
-
|
133
|
-
[create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
|
134
|
-
[create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
|
135
|
-
[reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
|
136
|
-
|
137
128
|
## Creating a Service Account
|
138
129
|
|
139
130
|
Google Cloud requires a **Project ID** and **Service Account Credentials** to
|
@@ -144,31 +135,22 @@ If you are not running this client within [Google Cloud Platform
|
|
144
135
|
environments](#google-cloud-platform-environments), you need a Google
|
145
136
|
Developers service account.
|
146
137
|
|
147
|
-
1. Visit the [Google
|
138
|
+
1. Visit the [Google Cloud Console](https://console.cloud.google.com/project).
|
148
139
|
1. Create a new project or click on an existing project.
|
149
|
-
1. Activate the
|
140
|
+
1. Activate the menu in the upper left and select **APIs & Services**. From
|
150
141
|
here, you will enable the APIs that your application requires.
|
151
142
|
|
152
|
-
![Enable the APIs that your application requires][enable-apis]
|
153
|
-
|
154
143
|
*Note: You may need to enable billing in order to use these services.*
|
155
144
|
|
156
145
|
1. Select **Credentials** from the side navigation.
|
157
146
|
|
158
|
-
|
159
|
-
|
160
|
-
![Create a new service account][create-new-service-account]
|
161
|
-
|
162
|
-
![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
|
163
|
-
|
164
|
-
Find the "Add credentials" drop down and select "Service account" to be
|
165
|
-
guided through downloading a new JSON key file.
|
166
|
-
|
167
|
-
If you want to re-use an existing service account, you can easily generate a
|
168
|
-
new key file. Just select the account you wish to re-use, and click "Generate
|
169
|
-
new JSON key":
|
147
|
+
Find the "Create credentials" drop down near the top of the page, and select
|
148
|
+
"Service account" to be guided through downloading a new JSON key file.
|
170
149
|
|
171
|
-
|
150
|
+
If you want to re-use an existing service account, you can easily generate
|
151
|
+
a new key file. Just select the account you wish to re-use click the pencil
|
152
|
+
tool on the right side to edit the service account, select the **Keys** tab,
|
153
|
+
and then select **Add Key**.
|
172
154
|
|
173
155
|
The key file you download will be used by this library to authenticate API
|
174
156
|
requests and should be stored in a secure location.
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,74 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.15.5 (2023-11-06)
|
4
|
+
|
5
|
+
#### Bug Fixes
|
6
|
+
|
7
|
+
* set x-goog-request-params for streaming pull request ([#23508](https://github.com/googleapis/google-cloud-ruby/issues/23508))
|
8
|
+
|
9
|
+
### 2.15.4 (2023-05-19)
|
10
|
+
|
11
|
+
#### Documentation
|
12
|
+
|
13
|
+
* Fixed broken links in authentication documentation ([#21619](https://github.com/googleapis/google-cloud-ruby/issues/21619))
|
14
|
+
|
15
|
+
### 2.15.4 (2023-05-18)
|
16
|
+
|
17
|
+
#### Documentation
|
18
|
+
|
19
|
+
* Fixed broken links in authentication documentation ([#21619](https://github.com/googleapis/google-cloud-ruby/issues/21619))
|
20
|
+
|
21
|
+
### 2.15.3 (2023-04-19)
|
22
|
+
|
23
|
+
#### Bug Fixes
|
24
|
+
|
25
|
+
* wait for successful receipt modack when exactly once delivery enabled ([#21431](https://github.com/googleapis/google-cloud-ruby/issues/21431))
|
26
|
+
|
27
|
+
### 2.15.2 (2023-03-19)
|
28
|
+
|
29
|
+
#### Bug Fixes
|
30
|
+
|
31
|
+
* make batch handle publish interval ([#20913](https://github.com/googleapis/google-cloud-ruby/issues/20913))
|
32
|
+
|
33
|
+
### 2.15.1 (2023-02-23)
|
34
|
+
|
35
|
+
#### Documentation
|
36
|
+
|
37
|
+
* Correct default value for streams ([#20485](https://github.com/googleapis/google-cloud-ruby/issues/20485))
|
38
|
+
|
39
|
+
### 2.15.0 (2023-01-22)
|
40
|
+
|
41
|
+
#### Features
|
42
|
+
|
43
|
+
* support publisher compression ([#19910](https://github.com/googleapis/google-cloud-ruby/issues/19910))
|
44
|
+
|
45
|
+
### 2.14.0 (2023-01-12)
|
46
|
+
|
47
|
+
#### Features
|
48
|
+
|
49
|
+
* Added support for schema evolution, including managing schema revisions, and schema commit and rollback ([#19981](https://github.com/googleapis/google-cloud-ruby/issues/19981))
|
50
|
+
|
51
|
+
### 2.13.0 (2022-10-18)
|
52
|
+
|
53
|
+
#### Features
|
54
|
+
|
55
|
+
* Added support for bigquery subscription ([#19221](https://github.com/googleapis/google-cloud-ruby/issues/19221))
|
56
|
+
|
57
|
+
### 2.12.1 (2022-08-21)
|
58
|
+
|
59
|
+
#### Bug Fixes
|
60
|
+
|
61
|
+
* update non EOS ack to return Success always ([#19023](https://github.com/googleapis/google-cloud-ruby/issues/19023))
|
62
|
+
|
63
|
+
### 2.12.0 (2022-08-09)
|
64
|
+
|
65
|
+
#### Features
|
66
|
+
|
67
|
+
* bump the minimum required version of pubsub v1 ([#18983](https://github.com/googleapis/google-cloud-ruby/issues/18983))
|
68
|
+
#### Bug Fixes
|
69
|
+
|
70
|
+
* honour async options of topic ([#18953](https://github.com/googleapis/google-cloud-ruby/issues/18953))
|
71
|
+
|
3
72
|
### 2.11.0 (2022-08-01)
|
4
73
|
|
5
74
|
#### Features
|
data/LOGGING.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
To enable logging for this library, set the logger for the underlying
|
6
6
|
[gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
|
7
7
|
that you set may be a Ruby stdlib
|
8
|
-
[`Logger`](https://ruby-doc.org/
|
8
|
+
[`Logger`](https://ruby-doc.org/current/stdlibs/logger/Logger.html) as
|
9
9
|
shown below, or a
|
10
10
|
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
11
11
|
that will write logs to [Stackdriver
|
@@ -141,7 +141,7 @@ module Google
|
|
141
141
|
|
142
142
|
until @queue.empty?
|
143
143
|
item = @queue.first
|
144
|
-
if try_add item.msg, item.callback
|
144
|
+
if try_add item.msg, item.callback, item.create_time
|
145
145
|
@queue.shift
|
146
146
|
next
|
147
147
|
end
|
@@ -178,12 +178,7 @@ module Google
|
|
178
178
|
return false
|
179
179
|
end
|
180
180
|
|
181
|
-
|
182
|
-
item = @queue.first
|
183
|
-
added = try_add item.msg, item.callback
|
184
|
-
break unless added
|
185
|
-
@queue.shift
|
186
|
-
end
|
181
|
+
refill_items
|
187
182
|
|
188
183
|
return false unless @publishing
|
189
184
|
if @items.empty?
|
@@ -191,6 +186,7 @@ module Google
|
|
191
186
|
return false
|
192
187
|
else
|
193
188
|
return true if stopping?
|
189
|
+
return true if interval_met?(@items.first.create_time) || batch_full_by_count?
|
194
190
|
if @queue.empty?
|
195
191
|
@publishing = false
|
196
192
|
return false
|
@@ -255,18 +251,39 @@ module Google
|
|
255
251
|
end
|
256
252
|
end
|
257
253
|
|
254
|
+
def total_message_bytes
|
255
|
+
@total_message_bytes
|
256
|
+
end
|
257
|
+
|
258
258
|
protected
|
259
259
|
|
260
|
-
def
|
261
|
-
|
260
|
+
def interval_met? create_time
|
261
|
+
Time.now - create_time > @publisher.interval
|
262
|
+
end
|
263
|
+
|
264
|
+
def batch_full_by_count?
|
265
|
+
total_message_count == @publisher.max_messages
|
266
|
+
end
|
267
|
+
|
268
|
+
def refill_items
|
269
|
+
until @queue.empty?
|
270
|
+
item = @queue.first
|
271
|
+
added = try_add item.msg, item.callback, item.create_time
|
272
|
+
break unless added
|
273
|
+
@queue.shift
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
def items_add msg, callback, create_time
|
278
|
+
item = Item.new msg, callback, (create_time || Time.now)
|
262
279
|
@items << item
|
263
280
|
@total_message_bytes += item.bytesize + 2
|
264
281
|
end
|
265
282
|
|
266
|
-
def try_add msg, callback
|
283
|
+
def try_add msg, callback, create_time = nil
|
267
284
|
if @items.empty?
|
268
285
|
# Always add when empty, even if bytesize is bigger than total
|
269
|
-
items_add msg, callback
|
286
|
+
items_add msg, callback, create_time
|
270
287
|
return true
|
271
288
|
end
|
272
289
|
new_message_count = total_message_count + 1
|
@@ -275,12 +292,12 @@ module Google
|
|
275
292
|
new_message_bytes >= @publisher.max_bytes
|
276
293
|
return false
|
277
294
|
end
|
278
|
-
items_add msg, callback
|
295
|
+
items_add msg, callback, create_time
|
279
296
|
true
|
280
297
|
end
|
281
298
|
|
282
299
|
def queue_add msg, callback
|
283
|
-
item = Item.new msg, callback
|
300
|
+
item = Item.new msg, callback, Time.now
|
284
301
|
@queue << item
|
285
302
|
end
|
286
303
|
|
@@ -288,11 +305,7 @@ module Google
|
|
288
305
|
@items.count
|
289
306
|
end
|
290
307
|
|
291
|
-
|
292
|
-
@total_message_bytes
|
293
|
-
end
|
294
|
-
|
295
|
-
Item = Struct.new :msg, :callback do
|
308
|
+
Item = Struct.new :msg, :callback, :create_time do
|
296
309
|
def bytesize
|
297
310
|
msg.to_proto.bytesize
|
298
311
|
end
|
@@ -70,7 +70,8 @@ module Google
|
|
70
70
|
##
|
71
71
|
# @private Implementation accessors
|
72
72
|
attr_reader :service, :batch, :publish_thread_pool,
|
73
|
-
:callback_thread_pool, :flow_controller
|
73
|
+
:callback_thread_pool, :flow_controller,
|
74
|
+
:compress, :compression_bytes_threshold
|
74
75
|
|
75
76
|
##
|
76
77
|
# @private Create a new instance of the object.
|
@@ -80,7 +81,9 @@ module Google
|
|
80
81
|
max_messages: 100,
|
81
82
|
interval: 0.01,
|
82
83
|
threads: {},
|
83
|
-
flow_control: {}
|
84
|
+
flow_control: {},
|
85
|
+
compress: nil,
|
86
|
+
compression_bytes_threshold: nil
|
84
87
|
# init MonitorMixin
|
85
88
|
super()
|
86
89
|
@topic_name = service.topic_path topic_name
|
@@ -105,6 +108,9 @@ module Google
|
|
105
108
|
@cond = new_cond
|
106
109
|
@flow_controller = FlowController.new(**@flow_control)
|
107
110
|
@thread = Thread.new { run_background }
|
111
|
+
@compress = compress || Google::Cloud::PubSub::DEFAULT_COMPRESS
|
112
|
+
@compression_bytes_threshold = compression_bytes_threshold ||
|
113
|
+
Google::Cloud::PubSub::DEFAULT_COMPRESSION_BYTES_THRESHOLD
|
108
114
|
end
|
109
115
|
|
110
116
|
##
|
@@ -370,7 +376,9 @@ module Google
|
|
370
376
|
items = batch.rebalance!
|
371
377
|
|
372
378
|
unless items.empty?
|
373
|
-
grpc = @service.publish topic_name,
|
379
|
+
grpc = @service.publish topic_name,
|
380
|
+
items.map(&:msg),
|
381
|
+
compress: compress && batch.total_message_bytes >= compression_bytes_threshold
|
374
382
|
items.zip Array(grpc.message_ids) do |item, id|
|
375
383
|
@flow_controller.release item.bytesize
|
376
384
|
next unless item.callback
|
@@ -39,11 +39,32 @@ module Google
|
|
39
39
|
# @private The messages to publish
|
40
40
|
attr_reader :messages
|
41
41
|
|
42
|
+
##
|
43
|
+
# @private Enables publisher compression
|
44
|
+
attr_reader :compress
|
45
|
+
|
46
|
+
##
|
47
|
+
# @private The threshold bytes size for compression
|
48
|
+
attr_reader :compression_bytes_threshold
|
49
|
+
|
50
|
+
##
|
51
|
+
# @private The total bytes size of messages data.
|
52
|
+
attr_reader :total_message_bytes
|
53
|
+
|
42
54
|
##
|
43
55
|
# @private Create a new instance of the object.
|
44
|
-
def initialize data,
|
56
|
+
def initialize data,
|
57
|
+
attributes,
|
58
|
+
ordering_key,
|
59
|
+
extra_attrs,
|
60
|
+
compress: nil,
|
61
|
+
compression_bytes_threshold: nil
|
45
62
|
@messages = []
|
46
63
|
@mode = :batch
|
64
|
+
@compress = compress || Google::Cloud::PubSub::DEFAULT_COMPRESS
|
65
|
+
@compression_bytes_threshold = compression_bytes_threshold ||
|
66
|
+
Google::Cloud::PubSub::DEFAULT_COMPRESSION_BYTES_THRESHOLD
|
67
|
+
@total_message_bytes = 0
|
47
68
|
return if data.nil?
|
48
69
|
@mode = :single
|
49
70
|
publish data, attributes, ordering_key: ordering_key, **extra_attrs
|
@@ -74,6 +95,7 @@ module Google
|
|
74
95
|
#
|
75
96
|
def publish data, attributes = nil, ordering_key: nil, **extra_attrs
|
76
97
|
msg = Convert.pubsub_message data, attributes, ordering_key, extra_attrs
|
98
|
+
@total_message_bytes += msg.data.bytesize + 2
|
77
99
|
@messages << msg
|
78
100
|
end
|
79
101
|
|
@@ -92,6 +114,15 @@ module Google
|
|
92
114
|
msgs
|
93
115
|
end
|
94
116
|
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# @private Call the publish API with arrays of data and attrs.
|
120
|
+
def publish_batch_messages topic_name, service
|
121
|
+
grpc = service.publish topic_name,
|
122
|
+
messages,
|
123
|
+
compress: compress && total_message_bytes >= compression_bytes_threshold
|
124
|
+
to_gcloud_messages Array(grpc.message_ids)
|
125
|
+
end
|
95
126
|
end
|
96
127
|
end
|
97
128
|
|
@@ -24,6 +24,9 @@ require "google/cloud/pubsub/snapshot"
|
|
24
24
|
module Google
|
25
25
|
module Cloud
|
26
26
|
module PubSub
|
27
|
+
DEFAULT_COMPRESS = false
|
28
|
+
DEFAULT_COMPRESSION_BYTES_THRESHOLD = 240
|
29
|
+
|
27
30
|
##
|
28
31
|
# # Project
|
29
32
|
#
|
@@ -103,6 +106,9 @@ module Google
|
|
103
106
|
# * `:threads` (Hash) The number of threads to create to handle concurrent calls by the publisher:
|
104
107
|
# * `:publish` (Integer) The number of threads used to publish messages. Default is 2.
|
105
108
|
# * `:callback` (Integer) The number of threads to handle the published messages' callbacks. Default is 4.
|
109
|
+
# * `:compress` (Boolean) The flag that enables publisher compression. Default is false
|
110
|
+
# * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
|
111
|
+
# Default is 240.
|
106
112
|
# * `:flow_control` (Hash) The client flow control settings for message publishing:
|
107
113
|
# * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
|
108
114
|
# `10 * max_messages`.
|
@@ -160,7 +166,7 @@ module Google
|
|
160
166
|
#
|
161
167
|
def topic topic_name, project: nil, skip_lookup: nil, async: nil
|
162
168
|
ensure_service!
|
163
|
-
options = { project: project }
|
169
|
+
options = { project: project, async: async }
|
164
170
|
return Topic.from_name topic_name, service, options if skip_lookup
|
165
171
|
grpc = service.get_topic topic_name, options
|
166
172
|
Topic.from_grpc grpc, service, async: async
|
@@ -211,11 +217,13 @@ module Google
|
|
211
217
|
# the batch is published. Default is 0.01.
|
212
218
|
# * `:threads` (Hash) The number of threads to create to handle concurrent
|
213
219
|
# calls by the publisher:
|
214
|
-
#
|
215
220
|
# * `:publish` (Integer) The number of threads used to publish messages.
|
216
221
|
# Default is 2.
|
217
222
|
# * `:callback` (Integer) The number of threads to handle the published
|
218
223
|
# messages' callbacks. Default is 4.
|
224
|
+
# * `:compress` (Boolean) The flag that enables publisher compression. Default is false
|
225
|
+
# * `:compression_bytes_threshold` (Integer) The number of bytes above which compress should be enabled.
|
226
|
+
# Default is 240.
|
219
227
|
# * `:flow_control` (Hash) The client flow control settings for message publishing:
|
220
228
|
# * `:message_limit` (Integer) The maximum number of messages allowed to wait to be published. Default is
|
221
229
|
# `10 * max_messages`.
|
@@ -642,13 +650,6 @@ module Google
|
|
642
650
|
def ensure_service!
|
643
651
|
raise "Must have active connection to service" unless service
|
644
652
|
end
|
645
|
-
|
646
|
-
##
|
647
|
-
# Call the publish API with arrays of data data and attrs.
|
648
|
-
def publish_batch_messages topic_name, batch
|
649
|
-
grpc = service.publish topic_name, batch.messages
|
650
|
-
batch.to_gcloud_messages Array(grpc.message_ids)
|
651
|
-
end
|
652
653
|
end
|
653
654
|
end
|
654
655
|
|
@@ -204,7 +204,12 @@ module Google
|
|
204
204
|
#
|
205
205
|
def acknowledge! &block
|
206
206
|
ensure_subscription!
|
207
|
-
subscription.
|
207
|
+
if subscription.respond_to?(:exactly_once_delivery_enabled) && subscription.exactly_once_delivery_enabled
|
208
|
+
subscription.acknowledge ack_id, &block
|
209
|
+
else
|
210
|
+
subscription.acknowledge ack_id
|
211
|
+
yield AcknowledgeResult.new(AcknowledgeResult::SUCCESS) if block_given?
|
212
|
+
end
|
208
213
|
end
|
209
214
|
alias ack! acknowledge!
|
210
215
|
|
@@ -265,7 +270,12 @@ module Google
|
|
265
270
|
#
|
266
271
|
def modify_ack_deadline! new_deadline, &block
|
267
272
|
ensure_subscription!
|
268
|
-
subscription.
|
273
|
+
if subscription.respond_to?(:exactly_once_delivery_enabled) && subscription.exactly_once_delivery_enabled
|
274
|
+
subscription.modify_ack_deadline new_deadline, ack_id, &block
|
275
|
+
else
|
276
|
+
subscription.modify_ack_deadline new_deadline, ack_id
|
277
|
+
yield AcknowledgeResult.new(AcknowledgeResult::SUCCESS) if block_given?
|
278
|
+
end
|
269
279
|
end
|
270
280
|
|
271
281
|
##
|
@@ -173,8 +173,10 @@ module Google
|
|
173
173
|
# Raises GRPC status code 5 if the topic does not exist.
|
174
174
|
# The messages parameter is an array of arrays.
|
175
175
|
# The first element is the data, second is attributes hash.
|
176
|
-
def publish topic, messages
|
177
|
-
|
176
|
+
def publish topic, messages, compress: false
|
177
|
+
request = { topic: topic_path(topic), messages: messages }
|
178
|
+
compress_options = ::Gapic::CallOptions.new metadata: { "grpc-internal-encoding-request": "gzip" }
|
179
|
+
compress ? (publisher.publish request, compress_options) : (publisher.publish request)
|
178
180
|
end
|
179
181
|
|
180
182
|
##
|
@@ -238,8 +240,8 @@ module Google
|
|
238
240
|
return_immediately: return_immediately
|
239
241
|
end
|
240
242
|
|
241
|
-
def streaming_pull request_enum
|
242
|
-
subscriber.streaming_pull request_enum
|
243
|
+
def streaming_pull request_enum, options = {}
|
244
|
+
subscriber.streaming_pull request_enum, options
|
243
245
|
end
|
244
246
|
|
245
247
|
##
|
@@ -231,7 +231,8 @@ module Google
|
|
231
231
|
end
|
232
232
|
|
233
233
|
# Call the StreamingPull API to get the response enumerator
|
234
|
-
|
234
|
+
options = { :"metadata" => { :"x-goog-request-params" => @subscriber.subscription_name } }
|
235
|
+
enum = @subscriber.service.streaming_pull @request_queue.each, options
|
235
236
|
|
236
237
|
loop do
|
237
238
|
synchronize do
|
@@ -248,25 +249,30 @@ module Google
|
|
248
249
|
# Cannot syncronize the enumerator, causes deadlock
|
249
250
|
response = enum.next
|
250
251
|
new_exactly_once_delivery_enabled = response&.subscription_properties&.exactly_once_delivery_enabled
|
252
|
+
received_messages = response.received_messages
|
251
253
|
|
252
254
|
# Use synchronize so changes happen atomically
|
253
255
|
synchronize do
|
254
256
|
update_min_duration_per_lease_extension new_exactly_once_delivery_enabled
|
255
|
-
@exactly_once_delivery_enabled = new_exactly_once_delivery_enabled unless new_exactly_once_delivery_enabled.nil?
|
257
|
+
@exactly_once_delivery_enabled = new_exactly_once_delivery_enabled unless new_exactly_once_delivery_enabled.nil?
|
256
258
|
@subscriber.exactly_once_delivery_enabled = @exactly_once_delivery_enabled
|
257
259
|
|
258
260
|
# Create receipt of received messages reception
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
261
|
+
if @exactly_once_delivery_enabled
|
262
|
+
create_receipt_modack_for_eos received_messages
|
263
|
+
else
|
264
|
+
@subscriber.buffer.modify_ack_deadline @subscriber.deadline, received_messages.map(&:ack_id)
|
265
|
+
# Add received messages to inventory
|
266
|
+
@inventory.add received_messages
|
267
|
+
end
|
263
268
|
end
|
264
269
|
|
265
|
-
|
270
|
+
received_messages.each do |rec_msg_grpc|
|
266
271
|
rec_msg = ReceivedMessage.from_grpc(rec_msg_grpc, self)
|
267
272
|
# No need to synchronize the callback future
|
268
273
|
register_callback rec_msg
|
269
|
-
end
|
274
|
+
end if !@exactly_once_delivery_enabled # Exactly once delivery scenario is handled by callback
|
275
|
+
|
270
276
|
synchronize { pause_streaming! }
|
271
277
|
rescue StopIteration
|
272
278
|
break
|
@@ -295,6 +301,19 @@ module Google
|
|
295
301
|
|
296
302
|
# rubocop:enable all
|
297
303
|
|
304
|
+
def create_receipt_modack_for_eos received_messages
|
305
|
+
received_messages.each do |rec_msg_grpc|
|
306
|
+
callback = proc do |result|
|
307
|
+
if result.succeeded?
|
308
|
+
synchronize { @inventory.add rec_msg_grpc }
|
309
|
+
rec_msg = ReceivedMessage.from_grpc rec_msg_grpc, self
|
310
|
+
register_callback rec_msg
|
311
|
+
end
|
312
|
+
end
|
313
|
+
@subscriber.buffer.modify_ack_deadline @subscriber.deadline, [rec_msg_grpc.ack_id], callback
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
298
317
|
# Updates min_duration_per_lease_extension to 60 when exactly_once_delivery_enabled
|
299
318
|
# and reverts back to default 0 when disabled.
|
300
319
|
# Skips if exactly_once_enabled is not modified.
|
@@ -35,11 +35,11 @@ module Google
|
|
35
35
|
|
36
36
|
PERMANENT_FAILURE = "PERMANENT_FAILURE".freeze
|
37
37
|
# Google::Cloud::Unavailable error is already retried at gapic level
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
EXACTLY_ONCE_DELIVERY_POSSIBLE_RETRIABLE_ERRORS = [Google::Cloud::CanceledError,
|
39
|
+
Google::Cloud::DeadlineExceededError,
|
40
|
+
Google::Cloud::InternalError,
|
41
|
+
Google::Cloud::ResourceExhaustedError,
|
42
|
+
Google::Cloud::InvalidArgumentError].freeze
|
43
43
|
MAX_RETRY_DURATION = 600 # 600s since the server allows ack/modacks for 10 mins max
|
44
44
|
MAX_TRIES = 15
|
45
45
|
BASE_INTERVAL = 1
|
@@ -128,7 +128,7 @@ module Google
|
|
128
128
|
begin
|
129
129
|
@subscriber.service.acknowledge ack_req.subscription, *ack_req.ack_ids
|
130
130
|
handle_callback AcknowledgeResult.new(AcknowledgeResult::SUCCESS), ack_req.ack_ids
|
131
|
-
rescue *
|
131
|
+
rescue *EXACTLY_ONCE_DELIVERY_POSSIBLE_RETRIABLE_ERRORS => e
|
132
132
|
handle_failure e, ack_req.ack_ids if @subscriber.exactly_once_delivery_enabled
|
133
133
|
rescue StandardError => e
|
134
134
|
handle_callback construct_result(e), ack_req.ack_ids
|
@@ -146,7 +146,7 @@ module Google
|
|
146
146
|
handle_callback AcknowledgeResult.new(AcknowledgeResult::SUCCESS),
|
147
147
|
mod_ack_req.ack_ids,
|
148
148
|
modack: true
|
149
|
-
rescue *
|
149
|
+
rescue *EXACTLY_ONCE_DELIVERY_POSSIBLE_RETRIABLE_ERRORS => e
|
150
150
|
if @subscriber.exactly_once_delivery_enabled
|
151
151
|
handle_failure e, mod_ack_req.ack_ids, mod_ack_req.ack_deadline_seconds
|
152
152
|
end
|
@@ -276,7 +276,7 @@ module Google
|
|
276
276
|
max_interval: MAX_INTERVAL,
|
277
277
|
multiplier: MULTIPLIER,
|
278
278
|
max_elapsed_time: MAX_RETRY_DURATION,
|
279
|
-
on:
|
279
|
+
on: EXACTLY_ONCE_DELIVERY_POSSIBLE_RETRIABLE_ERRORS do
|
280
280
|
return if ack_ids.nil?
|
281
281
|
begin
|
282
282
|
yield ack_ids
|
@@ -53,7 +53,7 @@ module Google
|
|
53
53
|
# @attr_reader [Boolean] message_ordering Whether message ordering has
|
54
54
|
# been enabled.
|
55
55
|
# @attr_reader [Integer] streams The number of concurrent streams to open
|
56
|
-
# to pull messages from the subscription. Default is
|
56
|
+
# to pull messages from the subscription. Default is 2.
|
57
57
|
# @attr_reader [Integer] callback_threads The number of threads used to
|
58
58
|
# handle the received messages. Default is 8.
|
59
59
|
# @attr_reader [Integer] push_threads The number of threads to handle
|
@@ -303,6 +303,56 @@ module Google
|
|
303
303
|
config.freeze
|
304
304
|
end
|
305
305
|
|
306
|
+
##
|
307
|
+
# Inspect the Subscription's bigquery configuration settings. The
|
308
|
+
# configuration can be changed by modifying the values in the method's
|
309
|
+
# block.
|
310
|
+
#
|
311
|
+
# @yield [bigquery_config] a block for modifying the bigquery configuration
|
312
|
+
# @yieldparam [Google::Cloud::PubSub::V1::BigQueryConfig] bigquery_config
|
313
|
+
#
|
314
|
+
# @return [Google::Cloud::PubSub::V1::BigQueryConfig]
|
315
|
+
#
|
316
|
+
# @example
|
317
|
+
# require "google/cloud/pubsub"
|
318
|
+
#
|
319
|
+
# pubsub = Google::Cloud::PubSub.new
|
320
|
+
#
|
321
|
+
# sub = pubsub.subscription "my-topic-sub"
|
322
|
+
# sub.bigquery_config.table #=> "my-project:dataset-id.table-id"
|
323
|
+
# sub.bigquery_config.use_topic_schema #=> true
|
324
|
+
# sub.bigquery_config.write_metadata #=> false
|
325
|
+
#
|
326
|
+
# @example Update the bigquery configuration by passing a block:
|
327
|
+
# require "google/cloud/pubsub"
|
328
|
+
#
|
329
|
+
# pubsub = Google::Cloud::PubSub.new
|
330
|
+
# sub = pubsub.subscription "my-subscription"
|
331
|
+
#
|
332
|
+
# sub.bigquery_config do |bc|
|
333
|
+
# bc.write_metadata = true
|
334
|
+
# bc.use_topic_schema = false
|
335
|
+
# end
|
336
|
+
#
|
337
|
+
def bigquery_config
|
338
|
+
ensure_service!
|
339
|
+
|
340
|
+
config = reference? ? Google::Cloud::PubSub::V1::BigQueryConfig.new : @grpc.bigquery_config
|
341
|
+
|
342
|
+
if block_given?
|
343
|
+
old_config = config.dup
|
344
|
+
yield config
|
345
|
+
new_config = config
|
346
|
+
|
347
|
+
if old_config != new_config # has the object been changed?
|
348
|
+
update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, bigquery_config: new_config
|
349
|
+
@grpc = service.update_subscription update_grpc, :bigquery_config
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
config.freeze
|
354
|
+
end
|
355
|
+
|
306
356
|
##
|
307
357
|
# A hash of user-provided labels associated with this subscription.
|
308
358
|
# Labels can be used to organize and group subscriptions.See [Creating
|
@@ -887,7 +937,7 @@ module Google
|
|
887
937
|
# the default message_ordering value for the subscription when this
|
888
938
|
# argument is not provided. See {#reference?}.
|
889
939
|
# @param [Integer] streams The number of concurrent streams to open to
|
890
|
-
# pull messages from the subscription. Default is
|
940
|
+
# pull messages from the subscription. Default is 2. Optional.
|
891
941
|
# @param [Hash, Integer] inventory The settings to control how received messages are to be handled by the
|
892
942
|
# subscriber. When provided as an Integer instead of a Hash only `max_outstanding_messages` will be set.
|
893
943
|
# Optional.
|
@@ -676,12 +676,19 @@ module Google
|
|
676
676
|
# topic.publish "task completed",
|
677
677
|
# ordering_key: "task-key"
|
678
678
|
#
|
679
|
-
def publish data = nil, attributes = nil, ordering_key: nil,
|
679
|
+
def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, compression_bytes_threshold: nil,
|
680
|
+
**extra_attrs, &block
|
680
681
|
ensure_service!
|
681
|
-
batch = BatchPublisher.new data,
|
682
|
+
batch = BatchPublisher.new data,
|
683
|
+
attributes,
|
684
|
+
ordering_key,
|
685
|
+
extra_attrs,
|
686
|
+
compress: compress,
|
687
|
+
compression_bytes_threshold: compression_bytes_threshold
|
688
|
+
|
682
689
|
block&.call batch
|
683
690
|
return nil if batch.messages.count.zero?
|
684
|
-
publish_batch_messages
|
691
|
+
batch.publish_batch_messages name, service
|
685
692
|
end
|
686
693
|
|
687
694
|
##
|
@@ -1065,7 +1072,7 @@ module Google
|
|
1065
1072
|
# @private New reference {Topic} object without making an HTTP request.
|
1066
1073
|
def self.from_name name, service, options = {}
|
1067
1074
|
name = service.topic_path name, options
|
1068
|
-
from_grpc(nil, service).tap do |t|
|
1075
|
+
from_grpc(nil, service, async: options[:async]).tap do |t|
|
1069
1076
|
t.instance_variable_set :@resource_name, name
|
1070
1077
|
end
|
1071
1078
|
end
|
@@ -1085,13 +1092,6 @@ module Google
|
|
1085
1092
|
ensure_service!
|
1086
1093
|
reload! if reference?
|
1087
1094
|
end
|
1088
|
-
|
1089
|
-
##
|
1090
|
-
# Call the publish API with arrays of data data and attrs.
|
1091
|
-
def publish_batch_messages batch
|
1092
|
-
grpc = service.publish name, batch.messages
|
1093
|
-
batch.to_gcloud_messages Array(grpc.message_ids)
|
1094
|
-
end
|
1095
1095
|
end
|
1096
1096
|
end
|
1097
1097
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.15.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.8'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0.
|
55
|
+
version: '0.8'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: retriable
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -291,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
291
|
- !ruby/object:Gem::Version
|
292
292
|
version: '0'
|
293
293
|
requirements: []
|
294
|
-
rubygems_version: 3.
|
294
|
+
rubygems_version: 3.4.19
|
295
295
|
signing_key:
|
296
296
|
specification_version: 4
|
297
297
|
summary: API Client library for Google Cloud Pub/Sub
|