message_bus 2.0.9 → 2.1.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.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/README.md +18 -0
- data/assets/message-bus.js +7 -1
- data/examples/chat/docker_container/chat.yml +1 -1
- data/lib/message_bus/client.rb +11 -3
- data/lib/message_bus/version.rb +1 -1
- data/spec/lib/message_bus/client_spec.rb +25 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6609e7158e64715d6113ffb1c2d61d99c919d16b
|
4
|
+
data.tar.gz: d561cb2c1342bc50cca592676f7f45c6eb50326e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f42d527e19b5a9e15edabb29198a860447fb2e57697b2d946aa1bac26e5d2c8eec860a8839ff6fede461e61a050c806ae9fbfba39ff6e2ae0a945238d3921e6
|
7
|
+
data.tar.gz: 271dc3f565aa0dde4f2e513f5fb9cddaf4e59680bbe5b87136708c042020de47c9469cdf56d8f9d5025ce1272138e9ac7b4adfde5713ed896b7a9002bf8cbc42
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -196,10 +196,28 @@ MessageBus.start(); // call once at startup
|
|
196
196
|
|
197
197
|
// how often do you want the callback to fire in ms
|
198
198
|
MessageBus.callbackInterval = 500;
|
199
|
+
|
200
|
+
// you will get all new messages sent to channel
|
199
201
|
MessageBus.subscribe("/channel", function(data){
|
200
202
|
// data shipped from server
|
201
203
|
});
|
202
204
|
|
205
|
+
|
206
|
+
// you will get all new messages sent to channel (-1 is implicit)
|
207
|
+
MessageBus.subscribe("/channel", function(data){
|
208
|
+
// data shipped from server
|
209
|
+
}, -1);
|
210
|
+
|
211
|
+
|
212
|
+
// all messages AFTER message id 7 AND all new messages
|
213
|
+
MessageBus.subscribe("/channel", function(data){
|
214
|
+
// data shipped from server
|
215
|
+
}, 7);
|
216
|
+
|
217
|
+
// last 2 messages in channel AND all new messages
|
218
|
+
MessageBus.subscribe("/channel", function(data){
|
219
|
+
// data shipped from server
|
220
|
+
}, -3);
|
203
221
|
```
|
204
222
|
|
205
223
|
There is also a Ruby implementation of the client library, at
|
data/assets/message-bus.js
CHANGED
@@ -365,15 +365,21 @@
|
|
365
365
|
},
|
366
366
|
|
367
367
|
// Subscribe to a channel
|
368
|
+
// if lastId is 0 or larger, it will recieve messages AFTER that id
|
369
|
+
// if lastId is nagative it will perform lookbehind"
|
370
|
+
// -1 will subscribe to all new messages
|
371
|
+
// -2 will recieve last message + all new messages
|
372
|
+
// -3 will recieve last 2 messages + all new messages
|
368
373
|
subscribe: function(channel, func, lastId) {
|
369
374
|
|
370
375
|
if(!started && !stopped){
|
371
376
|
me.start();
|
372
377
|
}
|
373
378
|
|
374
|
-
if (typeof(lastId) !== "number"
|
379
|
+
if (typeof(lastId) !== "number") {
|
375
380
|
lastId = -1;
|
376
381
|
}
|
382
|
+
|
377
383
|
callbacks.push({
|
378
384
|
channel: channel,
|
379
385
|
func: func,
|
data/lib/message_bus/client.rb
CHANGED
@@ -121,11 +121,19 @@ class MessageBus::Client
|
|
121
121
|
new_message_ids = nil
|
122
122
|
|
123
123
|
@subscriptions.each do |k, v|
|
124
|
-
|
125
|
-
|
124
|
+
id = v.to_i
|
125
|
+
|
126
|
+
if id < -1
|
127
|
+
last_id = @bus.last_id(k, site_id)
|
128
|
+
id = last_id + id + 1
|
129
|
+
id = 0 if id < 0
|
130
|
+
end
|
131
|
+
|
132
|
+
next if id < 0
|
133
|
+
messages = @bus.backlog(k, id, site_id)
|
126
134
|
|
127
135
|
if messages.length == 0
|
128
|
-
if
|
136
|
+
if id > @bus.last_id(k, site_id)
|
129
137
|
@subscriptions[k] = -1
|
130
138
|
end
|
131
139
|
else
|
data/lib/message_bus/version.rb
CHANGED
@@ -29,7 +29,7 @@ describe MessageBus::Client do
|
|
29
29
|
|
30
30
|
while line = lines.shift
|
31
31
|
break if line == ""
|
32
|
-
name,val = line.split(": ")
|
32
|
+
name, val = line.split(": ")
|
33
33
|
headers[name] = val
|
34
34
|
end
|
35
35
|
|
@@ -39,7 +39,7 @@ describe MessageBus::Client do
|
|
39
39
|
break if length == 0
|
40
40
|
rest = lines.join("\r\n")
|
41
41
|
chunks << rest[0...length]
|
42
|
-
lines = (rest[length+2..-1] || "").split("\r\n")
|
42
|
+
lines = (rest[length + 2..-1] || "").split("\r\n")
|
43
43
|
end
|
44
44
|
|
45
45
|
# split/join gets tricky
|
@@ -49,15 +49,15 @@ describe MessageBus::Client do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def parse_chunk(data)
|
52
|
-
payload,_ = data.split(/\r\n\|\r\n/m)
|
52
|
+
payload, _ = data.split(/\r\n\|\r\n/m)
|
53
53
|
JSON.parse(payload)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "can chunk replies" do
|
57
57
|
@client.use_chunked = true
|
58
|
-
r,w = IO.pipe
|
58
|
+
r, w = IO.pipe
|
59
59
|
@client.io = w
|
60
|
-
@client.headers = {"Content-Type" => "application/json; charset=utf-8"}
|
60
|
+
@client.headers = { "Content-Type" => "application/json; charset=utf-8" }
|
61
61
|
@client << MessageBus::Message.new(1, 1, '/test', 'test')
|
62
62
|
@client << MessageBus::Message.new(2, 2, '/test', "a|\r\n|\r\n|b")
|
63
63
|
|
@@ -84,7 +84,7 @@ describe MessageBus::Client do
|
|
84
84
|
|
85
85
|
data[-5..-1].must_equal "0\r\n\r\n"
|
86
86
|
|
87
|
-
_,_,chunks = http_parse("HTTP/1.1 200 OK\r\n\r\n" << data)
|
87
|
+
_, _, chunks = http_parse("HTTP/1.1 200 OK\r\n\r\n" << data)
|
88
88
|
|
89
89
|
chunks.length.must_equal 2
|
90
90
|
|
@@ -116,6 +116,18 @@ describe MessageBus::Client do
|
|
116
116
|
log[0].data.must_equal("/hello" => 0)
|
117
117
|
end
|
118
118
|
|
119
|
+
it "allows negative subscribes to look behind" do
|
120
|
+
|
121
|
+
@bus.publish '/hello', 'world'
|
122
|
+
@bus.publish '/hello', 'sam'
|
123
|
+
|
124
|
+
@client.subscribe('/hello', -2)
|
125
|
+
|
126
|
+
log = @client.backlog
|
127
|
+
log.length.must_equal(1)
|
128
|
+
log[0].data.must_equal("sam")
|
129
|
+
end
|
130
|
+
|
119
131
|
it "provides status" do
|
120
132
|
@client.subscribe('/hello', -1)
|
121
133
|
log = @client.backlog
|
@@ -139,7 +151,7 @@ describe MessageBus::Client do
|
|
139
151
|
log = another_client.backlog
|
140
152
|
log.length.must_equal 1
|
141
153
|
log[0].channel.must_equal '/__status'
|
142
|
-
log[0].data.must_equal(
|
154
|
+
log[0].data.must_equal('/hello' => 1)
|
143
155
|
end
|
144
156
|
|
145
157
|
it "should provide a list of subscriptions" do
|
@@ -158,7 +170,7 @@ describe MessageBus::Client do
|
|
158
170
|
|
159
171
|
it "allows only client_id in list if message contains client_ids" do
|
160
172
|
@message = MessageBus::Message.new(1, 2, '/test', 'hello')
|
161
|
-
@message.client_ids = ["1","2"]
|
173
|
+
@message.client_ids = ["1", "2"]
|
162
174
|
@client.client_id = "2"
|
163
175
|
@client.allowed?(@message).must_equal true
|
164
176
|
|
@@ -168,23 +180,23 @@ describe MessageBus::Client do
|
|
168
180
|
|
169
181
|
describe "targetted at group" do
|
170
182
|
before do
|
171
|
-
@message = MessageBus::Message.new(1,2,'/test', 'hello')
|
172
|
-
@message.group_ids = [1,2,3]
|
183
|
+
@message = MessageBus::Message.new(1, 2, '/test', 'hello')
|
184
|
+
@message.group_ids = [1, 2, 3]
|
173
185
|
end
|
174
186
|
|
175
187
|
it "denies users that are not members of group" do
|
176
|
-
@client.group_ids = [77,0,10]
|
188
|
+
@client.group_ids = [77, 0, 10]
|
177
189
|
@client.allowed?(@message).must_equal false
|
178
190
|
end
|
179
191
|
|
180
192
|
it "allows users that are members of group" do
|
181
|
-
@client.group_ids = [1,2,3]
|
193
|
+
@client.group_ids = [1, 2, 3]
|
182
194
|
@client.allowed?(@message).must_equal true
|
183
195
|
end
|
184
196
|
|
185
197
|
it "allows all users if groups not set" do
|
186
198
|
@message.group_ids = nil
|
187
|
-
@client.group_ids = [77,0,10]
|
199
|
+
@client.group_ids = [77, 0, 10]
|
188
200
|
@client.allowed?(@message).must_equal true
|
189
201
|
end
|
190
202
|
|
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: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|