message_bus 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b1d52c269db2dcec90068d0ceb828b969666a64
4
- data.tar.gz: e2e46e33612cde225c94c17367599b63f3c824f4
3
+ metadata.gz: 6f16dc2f9a430b6e138bf4eba50155f27814356a
4
+ data.tar.gz: 64d84fbec00b3b9c01d7b90448db1693ccde7ad0
5
5
  SHA512:
6
- metadata.gz: 523d379b630f2c3d23db73835bde99b5fda6003f448ce7d9f3d66c169bbd18775d251aad51dc269bfe987e62279d49475712f5bab32db1baaf2c404fa6110a5c
7
- data.tar.gz: 42aa9744353b2a70fb7dfe6422a30eaaa721deb161695f0ea084cec809acde201af451cc253f801d3623257ad7f700fb8921d482d2d61fe21909542ef8e4074a
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
- globals = @subscriptions[nil]
232
- locals = @subscriptions[msg.site_id] if msg.site_id
251
+ @mutex.synchronize do
252
+ globals = @subscriptions[nil]
253
+ locals = @subscriptions[msg.site_id] if msg.site_id
233
254
 
234
- global_globals = globals[nil] if globals
235
- local_globals = locals[nil] if locals
255
+ global_globals = globals[nil] if globals
256
+ local_globals = locals[nil] if locals
236
257
 
237
- globals = globals[msg.channel] if globals
238
- locals = locals[msg.channel] if locals
258
+ globals = globals[msg.channel] if globals
259
+ locals = locals[msg.channel] if locals
239
260
 
240
- multi_each(globals,locals, global_globals, local_globals) do |c|
241
- begin
242
- c.call msg
243
- rescue => e
244
- MessageBus.logger.warn "failed to deliver message, skipping #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
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
 
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron