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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: d2bee95bc6938bb37f780cf48bccd6481f2bca144c6672acac69e6d3e1ef176b
4
- data.tar.gz: 387450399296441956030b46054a48b2f996c02e51eeb32e5bc181fa03d8b6d8
2
+ SHA1:
3
+ metadata.gz: b2c8ffc1228b2e50751a6671ce91e12239e22cf3
4
+ data.tar.gz: 76b8c24586fa1781acd95dd352b269cf4a21bf99
5
5
  SHA512:
6
- metadata.gz: 2a87dd71aba2740acd7dd326b9f9d2d8cf3b51c33f2c498bbb128346ed52fc2483f52b9135d5320c8ce3d025d2cb7357260d78b8d5963600256cb62704bfb173
7
- data.tar.gz: db86f4a8d2b3949ced575612eac992d9d878abe836ee818340ef2045486a0debc816600db95ffb19a497acf3371e673473fe7bcf5d54f48cbd7b1505db8bc791
6
+ metadata.gz: 2f17a8234add27233c63619a73bf214b38c53cb5e4938f61b7b13a1d3fd605f20bb335d213f5c0202a4f6358d0dfd982bf38a8079571e77ffce3fb67eb0d7245
7
+ data.tar.gz: 5815b33e4f0cce2de16ac2bd6836bbb2eb1d115fb87818e00a35cc571841fdcff36125453d9c24bab725004941c9ef861aaa683d5c5c728edd18fff50c3fc34b
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 20-04-2018
2
+
3
+ - Version 2.1.3
4
+
5
+ - FIX: Subtle issue where poll timeout may not be cleared causing multiple concurrent polls
6
+
1
7
  09-01-2018
2
8
 
3
9
  - Version 2.1.2
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:
@@ -289,6 +289,9 @@
289
289
  }
290
290
  }
291
291
 
292
+ if (pollTimeout) {
293
+ clearTimeout(pollTimeout);
294
+ }
292
295
  pollTimeout = setTimeout(function(){
293
296
  pollTimeout = null;
294
297
  poll();
@@ -277,7 +277,7 @@ class MessageBus::Memory::ReliablePubSub
277
277
  end
278
278
  end
279
279
  rescue => error
280
- MessageBus.logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack\n#{error.backtrace.join("\n")}"
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
- MessageBus.logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack\n#{error.backtrace.join("\n")}"
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
- MessageBus.logger.warn("Dropping old message cause max_in_memory_publish_backlog is full: #{e.message}\n#{e.backtrace.join('\n')}")
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
- MessageBus.logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
205
+ @logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
205
206
  end
206
207
  rescue => e
207
- MessageBus.logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
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
- MessageBus.logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack #{error.backtrace}"
371
+ @logger.warn "#{error} subscribe failed, reconnecting in 1 second. Call stack #{error.backtrace}"
371
372
  sleep 1
372
373
  retry
373
374
  end
@@ -36,7 +36,7 @@ class MessageBus::ConnectionManager
36
36
  end
37
37
 
38
38
  rescue => e
39
- MessageBus.logger.error "notify clients crash #{e} : #{e.backtrace}"
39
+ @bus.logger.error "notify clients crash #{e} : #{e.backtrace}"
40
40
  end
41
41
  end
42
42
  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
- MessageBus.subscribe('/_diagnostics/hup') do |msg|
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
- MessageBus.subscribe('/_diagnostics/discover') do |msg|
42
- MessageBus.on_connect.call msg.site_id if MessageBus.on_connect
43
- MessageBus.publish '/_diagnostics/process-discovery', {
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
- MessageBus.on_disconnect.call msg.site_id if MessageBus.on_disconnect
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
- MessageBus.timer.queue(&run)
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 = MessageBus.timer.queue(@bus.long_polling_interval.to_f / 1000) {
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!
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module MessageBus
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.3"
4
4
  end
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
- MessageBus.logger.warn "Unexpected error in subscriber thread #{e}"
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
- MessageBus.logger.warn "Global messages on #{Process.pid} timed out, restarting process"
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
- MessageBus.logger.warn "#{Process.pid} successfully terminated by `TERM` signal."
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
- MessageBus.logger.warn "failed to deliver message, skipping #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
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
- MessageBus.logger.warn "failed to process message #{msg.inspect}\n ex: #{e} backtrace: #{e.backtrace}"
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
@@ -289,6 +289,9 @@
289
289
  }
290
290
  }
291
291
 
292
+ if (pollTimeout) {
293
+ clearTimeout(pollTimeout);
294
+ }
292
295
  pollTimeout = setTimeout(function(){
293
296
  pollTimeout = null;
294
297
  poll();
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.2
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-01-09 00:00:00.000000000 Z
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.7.3
145
+ rubygems_version: 2.6.13
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: ''