message_bus 1.0.14 → 1.0.15

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: 6909db1677e03068c2536f5576a123e371f946dd
4
- data.tar.gz: a4aab49db0edf4340ca5cd84a9f6c4a75f2928bf
3
+ metadata.gz: b1ac114fd681f0af69bcfd05337dfbe4d01a7ec5
4
+ data.tar.gz: 8dccb7dcc0e2cfda466c3c86ab457c874e4c181c
5
5
  SHA512:
6
- metadata.gz: be441795c69094b47ac1860310ff33e35bb1a61920ed31f93bffd5425a13a505f6ff8d0a04b19779700ed457c263414be5daa6001c349925880958acd966bdd3
7
- data.tar.gz: 455e07565586f43d12d89fbe7ee79177aad36973b5f4576d5cdafbebd9f9249b370df3f8023a77575c32e4cc697c4b4a44b501b161a6fcfec14d5021d808c811
6
+ metadata.gz: 19e87e3c06a0044ca70161484aa0f121ee5fe2a99cbda8edf6bcecaf87258e8e6e68b2b1983073e8430c881a8b8df6f186b7cfa1e0218dfa0350784c44cdbbcc
7
+ data.tar.gz: 23baa4e52b0dd3f660c7b0fdca2055571735d7d09a794ec84bf83fe8ad046f3ecaefff6db002a46cf9036e6d7ef6a601d9596eb7b7bb22b77389567f027bdf47
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 09-07-2015
2
+ - Version 1.0.15
3
+ - Feature: MessageBus.reliable_pub_sub.max_backlog_age (in secs) configurable (default to 7 days)
4
+ - Fix: API for MessageBus.backlog("/bla") was returning global backlog by mistake
5
+ - Change: Max global backlog size reduced to 2000 elements
6
+
1
7
  08-06-2015
2
8
  - Version 1.0.14
3
9
  - Fix: we can not use Thread#kill best keepalive can do is terminate process cleanly
