message_bus 1.0.11 → 1.0.12

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: 3e596a5f9146a82e6197f01287502006f9330f9b
4
- data.tar.gz: bb698d73ba25f0681cdda865b6f09a348a9f2b17
3
+ metadata.gz: 9edd8ca36b455984824a1b9841e626352f04751e
4
+ data.tar.gz: 4f9069b34ea6823a316d20079ec698444f0c6e43
5
5
  SHA512:
6
- metadata.gz: 061915a68b0301e7d86d4f40fcd4f9f40b2d34f362350dfd89c881e73b1bddf245eaa1ecf7ad7e53cff82c3f35ab280361d7d80a9481416f3dd6df1352f2f623
7
- data.tar.gz: bdc6d8c4c2e822c9835ed73237eadfd5da825481ac3c0e15245e90b1fd3a8e704199e2fd08250aa73c830f94ad705767f9543894f8815cb07e6b1aeef4a0106c
6
+ metadata.gz: 6fcc39d57dc21800df3e6fee29ec9bcf95285a44588e6b05e4746693cd070c7f6492e86fdc852351bfde59b209f7d21780912927d0bf20a290f6d4c4ebfb2ebd
7
+ data.tar.gz: 408932aae79880e94ac15d65c2a5d6fa75eb46eacc2a6fda8eb45f704daac3e7cc1322e4ea5dbe5653b548cfa6b8299a15e157dce46d7bc00d288e45a4d2ef3a
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 28-05-2015
2
+ - Version 1.0.12
3
+ - Feature: Support client_id targetted message
4
+
1
5
  06-05-2015
2
6
  - Version 1.0.11
3
7
  - Fix: race condition in TimerThread
data/README.md CHANGED
@@ -39,6 +39,9 @@ MessageBus.backlog "/channel", id
39
39
  # messages can be targetted at particular users or groups
40
40
  MessageBus.publish "/channel", user_ids: [1,2,3], group_ids: [4,5,6]
41
41
 
42
+ # messages can be targetted at particular clients (using MessageBus.clientId)
43
+ MessageBus.publish "/channel", client_ids: ["XXX","YYY"]
44
+
42
45
  # message bus determines the user ids and groups based on env
43
46
 
44
47
  MessageBus.user_id_lookup do |env|
data/lib/message_bus.rb CHANGED
@@ -2,13 +2,13 @@ require "monitor"
2
2
  require "set"
3
3
  require "message_bus/version"
4
4
  require "message_bus/message"
5
- require "message_bus/reliable_pub_sub"
6
5
  require "message_bus/client"
7
6
  require "message_bus/connection_manager"
8
7
  require "message_bus/message_handler"
9
8
  require "message_bus/diagnostics"
10
9
  require "message_bus/rack/middleware"
11
10
  require "message_bus/rack/diagnostics"
11
+ require "message_bus/redis/reliable_pub_sub"
12
12
 
13
13
  # we still need to take care of the logger
14
14
  if defined?(::Rails)
@@ -177,10 +177,14 @@ module MessageBus::Implementation
177
177
  end
178
178
  end
179
179
 
180
+ def reliable_pub_sub=(pub_sub)
181
+ @reliable_pub_sub = pub_sub
182
+ end
183
+
180
184
  def reliable_pub_sub
181
185
  @mutex.synchronize do
182
186
  return nil if @destroyed
183
- @reliable_pub_sub ||= MessageBus::ReliablePubSub.new redis_config
187
+ @reliable_pub_sub ||= MessageBus::Redis::ReliablePubSub.new redis_config
184
188
  end
185
189
  end
186
190
 
@@ -196,9 +200,12 @@ module MessageBus::Implementation
196
200
 
197
201
  user_ids = nil
198
202
  group_ids = nil
203
+ client_ids = nil
204
+
199
205
  if opts
200
206
  user_ids = opts[:user_ids]
201
207
  group_ids = opts[:group_ids]
208
+ client_ids = opts[:client_ids]
202
209
  end
203
210
 
204
211
  raise ::MessageBus::InvalidMessage if (user_ids || group_ids) && global?(channel)
@@ -206,7 +213,8 @@ module MessageBus::Implementation
206
213
  encoded_data = JSON.dump({
207
214
  data: data,
208
215
  user_ids: user_ids,
209
- group_ids: group_ids
216
+ group_ids: group_ids,
217
+ client_ids: client_ids
210
218
  })
211
219
 
212
220
  reliable_pub_sub.publish(encode_channel_name(channel), encoded_data)
@@ -319,6 +327,7 @@ module MessageBus::Implementation
319
327
  msg.data = parsed["data"]
320
328
  msg.user_ids = parsed["user_ids"]
321
329
  msg.group_ids = parsed["group_ids"]
330
+ msg.client_ids = parsed["client_ids"]
322
331
  end
323
332
 
324
333
  def subscribe_impl(channel, site_id, &blk)
@@ -55,6 +55,7 @@ class MessageBus::Client
55
55
 
56
56
  def allowed?(msg)
57
57
  allowed = !msg.user_ids || msg.user_ids.include?(self.user_id)
58
+ allowed &&= !msg.client_ids || msg.client_ids.include?(self.client_id)
58
59
  allowed && (
59
60
  msg.group_ids.nil? ||
60
61
  msg.group_ids.length == 0 ||
@@ -1,13 +1,14 @@
1
1
  class MessageBus::Message < Struct.new(:global_id, :message_id, :channel , :data)
2
2
 
3
- attr_accessor :site_id, :user_ids, :group_ids
3
+ attr_accessor :site_id, :user_ids, :group_ids, :client_ids
4
4
 
5
5
  def self.decode(encoded)
6
6
  s1 = encoded.index("|")
7
7
  s2 = encoded.index("|", s1+1)
8
8
  s3 = encoded.index("|", s2+1)
9
9
 
10
- MessageBus::Message.new encoded[0..s1].to_i, encoded[s1+1..s2].to_i, encoded[s2+1..s3-1].gsub("$$123$$", "|"), encoded[s3+1..-1]
10
+ MessageBus::Message.new(encoded[0..s1].to_i, encoded[s1+1..s2].to_i,
11
+ encoded[s2+1..s3-1].gsub("$$123$$", "|"), encoded[s3+1..-1])
11
12
  end
12
13
 
13
14
  # only tricky thing to encode is pipes in a channel name ... do a straight replace
@@ -88,7 +88,8 @@ class MessageBus::Rack::Middleware
88
88
  # close db connection as early as possible
89
89
  close_db_connection!
90
90
 
91
- client = MessageBus::Client.new(message_bus: @bus, client_id: client_id, user_id: user_id, site_id: site_id, group_ids: group_ids)
91
+ client = MessageBus::Client.new(message_bus: @bus, client_id: client_id,
92
+ user_id: user_id, site_id: site_id, group_ids: group_ids)
92
93
 
93
94
  request = Rack::Request.new(env)
94
95
  request.POST.each do |k,v|
@@ -7,8 +7,8 @@ require 'redis'
7
7
  # ids are all sequencially increasing numbers starting at 0
8
8
  #
9
9
 
10
-
11
- class MessageBus::ReliablePubSub
10
+ module MessageBus::Redis; end
11
+ class MessageBus::Redis::ReliablePubSub
12
12
  attr_reader :subscribed
13
13
  attr_accessor :max_publish_retries, :max_publish_wait, :max_backlog_size,
14
14
  :max_global_backlog_size, :max_in_memory_publish_backlog
@@ -27,7 +27,7 @@ class MessageBus::ReliablePubSub
27
27
  # max_backlog_size is per multiplexed channel
28
28
  def initialize(redis_config = {}, max_backlog_size = 1000)
29
29
  @redis_config = redis_config
30
- @max_backlog_size = 1000
30
+ @max_backlog_size = max_backlog_size
31
31
  # we can store a lot of messages, since only one queue
32
32
  @max_global_backlog_size = 100000
33
33
  @max_publish_retries = 10
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "1.0.11"
2
+ VERSION = "1.0.12"
3
3
  end
@@ -29,6 +29,16 @@ describe MessageBus::Client do
29
29
  log[0].data.should == 'world'
30
30
  end
31
31
 
32
+ it "allows only client_id in list if message contains client_ids" do
33
+ @message = MessageBus::Message.new(1, 2, '/test', 'hello')
34
+ @message.client_ids = ["1","2"]
35
+ @client.client_id = "2"
36
+ @client.allowed?(@message).should == true
37
+
38
+ @client.client_id = "3"
39
+ @client.allowed?(@message).should == false
40
+ end
41
+
32
42
  context "targetted at group" do
33
43
  before do
34
44
  @message = MessageBus::Message.new(1,2,'/test', 'hello')
@@ -50,6 +60,7 @@ describe MessageBus::Client do
50
60
  @client.group_ids = [77,0,10]
51
61
  @client.allowed?(@message).should == true
52
62
  end
63
+
53
64
  end
54
65
  end
55
66
 
@@ -18,6 +18,21 @@ describe MessageBus do
18
18
  @bus.destroy
19
19
  end
20
20
 
21
+ it "can transmit client_ids" do
22
+ client_ids = nil
23
+
24
+ @bus.subscribe("/chuck") do |msg|
25
+ client_ids = msg.client_ids
26
+ end
27
+
28
+ @bus.publish("/chuck", {:yeager => true}, client_ids: ['a','b'])
29
+
30
+ wait_for(2000){ client_ids}
31
+
32
+ client_ids.should == ['a', 'b']
33
+
34
+ end
35
+
21
36
  it "should recover from a redis flush" do
22
37
 
23
38
  data = nil
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'message_bus'
3
3
 
4
- describe MessageBus::ReliablePubSub do
4
+ describe MessageBus::Redis::ReliablePubSub do
5
5
 
6
6
  def new_bus
7
- MessageBus::ReliablePubSub.new(:db => 10)
7
+ MessageBus::Redis::ReliablePubSub.new(:db => 10)
8
8
  end
9
9
 
10
10
  def work_it
@@ -31,7 +31,7 @@ describe MessageBus::ReliablePubSub do
31
31
  begin
32
32
  pids = (1..10).map{spawn_child}
33
33
  responses = []
34
- bus = MessageBus::ReliablePubSub.new(:db => 10)
34
+ bus = MessageBus::Redis::ReliablePubSub.new(:db => 10)
35
35
  Thread.new do
36
36
  bus.subscribe("/response", 0) do |msg|
37
37
  responses << msg if pids.include? msg.data.to_i
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'message_bus'
3
3
 
4
- describe MessageBus::ReliablePubSub do
4
+ describe MessageBus::Redis::ReliablePubSub do
5
5
 
6
6
  def new_test_bus
7
- MessageBus::ReliablePubSub.new(:db => 10)
7
+ MessageBus::Redis::ReliablePubSub.new(:db => 10)
8
8
  end
9
9
 
10
10
  before do
@@ -47,6 +47,10 @@ describe MessageBus::ReliablePubSub do
47
47
  ]
48
48
  end
49
49
 
50
+ it "should initialize with max_backlog_size" do
51
+ MessageBus::Redis::ReliablePubSub.new({},2000).max_backlog_size.should == 2000
52
+ end
53
+
50
54
  it "should truncate channels correctly" do
51
55
  @bus.max_backlog_size = 2
52
56
  4.times do |t|
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.11
4
+ version: 1.0.12
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-05-06 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -81,7 +81,7 @@ files:
81
81
  - lib/message_bus/rack/middleware.rb
82
82
  - lib/message_bus/rack/thin_ext.rb
83
83
  - lib/message_bus/rails/railtie.rb
84
- - lib/message_bus/reliable_pub_sub.rb
84
+ - lib/message_bus/redis/reliable_pub_sub.rb
85
85
  - lib/message_bus/timer_thread.rb
86
86
  - lib/message_bus/version.rb
87
87
  - message_bus.gemspec
@@ -94,7 +94,7 @@ files:
94
94
  - spec/lib/message_handler_spec.rb
95
95
  - spec/lib/middleware_spec.rb
96
96
  - spec/lib/multi_process_spec.rb
97
- - spec/lib/reliable_pub_sub_spec.rb
97
+ - spec/lib/redis/reliable_pub_sub_spec.rb
98
98
  - spec/lib/timer_thread_spec.rb
99
99
  - spec/spec_helper.rb
100
100
  - vendor/assets/javascripts/message-bus.js
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.2.2
121
+ rubygems_version: 2.4.5
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: ''
@@ -132,6 +132,6 @@ test_files:
132
132
  - spec/lib/message_handler_spec.rb
133
133
  - spec/lib/middleware_spec.rb
134
134
  - spec/lib/multi_process_spec.rb
135
- - spec/lib/reliable_pub_sub_spec.rb
135
+ - spec/lib/redis/reliable_pub_sub_spec.rb
136
136
  - spec/lib/timer_thread_spec.rb
137
137
  - spec/spec_helper.rb