message_bus 2.1.2 → 2.1.3
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 +5 -5
- data/CHANGELOG +6 -0
- data/README.md +24 -2
- data/assets/message-bus.js +3 -0
- data/lib/message_bus/backends/memory.rb +1 -1
- data/lib/message_bus/backends/postgres.rb +1 -1
- data/lib/message_bus/backends/redis.rb +5 -4
- data/lib/message_bus/connection_manager.rb +1 -1
- data/lib/message_bus/diagnostics.rb +6 -6
- data/lib/message_bus/rack/middleware.rb +2 -2
- data/lib/message_bus/version.rb +1 -1
- data/lib/message_bus.rb +11 -6
- data/vendor/assets/javascripts/message-bus.js +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2c8ffc1228b2e50751a6671ce91e12239e22cf3
|
4
|
+
data.tar.gz: 76b8c24586fa1781acd95dd352b269cf4a21bf99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f17a8234add27233c63619a73bf214b38c53cb5e4938f61b7b13a1d3fd605f20bb335d213f5c0202a4f6358d0dfd982bf38a8079571e77ffce3fb67eb0d7245
|
7
|
+
data.tar.gz: 5815b33e4f0cce2de16ac2bd6836bbb2eb1d115fb87818e00a35cc571841fdcff36125453d9c24bab725004941c9ef861aaa683d5c5c728edd18fff50c3fc34b
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,7 @@ Live chat demo per [examples/chat](https://github.com/SamSaffron/message_bus/tre
|
|
19
19
|
|
20
20
|
If you are looking to contribute to this project here are some ideas
|
21
21
|
|
22
|
+
- MAKE THIS README BETTER!
|
22
23
|
- Build backends for other providers (zeromq, rabbitmq, disque) - currently we support pg and redis.
|
23
24
|
- Improve and properly document admin dashboard (add opt-in stats, better diagnostics into queues)
|
24
25
|
- Improve general documentation (Add examples, refine existing examples)
|
@@ -58,6 +59,9 @@ Server to Server messaging
|
|
58
59
|
```ruby
|
59
60
|
message_id = MessageBus.publish "/channel", "message"
|
60
61
|
|
62
|
+
# last id in a channel
|
63
|
+
id = MessageBus.last_id("/channel")
|
64
|
+
|
61
65
|
# in another process / spot
|
62
66
|
|
63
67
|
MessageBus.subscribe "/channel" do |msg|
|
@@ -142,13 +146,13 @@ location /message-bus/ {
|
|
142
146
|
|
143
147
|
If you wish to disable chunked encoding run:
|
144
148
|
|
145
|
-
```
|
149
|
+
```ruby
|
146
150
|
MessageBus.enableChunkedEncoding = false; // in your JavaScript
|
147
151
|
```
|
148
152
|
|
149
153
|
Or
|
150
154
|
|
151
|
-
```
|
155
|
+
```ruby
|
152
156
|
MessageBus.configure(chunked_encoding_enabled: false) // in Ruby
|
153
157
|
```
|
154
158
|
|
@@ -282,6 +286,24 @@ MessageBus.configure(backend: :redis, url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
|
|
282
286
|
```
|
283
287
|
The redis client message_bus uses is [redis-rb](https://github.com/redis/redis-rb), so you can visit it's repo to see what options you can configure.
|
284
288
|
|
289
|
+
#### Data Retention
|
290
|
+
|
291
|
+
Out of the box Redis keeps track of 2000 messages in the global backlog and 1000 messages in a per-channel backlog. Per-channel backlogs get cleared automatically after 7 days of inactivity.
|
292
|
+
|
293
|
+
This is configurable via accessors on the ReliablePubSub instance.
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
# only store 100 messages per channel
|
297
|
+
MessageBus.reliabe_pub_sub.max_backlog_size = 100
|
298
|
+
|
299
|
+
# only store 100 global messages
|
300
|
+
MessageBus.reliabe_pub_sub.max_global_backlog_size = 100
|
301
|
+
|
302
|
+
# flush per-channel backlog after 100 seconds of inactivity
|
303
|
+
MessageBus.reliabe_pub_sub.max_backlog_age = 100
|
304
|
+
|
305
|
+
```
|
306
|
+
|
285
307
|
### PostgreSQL
|
286
308
|
|
287
309
|
message_bus also supports PostgreSQL as the backend:
|
data/assets/message-bus.js
CHANGED
@@ -277,7 +277,7 @@ class MessageBus::Memory::ReliablePubSub
|
|
277
277
|
end
|
278
278
|
end
|
279
279
|
rescue => error
|
280
|
-
|
280
|
+
@config[:logger].warn "#{error} subscribe failed, reconnecting in 1 second. Call stack\n#{error.backtrace.join("\n")}"
|
281
281
|
sleep 1
|
282
282
|
retry
|
283
283
|
end
|
@@ -379,7 +379,7 @@ class MessageBus::Postgres::ReliablePubSub
|
|
379
379
|
end
|
380
380
|
end
|
381
381
|
rescue => error
|
382
|
-
|
382
|
+
@config[:logger].warn "#{error} subscribe failed, reconnecting in 1 second. Call stack\n#{error.backtrace.join("\n")}"
|
383
383
|
sleep 1
|
384
384
|
retry
|
385
385
|
end
|
@@ -30,6 +30,7 @@ class MessageBus::Redis::ReliablePubSub
|
|
30
30
|
# max_backlog_size is per multiplexed channel
|
31
31
|
def initialize(redis_config = {}, max_backlog_size = 1000)
|
32
32
|
@redis_config = redis_config.dup
|
33
|
+
@logger = @redis_config[:logger]
|
33
34
|
unless @redis_config[:enable_redis_logger]
|
34
35
|
@redis_config[:logger] = nil
|
35
36
|
end
|
@@ -160,7 +161,7 @@ LUA
|
|
160
161
|
@in_memory_backlog << [channel, data]
|
161
162
|
if @in_memory_backlog.length > @max_in_memory_publish_backlog
|
162
163
|
@in_memory_backlog.delete_at(0)
|
163
|
-
|
164
|
+
@logger.warn("Dropping old message cause max_in_memory_publish_backlog is full: #{e.message}\n#{e.backtrace.join('\n')}")
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
@@ -201,10 +202,10 @@ LUA
|
|
201
202
|
if e.message =~ /^READONLY/
|
202
203
|
try_again = true
|
203
204
|
else
|
204
|
-
|
205
|
+
@logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
|
205
206
|
end
|
206
207
|
rescue => e
|
207
|
-
|
208
|
+
@logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
|
208
209
|
end
|
209
210
|
|
210
211
|
@in_memory_backlog.delete_at(0) unless try_again
|
@@ -367,7 +368,7 @@ LUA
|
|
367
368
|
end
|
368
369
|
end
|
369
370
|
rescue => error
|
370
|
-
|
371
|
+
@logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack #{error.backtrace}"
|
371
372
|
sleep 1
|
372
373
|
retry
|
373
374
|
end
|
@@ -23,14 +23,14 @@ class MessageBus::Diagnostics
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.enable
|
26
|
+
def self.enable(bus = MessageBus)
|
27
27
|
full_path = full_process_path
|
28
28
|
start_time = Time.now.to_f
|
29
29
|
hostname = self.hostname
|
30
30
|
|
31
31
|
# it may make sense to add a channel per machine/host to streamline
|
32
32
|
# process to process comms
|
33
|
-
|
33
|
+
bus.subscribe('/_diagnostics/hup') do |msg|
|
34
34
|
if Process.pid == msg.data["pid"] && hostname == msg.data["hostname"]
|
35
35
|
$shutdown = true
|
36
36
|
sleep 4
|
@@ -38,16 +38,16 @@ class MessageBus::Diagnostics
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
bus.subscribe('/_diagnostics/discover') do |msg|
|
42
|
+
bus.on_connect.call msg.site_id if bus.on_connect
|
43
|
+
bus.publish '/_diagnostics/process-discovery', {
|
44
44
|
pid: Process.pid,
|
45
45
|
process_name: $0,
|
46
46
|
full_path: full_path,
|
47
47
|
uptime: (Time.now.to_f - start_time).to_i,
|
48
48
|
hostname: hostname
|
49
49
|
}, user_ids: [msg.data["user_id"]]
|
50
|
-
|
50
|
+
bus.on_disconnect.call msg.site_id if bus.on_disconnect
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -24,7 +24,7 @@ class MessageBus::Rack::Middleware
|
|
24
24
|
if thin_running
|
25
25
|
EM.next_tick(&run)
|
26
26
|
else
|
27
|
-
|
27
|
+
@bus.timer.queue(&run)
|
28
28
|
end
|
29
29
|
|
30
30
|
@started_listener = true
|
@@ -204,7 +204,7 @@ class MessageBus::Rack::Middleware
|
|
204
204
|
def add_client_with_timeout(client)
|
205
205
|
@connection_manager.add_client(client)
|
206
206
|
|
207
|
-
client.cleanup_timer =
|
207
|
+
client.cleanup_timer = @bus.timer.queue(@bus.long_polling_interval.to_f / 1000) {
|
208
208
|
begin
|
209
209
|
client.cleanup_timer = nil
|
210
210
|
client.ensure_closed!
|
data/lib/message_bus/version.rb
CHANGED
data/lib/message_bus.rb
CHANGED
@@ -195,6 +195,11 @@ module MessageBus::Implementation
|
|
195
195
|
def reliable_pub_sub
|
196
196
|
@mutex.synchronize do
|
197
197
|
return nil if @destroyed
|
198
|
+
|
199
|
+
# Make sure logger is loaded before config is
|
200
|
+
# passed to backend.
|
201
|
+
logger
|
202
|
+
|
198
203
|
@config[:reliable_pub_sub] ||= begin
|
199
204
|
@config[:backend_options] ||= {}
|
200
205
|
require "message_bus/backends/#{backend}"
|
@@ -208,7 +213,7 @@ module MessageBus::Implementation
|
|
208
213
|
end
|
209
214
|
|
210
215
|
def enable_diagnostics
|
211
|
-
MessageBus::Diagnostics.enable
|
216
|
+
MessageBus::Diagnostics.enable(self)
|
212
217
|
end
|
213
218
|
|
214
219
|
def publish(channel, data, opts = nil)
|
@@ -472,7 +477,7 @@ module MessageBus::Implementation
|
|
472
477
|
begin
|
473
478
|
global_subscribe_thread unless @destroyed
|
474
479
|
rescue => e
|
475
|
-
|
480
|
+
logger.warn "Unexpected error in subscriber thread #{e}"
|
476
481
|
end
|
477
482
|
end
|
478
483
|
|
@@ -486,7 +491,7 @@ module MessageBus::Implementation
|
|
486
491
|
# going for x3 keepalives missed for a restart, need to ensure this only very rarely happens
|
487
492
|
# note: after_fork will sort out a bad @last_message date, but thread will be dead anyway
|
488
493
|
if (Time.now - (@last_message || Time.now)) > keepalive_interval * 3
|
489
|
-
|
494
|
+
logger.warn "Global messages on #{Process.pid} timed out, restarting process"
|
490
495
|
# No other clean way to remove this thread, its listening on a socket
|
491
496
|
# no data is arriving
|
492
497
|
#
|
@@ -501,7 +506,7 @@ module MessageBus::Implementation
|
|
501
506
|
begin
|
502
507
|
Process.kill('KILL', pid)
|
503
508
|
rescue Errno::ESRCH
|
504
|
-
|
509
|
+
logger.warn "#{Process.pid} successfully terminated by `TERM` signal."
|
505
510
|
end
|
506
511
|
end
|
507
512
|
|
@@ -546,11 +551,11 @@ module MessageBus::Implementation
|
|
546
551
|
begin
|
547
552
|
c.call msg
|
548
553
|
rescue => e
|
549
|
-
|
554
|
+
logger.warn "failed to deliver message, skipping #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
|
550
555
|
end
|
551
556
|
end
|
552
557
|
rescue => e
|
553
|
-
|
558
|
+
logger.warn "failed to process message #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
|
554
559
|
end
|
555
560
|
@global_id = msg.global_id
|
556
561
|
end
|
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.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.6.13
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: ''
|