message_bus 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7add5c68e797a080452032f17f17930bd2d28092
4
- data.tar.gz: 15b55cad8b5dc0599d92fb88c74a83271703f46a
3
+ metadata.gz: 00b86d8f7631445d13999cf03c8474c94a5c6df0
4
+ data.tar.gz: da3f677b77b8695d27cb5d6997c22894ea33bd5b
5
5
  SHA512:
6
- metadata.gz: 3385147eb91410e0606e95d32183f017cf218b86d2c51f2cfed7fd8ec7b15394c64fa6b64bcc9e3862e61781030b7c8f4d8fbd640f4c3e698dc28e2dd784e3ed
7
- data.tar.gz: afcd0a5014c1c1f9ae229565d7dc7574f76eb1eecf544066acbed7b47db9d134b656a4bbc772ecf7285928f0e74b16a8c2e0f26cffa31aa252b55a86120066ef
6
+ metadata.gz: 7bba577513285f36a95898d524e2cc60f832be1e1c7bb92d63313fe82b5862dd3ddeb48930fff071bde92d85be03eea102836af19513633f23e0962c645e8d1d
7
+ data.tar.gz: bbb1d8c326c2e8c85ddacce97a37aabdf0562ac15b0bd7153ce1fec6ebebbd7c7d68d14a36ec45e1afaa2a1b911ca2e01facf4a86da521669251bf86e97143e2
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 09-12-2015
2
+
3
+ - Version 1.1.1
4
+ - Fix: In multisite config there was no way to specify site for last_id or backlog
5
+ to resolve overrides were added to #last_id and #backlog, MessageBus::Client now
6
+ uses the new overrides
7
+
1
8
  07-12-2015
2
9
 
3
10
  - Version 1.1.0
data/README.md CHANGED
@@ -4,6 +4,10 @@ A reliable, robust messaging bus for Ruby processes and web clients built on Red
4
4
 
5
5
  MessageBus implements a Server to Server channel based protocol and Server to Web Client protocol (using polling or long-polling)
6
6
 
7
+ Long-polling is implemented using Rack Hijack and Thin::Async, all common Ruby web server can run MessageBus (Thin, Puma, Unicorn) and handle a large amount of concurrent connections that wait on messages.
8
+
9
+ MessageBus is implemented as Rack middleware and can be used by and Rails / Sinatra or pure Rack application.
10
+
7
11
 
8
12
  ## Installation
9
13
 
@@ -78,8 +82,14 @@ MessageBus.publish "/channel", "some message"
78
82
 
79
83
  # you may publish messages to ALL sites using the /global/ prefix
80
84
  MessageBus.publish "/global/channel", "will go to all sites"
85
+
81
86
  ```
82
87
 
88
+ ### Client support
89
+
90
+ MessageBus ships a simple ~300 line JavaScript library which provides an API to interact with the server.
91
+
92
+
83
93
  JavaScript can listen on any channel (and receive notification via polling or long polling):
84
94
 
85
95
  ```html
@@ -96,9 +106,41 @@ MessageBus.subscribe("/channel", function(data){
96
106
  // data shipped from server
97
107
  });
98
108
 
99
-
100
109
  ```
101
110
 
111
+ **Client settings**:
112
+
113
+
114
+ All client settings are settable via `MessageBus.OPTION`
115
+
116
+ Setting|Default|
117
+ ----|---|---|
118
+ enableLongPolling|true|Allow long-polling (provided it is enable by the server)
119
+ callbackInterval|15000|Safeguard to ensure background polling does not exceed this interval (in milliseconds)
120
+ backgroundCallbackInterval|60000|Interval to poll when long polling is disabled (either explicitly or due to browser being in backgroud)
121
+ maxPollInterval|180000|If request to the server start failing, MessageBus will backoff, this is the upper limit of the backoff.
122
+ alwaysLongPoll|false|For debugging you may want to disable the "is browser in background" check and always long-poll
123
+ baseUrl|/|If message bus is mounted in a subdirectory of different domain, you may configure it to perform requests there
124
+ ajax|$.ajax|The only dependency on jQuery, you may set up a custom ajax function here
125
+
126
+ **API**:
127
+
128
+ `MessageBus.diagnostics()` : Returns a log that may be used for diagnostics on the status of message bus
129
+
130
+ `MessageBus.pause()` : Pause all MessageBus activity
131
+
132
+ `MessageBus.resume()` : Resume MessageBus activity
133
+
134
+ `MessageBus.stop()` : Stop all MessageBus activity
135
+
136
+ `MessageBus.start()` : Must be called to startup the MessageBus poller
137
+
138
+ `MessageBus.subscribe(channel,func,lastId)` : Subscribe to a channel, optionally you may specify the id of the last message you received in the channel.
139
+
140
+ `MessageBus.unsubscribe(channel,func)` : Unsubscribe callback from a particular channel
141
+
142
+
143
+
102
144
  ## Configuration
103
145
 
104
146
  ### Redis
@@ -145,14 +187,13 @@ after_fork do |server, worker|
145
187
  end
146
188
  ```
147
189
 
148
- ## Similar projects
190
+ ## Want to help?
191
+
192
+ If you are looking to contribute to this project here are some ideas
149
193
 
150
- Faye - http://faye.jcoglan.com/
194
+ - Build an in-memory storage backend to ease testing and for very simple deployments
195
+ - Build a PostgreSQL backend using NOTIFY and LISTEN
196
+ - Improve general documentation
197
+ - Port the test suite to MiniTest
151
198
 
152
- ## Contributing
153
199
 
