message_bus 0.0.1 → 0.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/README.md +21 -0
- data/lib/message_bus.rb +33 -11
- data/lib/message_bus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f16dc2f9a430b6e138bf4eba50155f27814356a
|
4
|
+
data.tar.gz: 64d84fbec00b3b9c01d7b90448db1693ccde7ad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7266850ef7f3c3d883ff437d9e3235073d2c8d082895e5c37253dd9934a274cd1ee326ffe4e6aa6c0725455db8bbe8d62a74895d312cc3862f66ca3d12b29d10
|
7
|
+
data.tar.gz: 2210de6251404a4a27962bf2fae46da513057ed5cc91c2a6f5f0f229638b1bc5cb019beafad8befbbb2ff0e3cdd8cc4568e3a5a1f49c8671f90d508c4d1f5835
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A reliable, robust messaging bus for Ruby processes and web clients built on Redis.
|
4
4
|
|
5
|
+
MessageBus implements a Server to Server channel based protocol and Server to Web Client protocol (using polling or long-polling)
|
6
|
+
|
5
7
|
|
6
8
|
## Installation
|
7
9
|
|
@@ -48,6 +50,25 @@ MessageBus.group_ids_lookup do |env|
|
|
48
50
|
# can be nil or []
|
49
51
|
end
|
50
52
|
|
53
|
+
```
|
54
|
+
|
55
|
+
JavaScript can listen on any channel (and receive notification via polling or long polling):
|
56
|
+
|
57
|
+
```html
|
58
|
+
<script src="message-bus.js" type="text/javascript"></script>
|
59
|
+
```
|
60
|
+
Note, the message-bus.js file is located in the assets folder.
|
61
|
+
|
62
|
+
```javascript
|
63
|
+
MessageBus.start(); // call once at startup
|
64
|
+
|
65
|
+
// how often do you want the callback to fire in ms
|
66
|
+
MessageBus.callbackInterval = 500;
|
67
|
+
MessageBus.subscribe("/channel", function(data){
|
68
|
+
// data shipped from server
|
69
|
+
}
|
70
|
+
|
71
|
+
|
51
72
|
```
|
52
73
|
|
53
74
|
|
data/lib/message_bus.rb
CHANGED
@@ -174,6 +174,15 @@ module MessageBus::Implementation
|
|
174
174
|
subscribe_impl(channel, nil, &blk)
|
175
175
|
end
|
176
176
|
|
177
|
+
def unsubscribe(channel=nil, &blk)
|
178
|
+
unsubscribe_impl(channel, nil, &blk)
|
179
|
+
end
|
180
|
+
|
181
|
+
def local_unsubscribe(channel=nil, &blk)
|
182
|
+
site_id = MessageBus.site_id_lookup.call if MessageBus.site_id_lookup
|
183
|
+
unsubscribe_impl(channel, site_id, &blk)
|
184
|
+
end
|
185
|
+
|
177
186
|
# subscribe only on current site
|
178
187
|
def local_subscribe(channel=nil, &blk)
|
179
188
|
site_id = MessageBus.site_id_lookup.call if MessageBus.site_id_lookup
|
@@ -217,6 +226,17 @@ module MessageBus::Implementation
|
|
217
226
|
@subscriptions[site_id][channel] ||= []
|
218
227
|
@subscriptions[site_id][channel] << blk
|
219
228
|
ensure_subscriber_thread
|
229
|
+
blk
|
230
|
+
end
|
231
|
+
|
232
|
+
def unsubscribe_impl(channel, site_id, &blk)
|
233
|
+
@mutex.synchronize do
|
234
|
+
if blk
|
235
|
+
@subscriptions[site_id][channel].delete blk
|
236
|
+
else
|
237
|
+
@subscriptions[site_id][channel] = []
|
238
|
+
end
|
239
|
+
end
|
220
240
|
end
|
221
241
|
|
222
242
|
def ensure_subscriber_thread
|
@@ -228,20 +248,22 @@ module MessageBus::Implementation
|
|
228
248
|
begin
|
229
249
|
decode_message!(msg)
|
230
250
|
|
231
|
-
|
232
|
-
|
251
|
+
@mutex.synchronize do
|
252
|
+
globals = @subscriptions[nil]
|
253
|
+
locals = @subscriptions[msg.site_id] if msg.site_id
|
233
254
|
|
234
|
-
|
235
|
-
|
255
|
+
global_globals = globals[nil] if globals
|
256
|
+
local_globals = locals[nil] if locals
|
236
257
|
|
237
|
-
|
238
|
-
|
258
|
+
globals = globals[msg.channel] if globals
|
259
|
+
locals = locals[msg.channel] if locals
|
239
260
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
261
|
+
multi_each(globals,locals, global_globals, local_globals) do |c|
|
262
|
+
begin
|
263
|
+
c.call msg
|
264
|
+
rescue => e
|
265
|
+
MessageBus.logger.warn "failed to deliver message, skipping #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
|
266
|
+
end
|
245
267
|
end
|
246
268
|
end
|
247
269
|
|
data/lib/message_bus/version.rb
CHANGED