msgr 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d7147b5f93af8abbb88769c9bc5ad79e6aaccce
4
- data.tar.gz: 51d0238c5a3f1da6c31727096f696741f2ed86cf
3
+ metadata.gz: 734c3680e24335ea471f3fc2446b461fbfa00efc
4
+ data.tar.gz: facaa4877340b7882f85982e47505ee8183f7df0
5
5
  SHA512:
6
- metadata.gz: e4a0de140ab0c7195f422add2998dfdaef6c089acdcde696a7e10e9b0cd5d08203b0d5adc5ff4ddfeb71ae5d981f0a2f9eb6b0ec91098b57e142217027731493
7
- data.tar.gz: 7b1be5091653909b0fd4ea7bd2f22aa85c926b82ab796ed1e4cc30a3f2ba358e7df1202e5265aad421fd92d4a9a2c34c09e945ae778b372eb946bc564e64f584
6
+ metadata.gz: 2cbce31c84a705f41af34a421cf24a0fed7c66adf5274d6ead1c8b776600a5378a4f55260b9a6c60f770c136c9fc4409a741dd6143cea8034df559e72ac58fd4
7
+ data.tar.gz: fb789cb58f7330d7fb0e45483d32ff83a80240b15912d027e82b558087dbf7763c38ce27dcfc1a0d98b720aaae44883c4f5ff98c4d0d9e3b50b26d41d8b3b4a2
@@ -0,0 +1,40 @@
1
+ module Msgr
2
+
3
+ class Binding
4
+ include Logging
5
+
6
+ attr_reader :queue, :subscription, :connection, :route, :dispatcher
7
+
8
+ def initialize(connection, route, dispatcher)
9
+ @connection = connection
10
+ @route = route
11
+ @dispatcher = dispatcher
12
+ @queue = connection.queue(route.name)
13
+
14
+ route.keys.each do |key|
15
+ log(:debug) { "Bind #{key} to #{queue.name}." }
16
+
17
+ queue.bind connection.exchange, routing_key: key
18
+ end
19
+
20
+ @subscription = queue.subscribe(ack: true) do |*args|
21
+ begin
22
+ dispatcher.call Message.new(self, *args, route)
23
+ rescue => err
24
+ log(:error) do
25
+ "Rescued error from subscribe: #{err.class.name}: #{err}\n#{err.backtrace.join("\n")}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def release
32
+ subscription.cancel
33
+ end
34
+
35
+ def delete
36
+ release
37
+ queue.delete
38
+ end
39
+ end
40
+ end
data/lib/msgr/client.rb CHANGED
@@ -15,7 +15,7 @@ module Msgr
15
15
  @uri.path = config[:vhost] ||= @uri.path.present? ? @uri.path : '/'
16
16
  config.reject! { |_, v| v.nil? }
17
17
 
18
- @config = config
18
+ @config = config
19
19
  @config[:max] ||= 2
20
20
 
21
21
  @mutex = ::Mutex.new
@@ -56,13 +56,14 @@ module Msgr
56
56
  end
57
57
  end
58
58
 
59
- def stop
59
+ def stop(opts = {})
60
60
  mutex.synchronize do
61
61
  check_process!
62
62
 
63
63
  log(:info) { "Stop on #{uri}..." }
64
64
 
65
65
  connection.release
66
+ connection.delete if opts[:delete]
66
67
  connection.close
67
68
  dispatcher.shutdown
68
69
 
@@ -119,10 +120,10 @@ module Msgr
119
120
  end
120
121
 
121
122
  def reset
122
- @connection = nil
123
- @pool = nil
124
- @channel = nil
125
- @subscriptions = nil
123
+ @connection = nil
124
+ @pool = nil
125
+ @channel = nil
126
+ @bindings = nil
126
127
  end
127
128
  end
128
129
  end
@@ -17,7 +17,7 @@ module Msgr
17
17
  end
18
18
 
19
19
  def running?
20
- subscriptions.any?
20
+ bindings.any?
21
21
  end
22
22
 
23
23
  def publish(payload, opts = {})
@@ -46,11 +46,22 @@ module Msgr
46
46
  end
47
47
 
48
48
  def release
49
- subscriptions.each { |subscription| subscription.cancel }
49
+ return if bindings.empty?
50
+ log(:debug) { "Release bindings (#{bindings.size})..." }
51
+
52
+ bindings.each { |binding| binding.release }
50
53
  end
51
54
 
52
- def subscriptions
53
- @subscription ||= []
55
+ def delete
56
+ return if bindings.empty?
57
+ log(:debug) { "Delete bindings (#{bindings.size})..." }
58
+
59
+ bindings.each { |binding| binding.delete }
60
+ exchange.delete
61
+ end
62
+
63
+ def bindings
64
+ @bindings ||= []
54
65
  end
55
66
 
56
67
  def prefix(name)
@@ -105,25 +116,7 @@ module Msgr
105
116
 
106
117
  private
107
118
  def bind_all(routes)
108
- routes.each do |route|
109
- queue = queue(route.name)
110
-
111
- route.keys.each do |key|
112
- log(:debug) { "Bind #{key} to #{queue.name}." }
113
-
114
- queue.bind exchange, routing_key: key
115
- end
116
-
117
- subscriptions << queue.subscribe(ack: true) do |*args|
118
- begin
119
- @dispatcher.call Message.new(self, *args, route)
120
- rescue => err
121
- log(:error) do
122
- "Rescued error from subscribe: #{err.class.name}: #{err}\n#{err.backtrace.join("\n")}"
123
- end
124
- end
125
- end
126
- end
119
+ routes.each { |route| bindings << Binding.new(self, route, @dispatcher) }
127
120
  end
128
121
  end
129
122
  end
data/lib/msgr/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Msgr
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 9
4
+ MINOR = 10
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
data/lib/msgr.rb CHANGED
@@ -8,6 +8,7 @@ require 'active_support/core_ext/hash/keys'
8
8
 
9
9
  require 'msgr/logging'
10
10
  require 'msgr/client'
11
+ require 'msgr/binding'
11
12
  require 'msgr/connection'
12
13
  require 'msgr/consumer'
13
14
  require 'msgr/dispatcher'
@@ -23,7 +23,7 @@ describe Msgr do
23
23
  end
24
24
 
25
25
  after do
26
- client.stop
26
+ client.stop delete: true
27
27
  end
28
28
 
29
29
  it 'should dispatch published methods to consumer' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -98,6 +98,7 @@ files:
98
98
  - gemfiles/Gemfile.rails-3-2
99
99
  - gemfiles/Gemfile.rails-4-0
100
100
  - lib/msgr.rb
101
+ - lib/msgr/binding.rb
101
102
  - lib/msgr/client.rb
102
103
  - lib/msgr/connection.rb
103
104
  - lib/msgr/consumer.rb