message_bus 3.3.0 → 3.3.5
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.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +54 -0
- data/.rubocop.yml +3 -1
- data/CHANGELOG +49 -1
- data/DEV.md +9 -0
- data/README.md +5 -6
- data/Rakefile +4 -0
- data/assets/message-bus-ajax.js +1 -7
- data/assets/message-bus.js +5 -24
- data/lib/message_bus.rb +19 -7
- data/lib/message_bus/backends/redis.rb +12 -9
- data/lib/message_bus/client.rb +0 -1
- data/lib/message_bus/distributed_cache.rb +7 -2
- data/lib/message_bus/message.rb +2 -2
- data/lib/message_bus/rack/middleware.rb +16 -16
- data/lib/message_bus/timer_thread.rb +8 -1
- data/lib/message_bus/version.rb +1 -1
- data/message_bus.gemspec +1 -1
- data/package.json +1 -1
- data/spec/lib/message_bus_spec.rb +33 -4
- metadata +9 -8
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f34126c192c671b895e7cf912a04ffcb5d05a5a5447786c3f5e3db3595c79004
|
4
|
+
data.tar.gz: 5a638bf3eb07680d17d93b762bc41d92d8b4c4412d9f3fae3e7410ec2ae67488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7102c7e62cc9854237fab235e2020f318bbdc956ba64f6d0c77c515430df1169bb06e01a9125f71631546daa3dfa1179c971ca207f32a9cda96880b0d9be6c6
|
7
|
+
data.tar.gz: 91b8e655e1dc27b4f386477d38dea8ef4f44daa658793a2205392135cb2f846a80ac0aca52fc04c9a471990b64cb18c6ea9dbd36818690c28cac0c80f922d8be
|
@@ -0,0 +1,54 @@
|
|
1
|
+
name: Message Bus Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
env:
|
10
|
+
PGHOST: localhost
|
11
|
+
PGPORT: 5432
|
12
|
+
PGPASSWORD: postgres
|
13
|
+
PGUSER: postgres
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
build:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
services:
|
20
|
+
postgres:
|
21
|
+
image: postgres:9.4
|
22
|
+
env:
|
23
|
+
POSTGRES_PASSWORD: postgres
|
24
|
+
ports:
|
25
|
+
- 5432:5432
|
26
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
27
|
+
strategy:
|
28
|
+
matrix:
|
29
|
+
ruby: ["2.7", "2.6", "2.5"]
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- uses: actions/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby }}
|
35
|
+
- name: Bundler cache
|
36
|
+
uses: actions/cache@v2
|
37
|
+
with:
|
38
|
+
path: vendor/bundle
|
39
|
+
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
40
|
+
restore-keys: |
|
41
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-
|
42
|
+
- name: Create Database
|
43
|
+
run: |
|
44
|
+
createdb message_bus_test
|
45
|
+
- name: Setup redis
|
46
|
+
uses: shogo82148/actions-setup-redis@v1
|
47
|
+
with:
|
48
|
+
redis-version: '5.x'
|
49
|
+
- name: Setup gems
|
50
|
+
run: |
|
51
|
+
bundle config path vendor/bundle
|
52
|
+
bundle install --jobs 4
|
53
|
+
- name: Tests
|
54
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,4 +1,52 @@
|
|
1
|
-
-
|
1
|
+
28-04-2021
|
2
|
+
|
3
|
+
- Version 3.3.5
|
4
|
+
|
5
|
+
- PERF: Optimised CORS preflight handling
|
6
|
+
- FEATURE: Enable CORS preflight caching
|
7
|
+
- FEATURE: Removed trailing cache buster from message bus polls
|
8
|
+
- PERF: Improved delay poll timeout for cases where a tab moves in and out of the background
|
9
|
+
|
10
|
+
02-10-2020
|
11
|
+
|
12
|
+
- Version 3.3.4
|
13
|
+
|
14
|
+
- FIX: Remove trailing comma incorrectly added in ec60d8865.
|
15
|
+
|
16
|
+
18-09-2020
|
17
|
+
|
18
|
+
- Version 3.3.3
|
19
|
+
|
20
|
+
- FIX: `queue_in_memory` option not being passed to the backends.
|
21
|
+
- FIX: `MessageBus::DistributedCache#publish` should raise on error.
|
22
|
+
|
23
|
+
On the redis backend, any errors encountered during `MessageBus#publish`
|
24
|
+
will add the message into an in memory queue and silently swallow the
|
25
|
+
error. While this is behavior is OK for normal message_bus usage, it may
|
26
|
+
lead to inconsistency when using `DistributedCache`. If a process
|
27
|
+
doesn't publish successfully to another process, it will still update
|
28
|
+
its in memory cache leaving the other processes unaware. As such, the
|
29
|
+
distributed cache is out of sync and will require another successful
|
30
|
+
write to the cache to resync all the caches.
|
31
|
+
|
32
|
+
15-09-2020
|
33
|
+
|
34
|
+
- Version 3.3.2
|
35
|
+
|
36
|
+
- FIX: In the JavaScript client throw when when lastId is given but is not a number.
|
37
|
+
- FEATURE: raise when attempting to publish to invalid targets
|
38
|
+
- Log when DistributedCache encounters an error when publishing.
|
39
|
+
|
40
|
+
09-06-2020
|
41
|
+
|
42
|
+
- Version 3.3.1
|
43
|
+
|
44
|
+
- FIX: Disconnect Redis conn when rescuing errors in global subscribe.
|
45
|
+
- FIX: `MessageBus::Backends::Redis#global_subscribe` not closing Redis connections.
|
46
|
+
|
47
|
+
15-05-2020
|
48
|
+
|
49
|
+
- Version 3.3.0
|
2
50
|
|
3
51
|
- FEATURE: `MessageBus.base_route=` to alter the route that message bus will listen on.
|
4
52
|
|
data/DEV.md
ADDED
data/README.md
CHANGED
@@ -10,12 +10,6 @@ MessageBus is implemented as Rack middleware and can be used by any Rails / Sina
|
|
10
10
|
|
11
11
|
Read the generated docs: <https://www.rubydoc.info/gems/message_bus>
|
12
12
|
|
13
|
-
## Try it out!
|
14
|
-
|
15
|
-
Live chat demo per [examples/chat](https://github.com/SamSaffron/message_bus/tree/master/examples/chat) is at:
|
16
|
-
|
17
|
-
### http://chat.samsaffron.com
|
18
|
-
|
19
13
|
## Ruby version support
|
20
14
|
|
21
15
|
MessageBus only support officially supported versions of Ruby; as of [2018-06-20](https://www.ruby-lang.org/en/news/2018/06/20/support-of-ruby-2-2-has-ended/) this means we only support Ruby version 2.3 and up.
|
@@ -304,6 +298,11 @@ MessageBus.subscribe("/channel", function(data){
|
|
304
298
|
MessageBus.subscribe("/channel", function(data){
|
305
299
|
// data shipped from server
|
306
300
|
}, -3);
|
301
|
+
|
302
|
+
// you will get the entire backlog
|
303
|
+
MessageBus.subscribe("/channel", function(data){
|
304
|
+
// data shipped from server
|
305
|
+
}, 0);
|
307
306
|
```
|
308
307
|
|
309
308
|
#### JavaScript Client settings
|
data/Rakefile
CHANGED
data/assets/message-bus-ajax.js
CHANGED
@@ -8,17 +8,11 @@
|
|
8
8
|
throw new Error("MessageBus must be loaded before the ajax adapter");
|
9
9
|
}
|
10
10
|
|
11
|
-
var cacheBuster = Math.random() * 10000 | 0;
|
12
|
-
|
13
11
|
global.MessageBus.ajax = function(options){
|
14
12
|
var XHRImpl = (global.MessageBus && global.MessageBus.xhrImplementation) || global.XMLHttpRequest;
|
15
13
|
var xhr = new XHRImpl();
|
16
14
|
xhr.dataType = options.dataType;
|
17
|
-
|
18
|
-
if (!options.cache){
|
19
|
-
url += ((-1 == url.indexOf('?')) ? '?' : '&') + '_=' + (cacheBuster++)
|
20
|
-
}
|
21
|
-
xhr.open('POST', url);
|
15
|
+
xhr.open('POST', options.url);
|
22
16
|
for (var name in options.headers){
|
23
17
|
xhr.setRequestHeader(name, options.headers[name]);
|
24
18
|
}
|
data/assets/message-bus.js
CHANGED
@@ -31,8 +31,6 @@
|
|
31
31
|
var started = false;
|
32
32
|
var clientId = uniqueId();
|
33
33
|
var callbacks = [];
|
34
|
-
var queue = [];
|
35
|
-
var interval = null;
|
36
34
|
var failCount = 0;
|
37
35
|
var baseUrl = "/";
|
38
36
|
var paused = false;
|
@@ -103,7 +101,6 @@
|
|
103
101
|
};
|
104
102
|
|
105
103
|
var processMessages = function(messages) {
|
106
|
-
var gotData = false;
|
107
104
|
if ((!messages) || (messages.length === 0)) { return false; }
|
108
105
|
|
109
106
|
for (var i = 0; i < messages.length; i++) {
|
@@ -213,24 +210,6 @@
|
|
213
210
|
}
|
214
211
|
};
|
215
212
|
|
216
|
-
var setOnProgressListener = function(xhr) {
|
217
|
-
var position = 0;
|
218
|
-
// if it takes longer than 3000 ms to get first chunk, we have some proxy
|
219
|
-
// this is messing with us, so just backoff from using chunked for now
|
220
|
-
var chunkedTimeout = setTimeout(disableChunked, 3000);
|
221
|
-
xhr.onprogress = function() {
|
222
|
-
clearTimeout(chunkedTimeout);
|
223
|
-
if (
|
224
|
-
xhr.getResponseHeader("Content-Type") ===
|
225
|
-
"application/json; charset=utf-8"
|
226
|
-
) {
|
227
|
-
// not chunked we are sending json back
|
228
|
-
chunked = false;
|
229
|
-
return;
|
230
|
-
}
|
231
|
-
position = handle_progress(xhr.responseText, position);
|
232
|
-
};
|
233
|
-
};
|
234
213
|
if (!me.ajax) {
|
235
214
|
throw new Error("Either jQuery or the ajax adapter must be loaded");
|
236
215
|
}
|
@@ -246,7 +225,6 @@
|
|
246
225
|
"/poll" +
|
247
226
|
(!longPoll ? "?dlp=t" : ""),
|
248
227
|
data: data,
|
249
|
-
cache: false,
|
250
228
|
async: true,
|
251
229
|
dataType: dataType,
|
252
230
|
type: "POST",
|
@@ -451,7 +429,7 @@
|
|
451
429
|
me.visibilityEvent = document.addEventListener(
|
452
430
|
"visibilitychange",
|
453
431
|
function() {
|
454
|
-
if (!document.hidden && !me.longPoll && pollTimeout) {
|
432
|
+
if (!document.hidden && !me.longPoll && (pollTimeout || delayPollTimeout)) {
|
455
433
|
clearTimeout(pollTimeout);
|
456
434
|
clearTimeout(delayPollTimeout);
|
457
435
|
|
@@ -484,13 +462,16 @@
|
|
484
462
|
// -1 will subscribe to all new messages
|
485
463
|
// -2 will recieve last message + all new messages
|
486
464
|
// -3 will recieve last 2 messages + all new messages
|
465
|
+
// if undefined will default to -1
|
487
466
|
subscribe: function(channel, func, lastId) {
|
488
467
|
if (!started && !stopped) {
|
489
468
|
me.start();
|
490
469
|
}
|
491
470
|
|
492
|
-
if (typeof lastId
|
471
|
+
if (lastId === null || typeof lastId === "undefined") {
|
493
472
|
lastId = -1;
|
473
|
+
} else if (typeof lastId !== "number") {
|
474
|
+
throw "lastId has type " + typeof lastId + " but a number was expected.";
|
494
475
|
}
|
495
476
|
|
496
477
|
if (typeof channel !== "string") {
|
data/lib/message_bus.rb
CHANGED
@@ -20,6 +20,7 @@ end
|
|
20
20
|
module MessageBus; end
|
21
21
|
MessageBus::BACKENDS = {}
|
22
22
|
class MessageBus::InvalidMessage < StandardError; end
|
23
|
+
class MessageBus::InvalidMessageTarget < MessageBus::InvalidMessage; end
|
23
24
|
class MessageBus::BusDestroyed < StandardError; end
|
24
25
|
|
25
26
|
# The main server-side interface to a message bus for the purposes of
|
@@ -329,6 +330,7 @@ module MessageBus::Implementation
|
|
329
330
|
#
|
330
331
|
# @raise [MessageBus::BusDestroyed] if the bus is destroyed
|
331
332
|
# @raise [MessageBus::InvalidMessage] if attempting to put permission restrictions on a globally-published message
|
333
|
+
# @raise [MessageBus::InvalidMessageTarget] if attempting to publish to a empty group of users
|
332
334
|
def publish(channel, data, opts = nil)
|
333
335
|
return if @off
|
334
336
|
|
@@ -348,7 +350,13 @@ module MessageBus::Implementation
|
|
348
350
|
site_id = opts[:site_id]
|
349
351
|
end
|
350
352
|
|
351
|
-
|
353
|
+
if (user_ids || group_ids) && global?(channel)
|
354
|
+
raise ::MessageBus::InvalidMessage
|
355
|
+
end
|
356
|
+
|
357
|
+
if (user_ids == []) || (group_ids == []) || (client_ids == [])
|
358
|
+
raise ::MessageBus::InvalidMessageTarget
|
359
|
+
end
|
352
360
|
|
353
361
|
encoded_data = JSON.dump(
|
354
362
|
data: data,
|
@@ -357,13 +365,17 @@ module MessageBus::Implementation
|
|
357
365
|
client_ids: client_ids
|
358
366
|
)
|
359
367
|
|
360
|
-
channel_opts =
|
368
|
+
channel_opts = {}
|
361
369
|
|
362
|
-
if opts
|
363
|
-
|
364
|
-
max_backlog_size
|
365
|
-
max_backlog_age
|
366
|
-
|
370
|
+
if opts
|
371
|
+
if ((age = opts[:max_backlog_age]) || (size = opts[:max_backlog_size]))
|
372
|
+
channel_opts[:max_backlog_size] = size
|
373
|
+
channel_opts[:max_backlog_age] = age
|
374
|
+
end
|
375
|
+
|
376
|
+
if opts.has_key?(:queue_in_memory)
|
377
|
+
channel_opts[:queue_in_memory] = opts[:queue_in_memory]
|
378
|
+
end
|
367
379
|
end
|
368
380
|
|
369
381
|
encoded_channel_name = encode_channel_name(channel, site_id)
|
@@ -251,11 +251,11 @@ LUA
|
|
251
251
|
|
252
252
|
# (see Base#global_unsubscribe)
|
253
253
|
def global_unsubscribe
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
254
|
+
begin
|
255
|
+
new_redis = new_redis_connection
|
256
|
+
new_redis.publish(redis_channel_name, UNSUB_MESSAGE)
|
257
|
+
ensure
|
258
|
+
new_redis&.disconnect!
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
@@ -278,13 +278,13 @@ LUA
|
|
278
278
|
end
|
279
279
|
|
280
280
|
begin
|
281
|
-
|
281
|
+
global_redis = new_redis_connection
|
282
282
|
|
283
283
|
if highest_id
|
284
284
|
clear_backlog.call(&blk)
|
285
285
|
end
|
286
286
|
|
287
|
-
|
287
|
+
global_redis.subscribe(redis_channel_name) do |on|
|
288
288
|
on.subscribe do
|
289
289
|
if highest_id
|
290
290
|
clear_backlog.call(&blk)
|
@@ -298,7 +298,7 @@ LUA
|
|
298
298
|
|
299
299
|
on.message do |_c, m|
|
300
300
|
if m == UNSUB_MESSAGE
|
301
|
-
|
301
|
+
global_redis.unsubscribe
|
302
302
|
return
|
303
303
|
end
|
304
304
|
m = MessageBus::Message.decode m
|
@@ -318,9 +318,12 @@ LUA
|
|
318
318
|
end
|
319
319
|
end
|
320
320
|
rescue => error
|
321
|
-
@logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack #{error.backtrace}"
|
321
|
+
@logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack #{error.backtrace.join("\n")}"
|
322
322
|
sleep 1
|
323
|
+
global_redis&.disconnect!
|
323
324
|
retry
|
325
|
+
ensure
|
326
|
+
global_redis&.disconnect!
|
324
327
|
end
|
325
328
|
end
|
326
329
|
|
data/lib/message_bus/client.rb
CHANGED
@@ -133,7 +133,6 @@ class MessageBus::Client
|
|
133
133
|
user_allowed = false
|
134
134
|
group_allowed = false
|
135
135
|
|
136
|
-
# this is an inconsistency we should fix anyway, publishing `user_ids: nil` should work same as groups
|
137
136
|
has_users = msg.user_ids && msg.user_ids.length > 0
|
138
137
|
has_groups = msg.group_ids && msg.group_ids.length > 0
|
139
138
|
|
@@ -16,11 +16,12 @@ module MessageBus
|
|
16
16
|
|
17
17
|
attr_accessor :app_version
|
18
18
|
|
19
|
-
def initialize(message_bus = nil)
|
19
|
+
def initialize(message_bus = nil, publish_queue_in_memory: true)
|
20
20
|
@subscribers = []
|
21
21
|
@subscribed = false
|
22
22
|
@lock = Mutex.new
|
23
23
|
@message_bus = message_bus || MessageBus
|
24
|
+
@publish_queue_in_memory = publish_queue_in_memory
|
24
25
|
end
|
25
26
|
|
26
27
|
def subscribers
|
@@ -75,7 +76,11 @@ module MessageBus
|
|
75
76
|
message[:origin] = hash.identity
|
76
77
|
message[:hash_key] = hash.key
|
77
78
|
message[:app_version] = @app_version if @app_version
|
78
|
-
|
79
|
+
|
80
|
+
@message_bus.publish(CHANNEL_NAME, message,
|
81
|
+
user_ids: [-1],
|
82
|
+
queue_in_memory: @publish_queue_in_memory
|
83
|
+
)
|
79
84
|
end
|
80
85
|
|
81
86
|
def set(hash, key, value)
|
data/lib/message_bus/message.rb
CHANGED
@@ -20,10 +20,10 @@ class MessageBus::Message < Struct.new(:global_id, :message_id, :channel, :data)
|
|
20
20
|
|
21
21
|
# only tricky thing to encode is pipes in a channel name ... do a straight replace
|
22
22
|
def encode
|
23
|
-
global_id
|
23
|
+
"#{global_id}|#{message_id}|#{channel.gsub("|", "$$123$$")}|#{data}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def encode_without_ids
|
27
|
-
channel.gsub("|", "$$123$$")
|
27
|
+
"#{channel.gsub("|", "$$123$$")}|#{data}"
|
28
28
|
end
|
29
29
|
end
|
@@ -81,6 +81,22 @@ class MessageBus::Rack::Middleware
|
|
81
81
|
client_id = env['PATH_INFO'][@base_route_length..-1].split("/")[0]
|
82
82
|
return [404, {}, ["not found"]] unless client_id
|
83
83
|
|
84
|
+
headers = {}
|
85
|
+
headers["Cache-Control"] = "must-revalidate, private, max-age=0"
|
86
|
+
headers["Content-Type"] = "application/json; charset=utf-8"
|
87
|
+
headers["Pragma"] = "no-cache"
|
88
|
+
headers["Expires"] = "0"
|
89
|
+
|
90
|
+
if @bus.extra_response_headers_lookup
|
91
|
+
@bus.extra_response_headers_lookup.call(env).each do |k, v|
|
92
|
+
headers[k] = v
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if env["REQUEST_METHOD"] == "OPTIONS"
|
97
|
+
return [200, headers, ["OK"]]
|
98
|
+
end
|
99
|
+
|
84
100
|
user_id = @bus.user_id_lookup.call(env) if @bus.user_id_lookup
|
85
101
|
group_ids = @bus.group_ids_lookup.call(env) if @bus.group_ids_lookup
|
86
102
|
site_id = @bus.site_id_lookup.call(env) if @bus.site_id_lookup
|
@@ -111,22 +127,6 @@ class MessageBus::Rack::Middleware
|
|
111
127
|
end
|
112
128
|
end
|
113
129
|
|
114
|
-
headers = {}
|
115
|
-
headers["Cache-Control"] = "must-revalidate, private, max-age=0"
|
116
|
-
headers["Content-Type"] = "application/json; charset=utf-8"
|
117
|
-
headers["Pragma"] = "no-cache"
|
118
|
-
headers["Expires"] = "0"
|
119
|
-
|
120
|
-
if @bus.extra_response_headers_lookup
|
121
|
-
@bus.extra_response_headers_lookup.call(env).each do |k, v|
|
122
|
-
headers[k] = v
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
if env["REQUEST_METHOD"] == "OPTIONS"
|
127
|
-
return [200, headers, ["OK"]]
|
128
|
-
end
|
129
|
-
|
130
130
|
long_polling = @bus.long_polling_enabled? &&
|
131
131
|
env['QUERY_STRING'] !~ /dlp=t/ &&
|
132
132
|
@connection_manager.client_count < @bus.max_active_clients
|
@@ -45,7 +45,14 @@ class MessageBus::TimerThread
|
|
45
45
|
while running
|
46
46
|
@mutex.synchronize do
|
47
47
|
running = @thread && @thread.alive?
|
48
|
-
|
48
|
+
|
49
|
+
if running
|
50
|
+
begin
|
51
|
+
@thread.wakeup
|
52
|
+
rescue ThreadError
|
53
|
+
raise if @thread.alive?
|
54
|
+
end
|
55
|
+
end
|
49
56
|
end
|
50
57
|
sleep 0
|
51
58
|
end
|
data/lib/message_bus/version.rb
CHANGED
data/message_bus.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.name = "message_bus"
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
gem.version = MessageBus::VERSION
|
20
|
-
gem.required_ruby_version = ">= 2.
|
20
|
+
gem.required_ruby_version = ">= 2.4.0"
|
21
21
|
gem.add_runtime_dependency 'rack', '>= 1.1.3'
|
22
22
|
gem.add_development_dependency 'redis'
|
23
23
|
gem.add_development_dependency 'pg'
|
data/package.json
CHANGED
@@ -201,6 +201,13 @@ describe MessageBus do
|
|
201
201
|
@bus.backlog("/chuck").map { |i| i.data }.to_a.must_equal ['norris', 'foo']
|
202
202
|
end
|
203
203
|
|
204
|
+
it "should correctly restrict the backlog size of a channel" do
|
205
|
+
@bus.publish("/chuck", "norris")
|
206
|
+
@bus.publish("/chuck", "foo", max_backlog_size: 1)
|
207
|
+
|
208
|
+
@bus.backlog("/chuck").map { |i| i.data }.to_a.must_equal ['foo']
|
209
|
+
end
|
210
|
+
|
204
211
|
it "allows you to look up last_message" do
|
205
212
|
@bus.publish("/bob", "dylan")
|
206
213
|
@bus.publish("/bob", "marley")
|
@@ -266,15 +273,37 @@ describe MessageBus do
|
|
266
273
|
end
|
267
274
|
|
268
275
|
it "should exception if publishing restricted messages to user" do
|
269
|
-
|
276
|
+
assert_raises(MessageBus::InvalidMessage) do
|
270
277
|
@bus.publish("/global/test", "test", user_ids: [1])
|
271
|
-
end
|
278
|
+
end
|
272
279
|
end
|
273
280
|
|
274
281
|
it "should exception if publishing restricted messages to group" do
|
275
|
-
|
282
|
+
assert_raises(MessageBus::InvalidMessage) do
|
276
283
|
@bus.publish("/global/test", "test", user_ids: [1])
|
277
|
-
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should raise if we publish to an empty group or user list" do
|
288
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
289
|
+
@bus.publish "/foo", "bar", user_ids: []
|
290
|
+
end
|
291
|
+
|
292
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
293
|
+
@bus.publish "/foo", "bar", group_ids: []
|
294
|
+
end
|
295
|
+
|
296
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
297
|
+
@bus.publish "/foo", "bar", client_ids: []
|
298
|
+
end
|
299
|
+
|
300
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
301
|
+
@bus.publish "/foo", "bar", group_ids: [], user_ids: [1]
|
302
|
+
end
|
303
|
+
|
304
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
305
|
+
@bus.publish "/foo", "bar", group_ids: [1], user_ids: []
|
306
|
+
end
|
278
307
|
end
|
279
308
|
end
|
280
309
|
|
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: 3.3.
|
4
|
+
version: 3.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -59,10 +59,11 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/ci.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rubocop.yml"
|
64
|
-
- ".travis.yml"
|
65
65
|
- CHANGELOG
|
66
|
+
- DEV.md
|
66
67
|
- Dockerfile
|
67
68
|
- Gemfile
|
68
69
|
- Guardfile
|
@@ -141,7 +142,7 @@ homepage: https://github.com/SamSaffron/message_bus
|
|
141
142
|
licenses:
|
142
143
|
- MIT
|
143
144
|
metadata: {}
|
144
|
-
post_install_message:
|
145
|
+
post_install_message:
|
145
146
|
rdoc_options: []
|
146
147
|
require_paths:
|
147
148
|
- lib
|
@@ -149,15 +150,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
150
|
requirements:
|
150
151
|
- - ">="
|
151
152
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
153
|
+
version: 2.4.0
|
153
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
155
|
requirements:
|
155
156
|
- - ">="
|
156
157
|
- !ruby/object:Gem::Version
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
160
|
-
signing_key:
|
160
|
+
rubygems_version: 3.2.2
|
161
|
+
signing_key:
|
161
162
|
specification_version: 4
|
162
163
|
summary: ''
|
163
164
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
before_install: gem install bundler
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.4
|
5
|
-
- 2.5
|
6
|
-
- 2.6
|
7
|
-
gemfile:
|
8
|
-
- Gemfile
|
9
|
-
addons:
|
10
|
-
postgresql: "9.4"
|
11
|
-
env:
|
12
|
-
- PGUSER=postgres
|
13
|
-
before_script:
|
14
|
-
- psql -c 'create database message_bus_test;' -U postgres
|
15
|
-
services:
|
16
|
-
- redis-server
|
17
|
-
- postgresql
|