mercury_amqp 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mercury/mercury.rb +30 -7
- data/lib/mercury/version.rb +1 -1
- data/spec/lib/mercury/monadic_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b38b3dede66b9e8be986f8b8f3fc480e62d326b6
|
4
|
+
data.tar.gz: 4b9b9dc78020adb4eefa32e0ec25b1e846088c41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de30e69c5f7d06a9579a28d38f5604038b0227ea0b380541c582107400139862bce47ab59c9be1cc6edd19a2d88533a29a3cb0ff8b26c607f67fe2337fbdc656
|
7
|
+
data.tar.gz: 79ecf41880b13bee8f514aeb9d3aaff18d4b17ad009fdbe336c20a0384ba002db06c99398b9861258f5aef34fe79fa8658d333310f6820f844e8cea6fe01a11a
|
data/lib/mercury/mercury.rb
CHANGED
@@ -25,12 +25,16 @@ class Mercury
|
|
25
25
|
username: 'guest',
|
26
26
|
password: 'guest',
|
27
27
|
parallelism: 1,
|
28
|
+
on_error: nil,
|
28
29
|
&k)
|
29
|
-
|
30
|
+
@on_error = on_error
|
31
|
+
AMQP.connect(host: host, port: port, vhost: vhost, username: username, password: password,
|
32
|
+
on_tcp_connection_failure: server_down_error_handler) do |amqp|
|
30
33
|
@amqp = amqp
|
31
34
|
@channel = AMQP::Channel.new(amqp, prefetch: parallelism) do
|
32
35
|
@channel.confirm_select
|
33
|
-
|
36
|
+
install_channel_error_handler
|
37
|
+
install_lost_connection_error_handler
|
34
38
|
k.call(self)
|
35
39
|
end
|
36
40
|
end
|
@@ -122,7 +126,7 @@ class Mercury
|
|
122
126
|
k.call(false)
|
123
127
|
else
|
124
128
|
# failed for unknown reason
|
125
|
-
|
129
|
+
handle_channel_error(ch, info)
|
126
130
|
end
|
127
131
|
end
|
128
132
|
check.call(ch) do |result|
|
@@ -133,13 +137,32 @@ class Mercury
|
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
136
|
-
def
|
137
|
-
|
140
|
+
def server_down_error_handler
|
141
|
+
make_error_handler('Failed to establish connection to AMQP server. Exiting.')
|
138
142
|
end
|
139
143
|
|
140
|
-
def
|
144
|
+
def install_lost_connection_error_handler
|
145
|
+
@amqp.on_tcp_connection_loss(&make_error_handler('Lost connection to AMQP server. Exiting.'))
|
146
|
+
end
|
147
|
+
|
148
|
+
def install_channel_error_handler
|
149
|
+
@channel.on_error(&method(:handle_channel_error))
|
150
|
+
end
|
151
|
+
|
152
|
+
def handle_channel_error(_ch, info)
|
141
153
|
@amqp.close do
|
142
|
-
|
154
|
+
make_error_handler("An error occurred: #{info.reply_code} - #{info.reply_text}").call
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def make_error_handler(msg)
|
159
|
+
proc do
|
160
|
+
Logatron.error(msg)
|
161
|
+
if @on_error.respond_to?(:call)
|
162
|
+
@on_error.call(msg)
|
163
|
+
else
|
164
|
+
raise msg
|
165
|
+
end
|
143
166
|
end
|
144
167
|
end
|
145
168
|
|
data/lib/mercury/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercury_amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Winton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|