data/README.md CHANGED
@@ -99,6 +99,18 @@ MessageBus.subscribe("/channel", function(data){
99
99
 
100
100
  ```
101
101
 
102
+ ## Configuration
103
+
104
+ ### Redis
105
+
106
+ You can configure redis setting in `config/initializers/message_bus.rb`, like
107
+
108
+ ```ruby
109
+ MessageBus.redis_config = { url: "redis://:p4ssw0rd@10.0.1.1:6380/15" }
110
+ ```
111
+ 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.
112
+
113
+
102
114
  ## Similar projects
103
115
 
104
116
  Faye - http://faye.jcoglan.com/
data/lib/message_bus.rb CHANGED
@@ -264,7 +264,11 @@ module MessageBus::Implementation
264
264
  subscribe_impl(channel, site_id, &blk)
265
265
  end
266
266
 
267
- def backlog(channel=nil, last_id)
267
+ def global_backlog(last_id=nil)
268
+ backlog(nil, last_id)
269
+ end
270
+
271
+ def backlog(channel=nil, last_id=nil)
268
272
  old =
269
273
  if channel
270
274
  reliable_pub_sub.backlog(encode_channel_name(channel), last_id)
@@ -11,7 +11,8 @@ module MessageBus::Redis; end
11
11
  class MessageBus::Redis::ReliablePubSub
12
12
  attr_reader :subscribed
13
13
  attr_accessor :max_publish_retries, :max_publish_wait, :max_backlog_size,
14
- :max_global_backlog_size, :max_in_memory_publish_backlog
14
+ :max_global_backlog_size, :max_in_memory_publish_backlog,
15
+ :max_backlog_age
15
16
 
16
17
  UNSUB_MESSAGE = "$$UNSUBSCRIBE"
17
18
 
@@ -28,14 +29,15 @@ class MessageBus::Redis::ReliablePubSub
28
29
  def initialize(redis_config = {}, max_backlog_size = 1000)
29
30
  @redis_config = redis_config
30
31
  @max_backlog_size = max_backlog_size
31
- # we can store a lot of messages, since only one queue
32
- @max_global_backlog_size = 100000
32
+ @max_global_backlog_size = 2000
33
33
  @max_publish_retries = 10
34
34
  @max_publish_wait = 500 #ms
35
35
  @max_in_memory_publish_backlog = 1000
36
36
  @in_memory_backlog = []
37
37
  @lock = Mutex.new
38
38
  @flush_backlog_thread = nil
39
+ # after 7 days inactive backlogs will be removed
40
+ @max_backlog_age = 604800
39
41
  end
40
42
 
41
43
  def new_redis_connection
@@ -98,17 +100,24 @@ class MessageBus::Redis::ReliablePubSub
98
100
  msg = MessageBus::Message.new global_id, backlog_id, channel, data
99
101
  payload = msg.encode
100
102
 
101
- redis.zadd backlog_key, backlog_id, payload
102
- redis.zadd global_backlog_key, global_id, backlog_id.to_s << "|" << channel
103
+ redis.multi do |m|
103
104
 
104
- redis.publish redis_channel_name, payload
105
+ redis.zadd backlog_key, backlog_id, payload
106
+ redis.expire backlog_key, @max_backlog_age
105
107
 
106
- if backlog_id > @max_backlog_size
107
- redis.zremrangebyscore backlog_key, 1, backlog_id - @max_backlog_size
108
- end
108
+ redis.zadd global_backlog_key, global_id, backlog_id.to_s << "|" << channel
109
+ redis.expire global_backlog_key, @max_backlog_age
110
+
111
+ redis.publish redis_channel_name, payload
112
+
113
+ if backlog_id > @max_backlog_size
114
+ redis.zremrangebyscore backlog_key, 1, backlog_id - @max_backlog_size
115
+ end
116
+
117
+ if global_id > @max_global_backlog_size
118
+ redis.zremrangebyscore global_backlog_key, 1, global_id - @max_global_backlog_size
119
+ end
109
120
 
110
- if global_id > @max_global_backlog_size
111
- redis.zremrangebyscore global_backlog_key, 1, global_id - @max_global_backlog_size
112
121
  end
113
122
 
114
123
  backlog_id
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "1.0.14"
2
+ VERSION = "1.0.15"
3
3
  end
@@ -115,6 +115,15 @@ describe MessageBus do
115
115
  r.map{|i| i.data}.to_a.should == ['foo', 'bar']
116
116
  end
117
117
 
118
+ it "should correctly get full backlog of a channel" do
119
+ @bus.publish("/chuck", "norris")
120
+ @bus.publish("/chuck", "foo")
121
+ @bus.publish("/chuckles", "bar")
122
+
123
+ @bus.backlog("/chuck").map{|i| i.data}.to_a.should == ['norris', 'foo']
124
+
125
+ end
126
+
118
127
  it "allows you to look up last_message" do
119
128
  @bus.publish("/bob", "dylan")
120
129
  @bus.publish("/bob", "marley")
@@ -201,7 +210,7 @@ describe MessageBus do
201
210
 
202
211
  $stdout.reopen("/dev/null", "w")
203
212
  $stderr.reopen("/dev/null", "w")
204
-
213
+
205
214
  # having some issues with exit here
206
215
  # TODO find and fix
207
216
  Process.kill "KILL", Process.pid
@@ -37,6 +37,13 @@ describe MessageBus::Redis::ReliablePubSub do
37
37
  end
38
38
  end
39
39
 
40
+ it "can set backlog age" do
41
+ @bus.max_backlog_age = 100
42
+ @bus.publish "/foo", "bar"
43
+ @bus.pub_redis.ttl(@bus.backlog_key("/foo")).should be <= 100
44
+ @bus.pub_redis.ttl(@bus.backlog_key("/foo")).should be > 0
45
+ end
46
+
40
47
  it "should be able to access the backlog" do
41
48
  @bus.publish "/foo", "bar"
42
49
  @bus.publish "/foo", "baz"
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.0.14
4
+ version: 1.0.15
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-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack