bunny_burrow 1.5.2 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bunny_burrow/client.rb +29 -19
- data/lib/bunny_burrow/version.rb +1 -1
- 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: 673a05f44f658570ba0b421d5e4592e4a6d8da47
|
4
|
+
data.tar.gz: aaa51e1e5a7c94e35e6812330092909fed493e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63c9fcb9eef80edb283b5be5a4b36f5e458276253b7a559da917864ebacda8de109a2f2e5b1196f0bb375e33384cdf988e37c4563160193ab70ce070488668f5
|
7
|
+
data.tar.gz: 542907ae1679ceee6196028f9c49fff90def448f76eaa368a8fb0babfc4b9fd1f5450e319640f79300cacb88f013f63a759a9a5f4a4e6ead1d021c406b708830
|
data/lib/bunny_burrow/client.rb
CHANGED
@@ -1,44 +1,54 @@
|
|
1
1
|
require_relative 'base'
|
2
|
+
require 'securerandom'
|
2
3
|
|
3
4
|
module BunnyBurrow
|
4
5
|
class Client < Base
|
6
|
+
|
7
|
+
DIRECT_REPLY_TO = 'amq.rabbitmq.reply-to'
|
8
|
+
|
9
|
+
|
5
10
|
def publish(payload, routing_key)
|
6
11
|
result = nil
|
7
12
|
|
8
|
-
# when creating a queue, a blank name indicates we want the AMPQ broker
|
9
|
-
# to generate a unique name for us. Also note that this queue will be on
|
10
|
-
# the default exchange
|
11
|
-
reply_to = channel.queue('', exclusive: true, auto_delete: true)
|
12
|
-
|
13
13
|
details = {
|
14
14
|
routing_key: routing_key,
|
15
|
-
reply_to:
|
15
|
+
reply_to: DIRECT_REPLY_TO
|
16
16
|
}
|
17
|
+
|
17
18
|
details[:request] = payload if log_request?
|
18
19
|
log "Publishing #{details}"
|
19
20
|
|
20
21
|
options = {
|
21
22
|
routing_key: routing_key,
|
22
|
-
reply_to:
|
23
|
+
reply_to: DIRECT_REPLY_TO,
|
23
24
|
persistence: false
|
24
25
|
}
|
25
26
|
|
26
|
-
|
27
|
+
consumer = Bunny::Consumer.new(channel, DIRECT_REPLY_TO, SecureRandom.uuid)
|
28
|
+
consumer.on_delivery do |_, _, received_payload|
|
29
|
+
result = handle_delivery(details, received_payload)
|
30
|
+
end
|
27
31
|
|
28
|
-
Timeout.timeout(timeout) do
|
29
|
-
reply_to.subscribe do |_, _, payload|
|
30
|
-
details[:response] = payload if log_response?
|
31
|
-
log "Receiving #{details}"
|
32
|
-
result = payload
|
33
|
-
lock.synchronize { condition.signal }
|
34
|
-
end
|
35
32
|
|
36
|
-
|
33
|
+
begin
|
34
|
+
channel.basic_consume_with consumer
|
35
|
+
topic_exchange.publish(payload.to_json, options)
|
36
|
+
|
37
|
+
Timeout.timeout(timeout) do
|
38
|
+
lock.synchronize {condition.wait(lock)}
|
39
|
+
end
|
40
|
+
ensure
|
41
|
+
consumer.cancel
|
37
42
|
end
|
43
|
+
result
|
44
|
+
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
def handle_delivery(details, payload)
|
47
|
+
details[:response] = payload if log_response?
|
48
|
+
log "Receiving #{details}"
|
49
|
+
result = payload
|
50
|
+
lock.synchronize {condition.signal}
|
51
|
+
result
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
data/lib/bunny_burrow/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny_burrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vericity
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|