message_bus 4.3.7 → 4.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/lib/message_bus/backends/redis.rb +63 -77
- data/lib/message_bus/rack/middleware.rb +3 -1
- data/lib/message_bus/version.rb +1 -1
- data/package-lock.json +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8919c0fad186b16833bee6f60c2cbab838be989395dbb63d5ea83ea25770a817
|
4
|
+
data.tar.gz: 12223e8d6cb7c4ef043ea4bfed14e0993a0d826380c4a3f5d8faed4fa55bfc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecc907090650eb544f36dee2f1ffac2e5e27408ff570d91d104ba118f20c03d9815dc441e08929128d60bb54640e929ea1ca0123bf9790f9caf562e6860441ee
|
7
|
+
data.tar.gz: a899cf220f0838916462e97146d50c0a297237c0f0569abf92da8d401a02f5a303ef769cb3318e33c4ffcef99092b01845bb6070c9b4282eb8c0cd08de37091e
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
14-09-2023
|
2
|
+
|
3
|
+
- Version 4.3.8
|
4
|
+
|
5
|
+
- FIX: Typo in `group_ids_lookup` option name in Redis params exclusion list that was preventing the use of the redis backend along with this option.
|
6
|
+
- FIX: Removes close_db_connection! deprecation warning.
|
7
|
+
|
1
8
|
28-06-2023
|
2
9
|
|
3
10
|
- Version 4.3.7
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "redis"
|
4
|
+
require "digest"
|
5
5
|
|
6
6
|
module MessageBus
|
7
7
|
module Backends
|
@@ -49,9 +49,7 @@ module MessageBus
|
|
49
49
|
@redis_config = redis_config.dup
|
50
50
|
@clear_every = redis_config.delete(:clear_every) || 1
|
51
51
|
@logger = @redis_config[:logger]
|
52
|
-
unless @redis_config[:enable_redis_logger]
|
53
|
-
@redis_config[:logger] = nil
|
54
|
-
end
|
52
|
+
@redis_config[:logger] = nil unless @redis_config[:enable_redis_logger]
|
55
53
|
@max_backlog_size = max_backlog_size
|
56
54
|
@max_global_backlog_size = 2000
|
57
55
|
@max_in_memory_publish_backlog = 1000
|
@@ -61,7 +59,7 @@ module MessageBus
|
|
61
59
|
@pub_redis = nil
|
62
60
|
@subscribed = false
|
63
61
|
# after 7 days inactive backlogs will be removed
|
64
|
-
@max_backlog_age =
|
62
|
+
@max_backlog_age = 604_800
|
65
63
|
end
|
66
64
|
|
67
65
|
# Reconnects to Redis; used after a process fork, typically triggered by a forking webserver
|
@@ -72,9 +70,7 @@ module MessageBus
|
|
72
70
|
|
73
71
|
# (see Base#reset!)
|
74
72
|
def reset!
|
75
|
-
pub_redis.keys("__mb_*").each
|
76
|
-
pub_redis.del k
|
77
|
-
end
|
73
|
+
pub_redis.keys("__mb_*").each { |k| pub_redis.del k }
|
78
74
|
end
|
79
75
|
|
80
76
|
# (see Base#destroy)
|
@@ -85,9 +81,7 @@ module MessageBus
|
|
85
81
|
# Deletes all backlogs and their data. Does not delete ID pointers, so new publications will get IDs that continue from the last publication before the expiry. Use with extreme caution.
|
86
82
|
# @see Base#expire_all_backlogs!
|
87
83
|
def expire_all_backlogs!
|
88
|
-
pub_redis.keys("__mb_*backlog_n").each
|
89
|
-
pub_redis.del k
|
90
|
-
end
|
84
|
+
pub_redis.keys("__mb_*backlog_n").each { |k| pub_redis.del k }
|
91
85
|
end
|
92
86
|
|
93
87
|
# Note, the script takes care of all expiry of keys, however
|
@@ -157,15 +151,15 @@ LUA
|
|
157
151
|
max_backlog_size,
|
158
152
|
max_global_backlog_size,
|
159
153
|
channel,
|
160
|
-
clear_every
|
154
|
+
clear_every,
|
161
155
|
],
|
162
156
|
keys: [
|
163
157
|
global_id_key,
|
164
158
|
backlog_id_key,
|
165
159
|
backlog_key,
|
166
160
|
global_backlog_key,
|
167
|
-
redis_channel_name
|
168
|
-
]
|
161
|
+
redis_channel_name,
|
162
|
+
],
|
169
163
|
)
|
170
164
|
rescue ::Redis::CommandError => e
|
171
165
|
if queue_in_memory && e.message =~ /READONLY/
|
@@ -173,7 +167,9 @@ LUA
|
|
173
167
|
@in_memory_backlog << [channel, data]
|
174
168
|
if @in_memory_backlog.length > @max_in_memory_publish_backlog
|
175
169
|
@in_memory_backlog.delete_at(0)
|
176
|
-
@logger.warn(
|
170
|
+
@logger.warn(
|
171
|
+
"Dropping old message cause max_in_memory_publish_backlog is full: #{e.message}\n#{e.backtrace.join('\n')}",
|
172
|
+
)
|
177
173
|
end
|
178
174
|
end
|
179
175
|
|
@@ -209,9 +205,7 @@ LUA
|
|
209
205
|
backlog_key = backlog_key(channel)
|
210
206
|
items = redis.zrangebyscore backlog_key, last_id.to_i + 1, "+inf"
|
211
207
|
|
212
|
-
items.map
|
213
|
-
MessageBus::Message.decode(i)
|
214
|
-
end
|
208
|
+
items.map { |i| MessageBus::Message.decode(i) }
|
215
209
|
end
|
216
210
|
|
217
211
|
# (see Base#global_backlog)
|
@@ -254,13 +248,9 @@ LUA
|
|
254
248
|
# we are subscribing on global and global is always going to be bigger than local
|
255
249
|
# so worst case is a replay of a few messages
|
256
250
|
message = get_message(channel, last_id)
|
257
|
-
if message
|
258
|
-
last_id = message.global_id
|
259
|
-
end
|
260
|
-
end
|
261
|
-
global_subscribe(last_id) do |m|
|
262
|
-
yield m if m.channel == channel
|
251
|
+
last_id = message.global_id if message
|
263
252
|
end
|
253
|
+
global_subscribe(last_id) { |m| yield m if m.channel == channel }
|
264
254
|
end
|
265
255
|
|
266
256
|
# (see Base#global_unsubscribe)
|
@@ -280,36 +270,31 @@ LUA
|
|
280
270
|
|
281
271
|
highest_id = last_id
|
282
272
|
|
283
|
-
clear_backlog =
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
273
|
+
clear_backlog =
|
274
|
+
lambda do
|
275
|
+
retries = 4
|
276
|
+
begin
|
277
|
+
highest_id = process_global_backlog(highest_id, retries > 0, &blk)
|
278
|
+
rescue BackLogOutOfOrder => e
|
279
|
+
highest_id = e.highest_id
|
280
|
+
retries -= 1
|
281
|
+
sleep(rand(50) / 1000.0)
|
282
|
+
retry
|
283
|
+
end
|
292
284
|
end
|
293
|
-
end
|
294
285
|
|
295
286
|
begin
|
296
287
|
global_redis = new_redis_connection
|
297
288
|
|
298
|
-
if highest_id
|
299
|
-
clear_backlog.call(&blk)
|
300
|
-
end
|
289
|
+
clear_backlog.call(&blk) if highest_id
|
301
290
|
|
302
291
|
global_redis.subscribe(redis_channel_name) do |on|
|
303
292
|
on.subscribe do
|
304
|
-
if highest_id
|
305
|
-
clear_backlog.call(&blk)
|
306
|
-
end
|
293
|
+
clear_backlog.call(&blk) if highest_id
|
307
294
|
@subscribed = true
|
308
295
|
end
|
309
296
|
|
310
|
-
on.unsubscribe
|
311
|
-
@subscribed = false
|
312
|
-
end
|
297
|
+
on.unsubscribe { @subscribed = false }
|
313
298
|
|
314
299
|
on.message do |_c, m|
|
315
300
|
if m == UNSUB_MESSAGE
|
@@ -346,29 +331,30 @@ LUA
|
|
346
331
|
private
|
347
332
|
|
348
333
|
def new_redis_connection
|
349
|
-
config =
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
334
|
+
config =
|
335
|
+
@redis_config.filter do |k, v|
|
336
|
+
# This is not ideal, required for Redis gem version 5
|
337
|
+
# redis-client no longer accepts arbitrary params
|
338
|
+
# anything unknown will error out.
|
339
|
+
# https://github.com/redis-rb/redis-client/blob/4c8e05acfb3477c1651138a4924616e79e6116f2/lib/redis_client/config.rb#L21-L39
|
340
|
+
#
|
341
|
+
#
|
342
|
+
# We should be doing the opposite and allowlisting params
|
343
|
+
# or splitting the object up. Starting with the smallest change that is backwards compatible
|
344
|
+
!%i[
|
345
|
+
backend
|
346
|
+
logger
|
347
|
+
long_polling_enabled
|
348
|
+
long_polling_interval
|
349
|
+
backend_options
|
350
|
+
base_route
|
351
|
+
client_message_filters
|
352
|
+
site_id_lookup
|
353
|
+
group_ids_lookup
|
354
|
+
user_id_lookup
|
355
|
+
transport_codec
|
356
|
+
].include?(k)
|
357
|
+
end
|
372
358
|
::Redis.new(config)
|
373
359
|
end
|
374
360
|
|
@@ -399,9 +385,7 @@ LUA
|
|
399
385
|
end
|
400
386
|
|
401
387
|
def process_global_backlog(highest_id, raise_error)
|
402
|
-
if highest_id > pub_redis.get(global_id_key).to_i
|
403
|
-
highest_id = 0
|
404
|
-
end
|
388
|
+
highest_id = 0 if highest_id > pub_redis.get(global_id_key).to_i
|
405
389
|
|
406
390
|
global_backlog(highest_id).each do |old|
|
407
391
|
if highest_id + 1 == old.global_id
|
@@ -444,19 +428,21 @@ LUA
|
|
444
428
|
if e.message =~ /^READONLY/
|
445
429
|
try_again = true
|
446
430
|
else
|
447
|
-
@logger.warn(
|
431
|
+
@logger.warn(
|
432
|
+
"Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}",
|
433
|
+
)
|
448
434
|
end
|
449
435
|
rescue => e
|
450
|
-
@logger.warn(
|
436
|
+
@logger.warn(
|
437
|
+
"Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}",
|
438
|
+
)
|
451
439
|
end
|
452
440
|
|
453
441
|
@in_memory_backlog.delete_at(0) unless try_again
|
454
442
|
end
|
455
443
|
end
|
456
444
|
ensure
|
457
|
-
@lock.synchronize
|
458
|
-
@flush_backlog_thread = nil
|
459
|
-
end
|
445
|
+
@lock.synchronize { @flush_backlog_thread = nil }
|
460
446
|
end
|
461
447
|
|
462
448
|
def cached_eval(redis, script, script_sha1, params)
|
@@ -479,10 +465,10 @@ LUA
|
|
479
465
|
# in case we are not connected to the correct server
|
480
466
|
# which can happen when sharing ips
|
481
467
|
pub_redis.disconnect!
|
482
|
-
pub_redis.set(key,
|
468
|
+
pub_redis.set(key, "1")
|
483
469
|
false
|
484
470
|
rescue ::Redis::CommandError => e
|
485
|
-
|
471
|
+
true if e.message =~ /^READONLY/
|
486
472
|
end
|
487
473
|
end
|
488
474
|
|
@@ -199,7 +199,9 @@ class MessageBus::Rack::Middleware
|
|
199
199
|
# ConnectionManagement in Rails puts a BodyProxy around stuff
|
200
200
|
# this means connections are not returned until rack.async is
|
201
201
|
# closed
|
202
|
-
if defined? ActiveRecord::Base.
|
202
|
+
if defined? ActiveRecord::Base.connection_handler
|
203
|
+
ActiveRecord::Base.connection_handler.clear_active_connections!
|
204
|
+
elsif defined? ActiveRecord::Base.clear_active_connections!
|
203
205
|
ActiveRecord::Base.clear_active_connections!
|
204
206
|
end
|
205
207
|
end
|
data/lib/message_bus/version.rb
CHANGED
data/package-lock.json
CHANGED
@@ -2003,9 +2003,9 @@
|
|
2003
2003
|
}
|
2004
2004
|
},
|
2005
2005
|
"node_modules/word-wrap": {
|
2006
|
-
"version": "1.2.
|
2007
|
-
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.
|
2008
|
-
"integrity": "sha512-
|
2006
|
+
"version": "1.2.4",
|
2007
|
+
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
|
2008
|
+
"integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
|
2009
2009
|
"dev": true,
|
2010
2010
|
"engines": {
|
2011
2011
|
"node": ">=0.10.0"
|
@@ -3553,9 +3553,9 @@
|
|
3553
3553
|
}
|
3554
3554
|
},
|
3555
3555
|
"word-wrap": {
|
3556
|
-
"version": "1.2.
|
3557
|
-
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.
|
3558
|
-
"integrity": "sha512-
|
3556
|
+
"version": "1.2.4",
|
3557
|
+
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
|
3558
|
+
"integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
|
3559
3559
|
"dev": true
|
3560
3560
|
},
|
3561
3561
|
"wrappy": {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|