liebre 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea30bec0897de16f0f5c622dfc40dd4918e10a4
4
- data.tar.gz: 129b44949789081686fd1331701bca94c1a498b5
3
+ metadata.gz: 8735a3d7c701e1d809f2d5e37008a989d1ace4e1
4
+ data.tar.gz: c0ecff68630874551934f13d5eb5f64bff928543
5
5
  SHA512:
6
- metadata.gz: fb2469f49b0b8583ce5b73fb20c6396b4791d395d2ad2dfc7f8d9486d8bc675a7dc2b666fe16cd5950d709bc05cf7cc1f0d9da24b6fe2eced3ef92ad71227d4d
7
- data.tar.gz: ec76d7163561e469037e61b12ab3f2c35968fec5217b756119729e51981692fe7dc691a2d80f0c7e4d0ab1da6f5c5d3668936226cd315e7644ec7b087b4588ae
6
+ metadata.gz: f799aa599bb0ef36f6364aaa2618a4ff3818310c29c4e6a749c42280a08e982336bed3e4663fd6bd807f897c7b29feb060c54f88c2635a24a2b66b1f50e24712
7
+ data.tar.gz: 06d1105f5c4bd235d56ca6ff97aad3116501f50992e3c20337eb331e1a478af7ef3657b0c0a5a1d731071800372b397f65b9e814af524d98e0723bc92e37eeb1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- liebre (0.1.2)
4
+ liebre (0.1.3)
5
5
  bunny (~> 2.5, >= 2.5.1)
6
6
 
7
7
  GEM
@@ -7,6 +7,7 @@ module Liebre
7
7
 
8
8
  def enqueue message, options = {}
9
9
  with_connection do
10
+ logger.debug "Liebre: Publishing '#{message}' with '#{options}' to exchange: #{exchange}"
10
11
  exchange.publish message, options
11
12
  end
12
13
  end
@@ -14,18 +15,21 @@ module Liebre
14
15
  def enqueue_and_wait message, options = {}
15
16
  result = nil
16
17
  with_connection do
18
+ correlation_id = options[:correlation_id] ||= generate_uuid
19
+ reply_queue = reply_queue correlation_id
20
+ options[:reply_to] = reply_queue.name
21
+ reply_queue.subscribe(:block => false) do |delivery_info, meta, payload|
22
+ if meta[:correlation_id] == correlation_id
23
+ result = payload
24
+ logger.debug "Liebre: Received response '#{result}'"
25
+ channel.consumers[delivery_info.consumer_tag].cancel
26
+ end
27
+ end
28
+ logger.debug "Liebre: Publishing '#{message}' with '#{options}' to exchange: #{exchange}"
29
+ exchange.publish message, options
17
30
  begin
18
- correlation_id = options[:correlation_id] ||= generate_uuid
19
- reply_queue = reply_queue correlation_id
20
- options[:reply_to] = reply_queue.name
21
- exchange.publish message, options
22
- Timeout::timeout(Liebre.config.rpc_request_timeout) do
23
- reply_queue.subscribe(:block => true) do |delivery_info, meta, payload|
24
- if meta[:correlation_id] == correlation_id
25
- result = payload
26
- channel.consumers[delivery_info.consumer_tag].cancel
27
- end
28
- end
31
+ Timeout.timeout(Liebre.config.rpc_request_timeout) do
32
+ sleep 0.01 while result.nil?
29
33
  end
30
34
  rescue Timeout::Error
31
35
  #do nothing
@@ -51,7 +55,7 @@ module Liebre
51
55
  end
52
56
 
53
57
  def exchange
54
- Liebre::Common::Utils.create_exchange channel, exchange_config
58
+ @exchange ||= Liebre::Common::Utils.create_exchange channel, exchange_config
55
59
  end
56
60
 
57
61
  def channel
@@ -81,6 +85,10 @@ module Liebre
81
85
  def generate_uuid
82
86
  SecureRandom.uuid
83
87
  end
88
+
89
+ def logger
90
+ Liebre::Config.logger
91
+ end
84
92
 
85
93
  attr_reader :publisher_name
86
94
 
@@ -19,15 +19,18 @@ module Liebre
19
19
 
20
20
  def initialize_queue
21
21
  queue.subscribe(:manual_ack => true) do |info, meta, payload|
22
+ response = :reject
22
23
  begin
