message_bus 2.0.1 → 2.0.2
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 +11 -0
- data/README.md +10 -2
- data/assets/message-bus.js +13 -1
- data/lib/message_bus.rb +5 -0
- data/lib/message_bus/rack/middleware.rb +7 -0
- data/lib/message_bus/version.rb +1 -1
- data/spec/assets/message-bus.spec.js +10 -0
- data/spec/lib/message_bus/rack/middleware_spec.rb +22 -0
- data/vendor/assets/javascripts/message-bus.js +13 -1
- 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: 80297cfac62f4fc79e8d16a425762576757aab5d
|
4
|
+
data.tar.gz: be8b74aed2b678c858de6a2941f74bcbaad455c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32fafd6d57c0176cc356724246909d430753428b375449b8c12a181dd8b2f50ab51404a6fd0c02a089cc7fbe2bf90e6071df6b5a24324fa0b0430e3c6f163460
|
7
|
+
data.tar.gz: e977e8bc61bdd4c74be64fe755ad413e036ae96fc149ccb26cbae05fb1bca53dcb45cf82b0ea6ae5e77e13ee3e3fc7a87a5068d6cbe98e5994f440c9668e43ca
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,12 @@ MessageBus.configure(group_ids_lookup: proc do |env|
|
|
83
83
|
# can be nil or []
|
84
84
|
end)
|
85
85
|
|
86
|
+
MessageBus.configure(on_middleware_error: proc do |env, e|
|
87
|
+
# If you wish to add special handling based on error
|
88
|
+
# return a rack result array: [status, headers, body]
|
89
|
+
# If you just want to pass it on return nil
|
90
|
+
end)
|
91
|
+
|
86
92
|
# example of message bus to set user_ids from an initializer in Rails and Devise:
|
87
93
|
# config/inializers/message_bus.rb
|
88
94
|
MessageBus.user_id_lookup do |env|
|
@@ -212,7 +218,9 @@ headers|{}|Extra headers to be include with request. Properties and values of o
|
|
212
218
|
|
213
219
|
`MessageBus.start()` : Must be called to startup the MessageBus poller
|
214
220
|
|
215
|
-
`MessageBus.
|
221
|
+
`MessageBus.status()` : Return status (started, paused, stopped)
|
222
|
+
|
223
|
+
`MessageBus.subscribe(channel,func,lastId)` : Subscribe to a channel, optionally you may specify the id of the last message you received in the channel. The callback accepts three arguments: `func(payload, globalId, messageId)`. You may save globalId or messageId of received messages and use then at a later time when client needs to subscribe, receiving the backlog just after that Id.
|
216
224
|
|
217
225
|
`MessageBus.unsubscribe(channel,func)` : Unsubscribe callback from a particular channel
|
218
226
|
|
@@ -299,7 +307,7 @@ For more information see [Passenger documentation](https://www.phusionpassenger.
|
|
299
307
|
#### Puma
|
300
308
|
```ruby
|
301
309
|
# path/to/your/config/puma.rb
|
302
|
-
require 'message_bus'
|
310
|
+
require 'message_bus' # omit this line for Rails 5
|
303
311
|
on_worker_boot do
|
304
312
|
MessageBus.after_fork
|
305
313
|
end
|
data/assets/message-bus.js
CHANGED
@@ -73,7 +73,7 @@
|
|
73
73
|
if (callback.channel === message.channel) {
|
74
74
|
callback.last_id = message.message_id;
|
75
75
|
try {
|
76
|
-
callback.func(message.data);
|
76
|
+
callback.func(message.data, message.global_id, message.message_id);
|
77
77
|
}
|
78
78
|
catch(e){
|
79
79
|
if(console.log) {
|
@@ -352,6 +352,18 @@
|
|
352
352
|
poll();
|
353
353
|
},
|
354
354
|
|
355
|
+
"status": function() {
|
356
|
+
if (paused) {
|
357
|
+
return "paused";
|
358
|
+
} else if (started) {
|
359
|
+
return "started";
|
360
|
+
} else if (stopped) {
|
361
|
+
return "stopped";
|
362
|
+
} else {
|
363
|
+
throw "Cannot determine current status";
|
364
|
+
}
|
365
|
+
},
|
366
|
+
|
355
367
|
// Subscribe to a channel
|
356
368
|
subscribe: function(channel, func, lastId) {
|
357
369
|
|
data/lib/message_bus.rb
CHANGED
@@ -154,6 +154,11 @@ module MessageBus::Implementation
|
|
154
154
|
@config[:is_admin_lookup]
|
155
155
|
end
|
156
156
|
|
157
|
+
def on_middleware_error(&blk)
|
158
|
+
configure(on_middleware_error: blk) if blk
|
159
|
+
@config[:on_middleware_error]
|
160
|
+
end
|
161
|
+
|
157
162
|
def extra_response_headers_lookup(&blk)
|
158
163
|
configure(extra_response_headers_lookup: blk) if blk
|
159
164
|
@config[:extra_response_headers_lookup]
|
@@ -181,6 +181,13 @@ class MessageBus::Rack::Middleware
|
|
181
181
|
else
|
182
182
|
[200, headers, ["[]"]]
|
183
183
|
end
|
184
|
+
|
185
|
+
rescue => e
|
186
|
+
if @bus.on_middleware_error && result=@bus.on_middleware_error.call(env, e)
|
187
|
+
result
|
188
|
+
else
|
189
|
+
raise
|
190
|
+
end
|
184
191
|
end
|
185
192
|
|
186
193
|
def close_db_connection!
|
data/lib/message_bus/version.rb
CHANGED
@@ -20,6 +20,16 @@ describe("Messagebus", function() {
|
|
20
20
|
});
|
21
21
|
});
|
22
22
|
|
23
|
+
it('returns status', function(done){
|
24
|
+
MessageBus.pause();
|
25
|
+
expect(MessageBus.status()).toMatch("paused");
|
26
|
+
MessageBus.resume();
|
27
|
+
expect(MessageBus.status()).toMatch("started");
|
28
|
+
MessageBus.stop();
|
29
|
+
expect(MessageBus.status()).toMatch("stopped");
|
30
|
+
done();
|
31
|
+
});
|
32
|
+
|
23
33
|
it('stores messages when paused, then delivers them when resumed', function(done){
|
24
34
|
MessageBus.pause()
|
25
35
|
spyOn(this.MockedXMLHttpRequest.prototype, 'send').and.callThrough();
|
@@ -309,6 +309,28 @@ describe MessageBus::Rack::Middleware do
|
|
309
309
|
JSON.parse(last_response.body).first["data"].must_equal({'json' => true})
|
310
310
|
end
|
311
311
|
|
312
|
+
describe "on_middleware_error handling" do
|
313
|
+
it "allows error handling of middleware failures" do
|
314
|
+
|
315
|
+
@bus.on_middleware_error do |env, err|
|
316
|
+
if ArgumentError === err
|
317
|
+
[407,{},[]]
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
@bus.group_ids_lookup do |env|
|
322
|
+
raise ArgumentError
|
323
|
+
end
|
324
|
+
|
325
|
+
post( "/message-bus/1234",
|
326
|
+
JSON.generate({'/foo' => 1}),
|
327
|
+
{ "CONTENT_TYPE" => "application/json" })
|
328
|
+
|
329
|
+
last_response.status.must_equal 407
|
330
|
+
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
312
334
|
describe "messagebus.channels env support" do
|
313
335
|
let(:extra_middleware) do
|
314
336
|
Class.new do
|
@@ -73,7 +73,7 @@
|
|
73
73
|
if (callback.channel === message.channel) {
|
74
74
|
callback.last_id = message.message_id;
|
75
75
|
try {
|
76
|
-
callback.func(message.data);
|
76
|
+
callback.func(message.data, message.global_id, message.message_id);
|
77
77
|
}
|
78
78
|
catch(e){
|
79
79
|
if(console.log) {
|
@@ -352,6 +352,18 @@
|
|
352
352
|
poll();
|
353
353
|
},
|
354
354
|
|
355
|
+
"status": function() {
|
356
|
+
if (paused) {
|
357
|
+
return "paused";
|
358
|
+
} else if (started) {
|
359
|
+
return "started";
|
360
|
+
} else if (stopped) {
|
361
|
+
return "stopped";
|
362
|
+
} else {
|
363
|
+
throw "Cannot determine current status";
|
364
|
+
}
|
365
|
+
},
|
366
|
+
|
355
367
|
// Subscribe to a channel
|
356
368
|
subscribe: function(channel, func, lastId) {
|
357
369
|
|
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.0.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: 2016-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|