message_bus 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/README.md +5 -0
- data/assets/message-bus.js +4 -1
- data/lib/message_bus.rb +9 -1
- data/lib/message_bus/backends/redis.rb +1 -1
- data/lib/message_bus/client.rb +0 -1
- data/lib/message_bus/distributed_cache.rb +7 -1
- data/lib/message_bus/message.rb +2 -2
- data/lib/message_bus/version.rb +1 -1
- data/spec/lib/message_bus_spec.rb +26 -4
- 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: 89229a2e20ef4e018c1e483fc24784fca853901f589fc25eabaca7cefa88d195
|
4
|
+
data.tar.gz: 36ec7e44a6223a60f4e51a937977ba74122e8ac36c8e5df9551beb5b0a3d679d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8847a0e7fd1f836000bda6ef017c498697489f84cf437732feab601b2a9c924aa981f4e96457360e36647568a00246e728459918a91afbda1e7b86e757f6520
|
7
|
+
data.tar.gz: 9217b0226498fca5fd7dc4159d72b5c86d0f588dff13cf1ddf8e3b8ce4d5f04fcb42f03cb4310233100603391f90ac6d1a8b1ee0a1cf4281ab2e1275799f7907
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
- Unrelease
|
2
|
+
|
3
|
+
15-09-2020
|
4
|
+
|
5
|
+
- Version 3.3.2
|
6
|
+
|
7
|
+
- FIX: In the JavaScript client throw when when lastId is given but is not a number.
|
8
|
+
- FEATURE: raise when attempting to publish to invalid targets
|
9
|
+
- Log when DistributedCache encounters an error when publishing.
|
10
|
+
|
1
11
|
09-06-2020
|
2
12
|
|
3
13
|
- Version 3.3.1
|
data/README.md
CHANGED
@@ -304,6 +304,11 @@ MessageBus.subscribe("/channel", function(data){
|
|
304
304
|
MessageBus.subscribe("/channel", function(data){
|
305
305
|
// data shipped from server
|
306
306
|
}, -3);
|
307
|
+
|
308
|
+
// you will get the entire backlog
|
309
|
+
MessageBus.subscribe("/channel", function(data){
|
310
|
+
// data shipped from server
|
311
|
+
}, 0);
|
307
312
|
```
|
308
313
|
|
309
314
|
#### JavaScript Client settings
|
data/assets/message-bus.js
CHANGED
@@ -484,13 +484,16 @@
|
|
484
484
|
// -1 will subscribe to all new messages
|
485
485
|
// -2 will recieve last message + all new messages
|
486
486
|
// -3 will recieve last 2 messages + all new messages
|
487
|
+
// if undefined will default to -1
|
487
488
|
subscribe: function(channel, func, lastId) {
|
488
489
|
if (!started && !stopped) {
|
489
490
|
me.start();
|
490
491
|
}
|
491
492
|
|
492
|
-
if (typeof lastId
|
493
|
+
if (lastId === null || typeof lastId === "undefined") {
|
493
494
|
lastId = -1;
|
495
|
+
} else if (typeof lastId !== "number") {
|
496
|
+
throw "lastId has type " + typeof lastId + " but a number was expected.";
|
494
497
|
}
|
495
498
|
|
496
499
|
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,
|
@@ -318,7 +318,7 @@ 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
323
|
global_redis&.disconnect!
|
324
324
|
retry
|
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
|
|
@@ -75,7 +75,13 @@ module MessageBus
|
|
75
75
|
message[:origin] = hash.identity
|
76
76
|
message[:hash_key] = hash.key
|
77
77
|
message[:app_version] = @app_version if @app_version
|
78
|
-
|
78
|
+
|
79
|
+
begin
|
80
|
+
@message_bus.publish(CHANNEL_NAME, message, user_ids: [-1])
|
81
|
+
rescue => e
|
82
|
+
@message_bus.logger.warn("DistributedCache failed to publish: #{e.message}\n#{e.backtrace.join("\n")}")
|
83
|
+
raise
|
84
|
+
end
|
79
85
|
end
|
80
86
|
|
81
87
|
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
|
data/lib/message_bus/version.rb
CHANGED
@@ -266,15 +266,37 @@ describe MessageBus do
|
|
266
266
|
end
|
267
267
|
|
268
268
|
it "should exception if publishing restricted messages to user" do
|
269
|
-
|
269
|
+
assert_raises(MessageBus::InvalidMessage) do
|
270
270
|
@bus.publish("/global/test", "test", user_ids: [1])
|
271
|
-
end
|
271
|
+
end
|
272
272
|
end
|
273
273
|
|
274
274
|
it "should exception if publishing restricted messages to group" do
|
275
|
-
|
275
|
+
assert_raises(MessageBus::InvalidMessage) do
|
276
276
|
@bus.publish("/global/test", "test", user_ids: [1])
|
277
|
-
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should raise if we publish to an empty group or user list" do
|
281
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
282
|
+
@bus.publish "/foo", "bar", user_ids: []
|
283
|
+
end
|
284
|
+
|
285
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
286
|
+
@bus.publish "/foo", "bar", group_ids: []
|
287
|
+
end
|
288
|
+
|
289
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
290
|
+
@bus.publish "/foo", "bar", client_ids: []
|
291
|
+
end
|
292
|
+
|
293
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
294
|
+
@bus.publish "/foo", "bar", group_ids: [], user_ids: [1]
|
295
|
+
end
|
296
|
+
|
297
|
+
assert_raises(MessageBus::InvalidMessageTarget) do
|
298
|
+
@bus.publish "/foo", "bar", group_ids: [1], user_ids: []
|
299
|
+
end
|
278
300
|
end
|
279
301
|
end
|
280
302
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|