154
- 1. Fork it
155
- 2. Create your feature branch (`git checkout -b my-new-feature`)
156
- 3. Commit your changes (`git commit -am 'Added some feature'`)
157
- 4. Push to the branch (`git push origin my-new-feature`)
158
- 5. Create new Pull Request
@@ -174,7 +174,7 @@ window.MessageBus = (function() {
174
174
  baseUrl: baseUrl,
175
175
  // TODO we can make the dependency on $ and jQuery conditional
176
176
  // all we really need is an implementation of ajax
177
- ajax: $.ajax,
177
+ ajax: ($ && $.ajax),
178
178
 
179
179
  diagnostics: function(){
180
180
  console.log("Stopped: " + stopped + " Started: " + started);
@@ -200,15 +200,13 @@ window.MessageBus = (function() {
200
200
  },
201
201
 
202
202
  // Start polling
203
- start: function(opts) {
203
+ start: function() {
204
204
  var poll, delayPollTimeout;
205
205
 
206
206
  if (started) return;
207
207
  started = true;
208
208
  stopped = false;
209
209
 
210
- if (!opts) opts = {};
211
-
212
210
  poll = function() {
213
211
  var data;
214
212
 
@@ -232,10 +232,10 @@ module MessageBus::Implementation
232
232
  ENCODE_SITE_TOKEN = "$|$"
233
233
 
234
234
  # encode channel name to include site
235
- def encode_channel_name(channel)
236
- if site_id_lookup && !global?(channel)
235
+ def encode_channel_name(channel, site_id=nil)
236
+ if (site_id || site_id_lookup) && !global?(channel)
237
237
  raise ArgumentError.new channel if channel.include? ENCODE_SITE_TOKEN
238
- "#{channel}#{ENCODE_SITE_TOKEN}#{site_id_lookup.call}"
238
+ "#{channel}#{ENCODE_SITE_TOKEN}#{site_id || site_id_lookup.call}"
239
239
  else
240
240
  channel
241
241
  end
@@ -268,10 +268,10 @@ module MessageBus::Implementation
268
268
  backlog(nil, last_id)
269
269
  end
270
270
 
271
- def backlog(channel=nil, last_id=nil)
271
+ def backlog(channel=nil, last_id=nil, site_id=nil)
272
272
  old =
273
273
  if channel
274
- reliable_pub_sub.backlog(encode_channel_name(channel), last_id)
274
+ reliable_pub_sub.backlog(encode_channel_name(channel,site_id), last_id)
275
275
  else
276
276
  reliable_pub_sub.global_backlog(last_id)
277
277
  end
@@ -282,8 +282,8 @@ module MessageBus::Implementation
282
282
  old
283
283
  end
284
284
 
285
- def last_id(channel)
286
- reliable_pub_sub.last_id(encode_channel_name(channel))
285
+ def last_id(channel,site_id=nil)
286
+ reliable_pub_sub.last_id(encode_channel_name(channel,site_id))
287
287
  end
288
288
 
289
289
  def last_message(channel)
@@ -89,7 +89,7 @@ class MessageBus::Client
89
89
  r = []
90
90
  @subscriptions.each do |k,v|
91
91
  next if v.to_i < 0
92
- messages = @bus.backlog(k,v)
92
+ messages = @bus.backlog(k, v, site_id)
93
93
  messages.each do |msg|
94
94
  r << msg if allowed?(msg)
95
95
  end
@@ -99,7 +99,7 @@ class MessageBus::Client
99
99
  @subscriptions.each do |k,v|
100
100
  if v.to_i == -1
101
101
  status_message ||= {}
102
- status_message[k] = @bus.last_id(k)
102
+ status_message[k] = @bus.last_id(k, site_id)
103
103
  end
104
104
  end
105
105
  r << MessageBus::Message.new(-1, -1, '/__status', status_message) if status_message
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -15,6 +15,31 @@ describe MessageBus::Client do
15
15
  @bus.destroy
16
16
  end
17
17
 
18
+ it "does not bleed data accross sites" do
19
+ @client.site_id = "test"
20
+
21
+ @client.subscribe('/hello', nil)
22
+ @bus.publish '/hello', 'world'
23
+ log = @client.backlog
24
+ log.length.should == 0
25
+ end
26
+
27
+ it "does not bleed status accross sites" do
28
+ @client.site_id = "test"
29
+
30
+ @client.subscribe('/hello', -1)
31
+ @bus.publish '/hello', 'world'
32
+ log = @client.backlog
33
+ log[0].data.should == {"/hello" => 0}
34
+ end
35
+
36
+ it "provides status" do
37
+ @client.subscribe('/hello', -1)
38
+ log = @client.backlog
39
+ log.length.should == 1
40
+ log[0].data.should == {"/hello" => 0}
41
+ end
42
+
18
43
  it "should provide a list of subscriptions" do
19
44
  @client.subscribe('/hello', nil)
20
45
  @client.subscriptions['/hello'].should_not be_nil
@@ -174,7 +174,7 @@ window.MessageBus = (function() {
174
174
  baseUrl: baseUrl,
175
175
  // TODO we can make the dependency on $ and jQuery conditional
176
176
  // all we really need is an implementation of ajax
177
- ajax: $.ajax,
177
+ ajax: ($ && $.ajax),
178
178
 
179
179
  diagnostics: function(){
180
180
  console.log("Stopped: " + stopped + " Started: " + started);
@@ -200,15 +200,13 @@ window.MessageBus = (function() {
200
200
  },
201
201
 
202
202
  // Start polling
203
- start: function(opts) {
203
+ start: function() {
204
204
  var poll, delayPollTimeout;
205
205
 
206
206
  if (started) return;
207
207
  started = true;
208
208
  stopped = false;
209
209
 
210
- if (!opts) opts = {};
211
-
212
210
  poll = function() {
213
211
  var data;
214
212
 
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack