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 +4 -4
- data/lib/msgr/binding.rb +40 -0
- data/lib/msgr/client.rb +7 -6
- data/lib/msgr/connection.rb +16 -23
- data/lib/msgr/version.rb +1 -1
- data/lib/msgr.rb +1 -0
- data/spec/msgr/msgr_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 734c3680e24335ea471f3fc2446b461fbfa00efc
|
4
|
+
data.tar.gz: facaa4877340b7882f85982e47505ee8183f7df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cbce31c84a705f41af34a421cf24a0fed7c66adf5274d6ead1c8b776600a5378a4f55260b9a6c60f770c136c9fc4409a741dd6143cea8034df559e72ac58fd4
|
7
|
+
data.tar.gz: fb789cb58f7330d7fb0e45483d32ff83a80240b15912d027e82b558087dbf7763c38ce27dcfc1a0d98b720aaae44883c4f5ff98c4d0d9e3b50b26d41d8b3b4a2
|
data/lib/msgr/binding.rb
ADDED
@@ -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
|
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
|
123
|
-
@pool
|
124
|
-
@channel
|
125
|
-
@
|
123
|
+
@connection = nil
|
124
|
+
@pool = nil
|
125
|
+
@channel = nil
|
126
|
+
@bindings = nil
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
data/lib/msgr/connection.rb
CHANGED
@@ -17,7 +17,7 @@ module Msgr
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def running?
|
20
|
-
|
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
|
-
|
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
|
53
|
-
|
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
|
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
data/lib/msgr.rb
CHANGED
data/spec/msgr/msgr_spec.rb
CHANGED
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.
|
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-
|
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
|