23
- logger.debug "Received message for #{klass.name}: #{payload} - #{meta}"
24
+ logger.debug "Liebre: Received message for #{klass.name}: #{payload} - #{meta}"
24
25
  consumer = klass.new(payload, meta)
25
26
  response = consumer.call
26
- handler.respond response, info
27
27
  rescue => e
28
+ response = :error
28
29
  logger.error e.inspect
29
30
  logger.error e.backtrace.join("\n")
30
- handler.respond :error, info
31
+ ensure
32
+ logger.debug "Liebre: Responding with #{response}"
33
+ handler.respond response, info
31
34
  end
32
35
  end
33
36
  end
@@ -71,7 +74,6 @@ module Liebre
71
74
  result = clone_hash config
72
75
  result['exchange']['name'] += "-error"
73
76
  result['queue']['name'] += "-error"
74
- result['queue']['opts']['exclusive'] = true
75
77
  result
76
78
  end
77
79
 
@@ -6,7 +6,7 @@ module Liebre
6
6
  def call
7
7
  queue.subscribe(:manual_ack => false) do |_info, meta, payload|
8
8
  begin
9
- logger.debug "Received message for #{klass.name}: #{payload} - #{meta}"
9
+ logger.debug "Liebre: Received message for #{klass.name}: #{payload} - #{meta}"
10
10
  consumer = klass.new(payload, meta, callback(meta))
11
11
  consumer.call
12
12
  rescue => e
@@ -26,7 +26,7 @@ module Liebre
26
26
  }
27
27
 
28
28
  lambda do |response|
29
- logger.debug "Responding with #{response}"
29
+ logger.debug "Liebre: Responding with #{response}"
30
30
  exchange.publish(response, opts)
31
31
  end
32
32
  end
data/lib/liebre/runner.rb CHANGED
@@ -28,9 +28,9 @@ module Liebre
28
28
 
29
29
  def do_shutdown
30
30
  Thread.start do
31
- logger.info("Closing AMQP connection...")
31
+ logger.info("Liebre: Closing AMQP connection...")
32
32
  conn_manager.stop
33
- logger.info("AMQP connection closed")
33
+ logger.info("Liebre: AMQP connection closed")
34
34
  end.join
35
35
  end
36
36
 
@@ -42,7 +42,7 @@ module Liebre
42
42
  def log_and_wait e
43
43
  logger.warn(e)
44
44
  sleep(retry_interval)
45
- logger.warn("Retrying connection")
45
+ logger.warn("Liebre: Retrying connection")
46
46
  end
47
47
 
48
48
  def logger
@@ -1,5 +1,5 @@
1
1
  module Liebre
2
2
 
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
 
5
5
  end
@@ -69,7 +69,7 @@ RSpec.describe Liebre::Publisher do
69
69
  expect(exchange).to receive(:publish).with message,
70
70
  {:correlation_id => correlation_id, :reply_to => reply_queue_name}
71
71
 
72
- expect(reply_queue).to receive(:subscribe).with(:block => true) do |&block|
72
+ expect(reply_queue).to receive(:subscribe).with(:block => false) do |&block|
73
73
  expect(channel).to receive(:consumers).and_return consumers
74
74
  expect(consumer).to receive(:cancel)
75
75
 
@@ -43,8 +43,7 @@ RSpec.describe Liebre::Runner::Starter::Consumer do
43
43
  "queue" => {
44
44
  "name" => "test_queue-error",
45
45
  "opts" => {
46
- "durable" => true,
47
- "exclusive" => true
46
+ "durable" => true
48
47
  }
49
48
  }
50
49
  }
@@ -47,14 +47,16 @@ RSpec.describe Liebre::Runner::Starter::RPC do
47
47
 
48
48
  let(:reply_to) { "queue_to_reply_to" }
49
49
  let(:correlation_id) { 123 }
50
+ let(:headers) { {} }
50
51
  let :meta do
51
52
  double 'meta',
52
53
  :reply_to => reply_to,
53
- :correlation_id => correlation_id
54
+ :correlation_id => correlation_id,
55
+ :headers => headers
54
56
  end
55
57
 
56
58
  let :opts do
57
- {:routing_key => reply_to, :correlation_id => correlation_id}
59
+ {:routing_key => reply_to, :correlation_id => correlation_id, :headers => headers}
58
60
  end
59
61
 
60
62
  let(:handler) { double 'handler' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liebre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jcabotc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-12 00:00:00.000000000 Z
12
+ date: 2016-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny