vx-common-amqp 0.3.2 → 0.3.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 +4 -4
- data/lib/vx/common/amqp/config.rb +4 -4
- data/lib/vx/common/amqp/consumer.rb +1 -2
- data/lib/vx/common/amqp/consumer/ack.rb +2 -4
- data/lib/vx/common/amqp/consumer/publish.rb +5 -2
- data/lib/vx/common/amqp/consumer/subscribe.rb +14 -11
- data/lib/vx/common/amqp/mixins/instrument.rb +13 -1
- data/lib/vx/common/amqp/session.rb +9 -3
- data/lib/vx/common/amqp/supervisor/threaded.rb +4 -8
- data/lib/vx/common/amqp/version.rb +1 -1
- data/spec/integration/threaded_supervisor_spec.rb +1 -0
- data/spec/spec_helper.rb +5 -1
- data/vx-common-amqp.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78c7ba1237547a68870877cf97e753e060e409a8
|
4
|
+
data.tar.gz: b176e9a6819bca67fc9244da4fec6186ef6ca94e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b71ffdcc44ec306ba4fdde80ae3f76df4cc708429a89651a7c7508f7dfb9439ea6280c426cc612a88dee7a04bd07e78ee0b69e1ec55c62b87c46deef5095816
|
7
|
+
data.tar.gz: f3f3d0af052ef31fc59c39c12ee69453a5676c961c82814074fa8bd966d6c19dd50017a3e9c07c31ae586529d0a82ec277afa25648fee5f1b1b090662c6977c6
|
@@ -6,9 +6,9 @@ module Vx
|
|
6
6
|
module AMQP
|
7
7
|
class Config
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :default_exchange_options, :default_queue_options,
|
10
10
|
:default_publish_options, :default_exchange_type, :logger, :pool_timeout,
|
11
|
-
:heartbeat, :spawn_attempts, :content_type, :instrumenter, :debug
|
11
|
+
:heartbeat, :spawn_attempts, :content_type, :instrumenter, :debug, :on_error
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
reset!
|
@@ -27,7 +27,6 @@ module Vx
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def reset!
|
30
|
-
@url = nil
|
31
30
|
@logger = ::Logger.new(STDOUT)
|
32
31
|
@default_exchange_type = :topic
|
33
32
|
@pool_timeout = 0.1
|
@@ -37,12 +36,13 @@ module Vx
|
|
37
36
|
@recieving_builder = nil
|
38
37
|
@subscribing_builder = nil
|
39
38
|
|
40
|
-
@spawn_attempts =
|
39
|
+
@spawn_attempts = 1
|
41
40
|
|
42
41
|
@content_type = 'application/json'
|
43
42
|
|
44
43
|
@callbacks = {}
|
45
44
|
@instrumenter = nil
|
45
|
+
@on_error = ->(e, env){ nil }
|
46
46
|
|
47
47
|
@default_exchange_options = {
|
48
48
|
durable: true,
|
@@ -7,9 +7,8 @@ module Vx
|
|
7
7
|
instrumentation = {
|
8
8
|
consumer_id: self.class.consumer_id,
|
9
9
|
consumer: self.class.consumer_name,
|
10
|
+
message_id: properties[:message_id],
|
10
11
|
multiple: multiple,
|
11
|
-
payload: payload,
|
12
|
-
uuid: uuid,
|
13
12
|
}
|
14
13
|
self.class.session.channel.ack delivery_info.delivery_tag, multiple
|
15
14
|
instrument("ack.consumer.amqp", instrumentation)
|
@@ -19,10 +18,9 @@ module Vx
|
|
19
18
|
instrumentation = {
|
20
19
|
consumer_id: self.class.consumer_id,
|
21
20
|
consumer: self.class.consumer_name,
|
22
|
-
|
21
|
+
message_id: properties[:message_id],
|
23
22
|
multiple: multiple,
|
24
23
|
requeue: requeue,
|
25
|
-
uuid: uuid,
|
26
24
|
}
|
27
25
|
self.class.session.channel.ack delivery_info.delivery_tag, multiple, requeue
|
28
26
|
instrument("nack.consumer.amqp", instrumentation)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module Vx
|
2
4
|
module Common
|
3
5
|
module AMQP
|
@@ -10,6 +12,7 @@ module Vx
|
|
10
12
|
options[:routing_key] = routing_key if routing_key && !options.key?(:routing_key)
|
11
13
|
options[:headers] = headers if headers && !options.key?(:headers)
|
12
14
|
options[:content_type] ||= content_type || config.content_type
|
15
|
+
options[:message_id] ||= SecureRandom.uuid
|
13
16
|
|
14
17
|
x = declare_exchange
|
15
18
|
|
@@ -17,10 +20,10 @@ module Vx
|
|
17
20
|
payload: message,
|
18
21
|
exchange: x.name,
|
19
22
|
consumer: consumer_name,
|
20
|
-
consumer_id: consumer_id
|
23
|
+
consumer_id: consumer_id,
|
24
|
+
message_id: options[:message_id]
|
21
25
|
}
|
22
26
|
|
23
|
-
instrument("start_publishing.consumer.amqp", instrumentation)
|
24
27
|
instrument("process_publishing.consumer.amqp", instrumentation) do
|
25
28
|
m = serialize_message message, options[:content_type]
|
26
29
|
x.publish m, options
|
@@ -13,17 +13,19 @@ module Vx
|
|
13
13
|
|
14
14
|
def start
|
15
15
|
rs = nil
|
16
|
-
|
16
|
+
instrumentation = {
|
17
|
+
consumer_id: consumer_id,
|
18
|
+
consumer: consumer_name
|
19
|
+
}
|
20
|
+
session.open instrumentation
|
17
21
|
session.with_channel do
|
18
22
|
x = declare_exchange
|
19
23
|
q = declare_queue
|
20
24
|
|
21
|
-
instrumentation
|
25
|
+
instrumentation.merge!(
|
22
26
|
exchange: x.name,
|
23
27
|
queue: q.name,
|
24
|
-
|
25
|
-
consumer: consumer_name
|
26
|
-
}
|
28
|
+
)
|
27
29
|
instrument("start.consumer.amqp", instrumentation)
|
28
30
|
|
29
31
|
q.bind(x, bind_options)
|
@@ -62,12 +64,14 @@ module Vx
|
|
62
64
|
consumer_id: consumer_id,
|
63
65
|
consumer: consumer_name,
|
64
66
|
payload: payload,
|
65
|
-
|
67
|
+
message_id: properties[:message_id]
|
66
68
|
}
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
Instrument.with request_id: uuid do
|
71
|
+
instrument("start_processing.consumer.amqp", instrumentation)
|
72
|
+
instrument("process.consumer.amqp", instrumentation) do
|
73
|
+
result = run_instance delivery_info, properties, payload, uuid
|
74
|
+
end
|
71
75
|
end
|
72
76
|
|
73
77
|
break if result == :shutdown
|
@@ -81,8 +85,7 @@ module Vx
|
|
81
85
|
new.tap do |inst|
|
82
86
|
inst.properties = properties
|
83
87
|
inst.delivery_info = delivery_info
|
84
|
-
inst.
|
85
|
-
inst.payload = payload
|
88
|
+
inst.request_id = uuid
|
86
89
|
end.perform payload
|
87
90
|
end
|
88
91
|
|
@@ -3,8 +3,20 @@ module Vx
|
|
3
3
|
module AMQP
|
4
4
|
module Instrument
|
5
5
|
|
6
|
+
def self.with(new_params)
|
7
|
+
old_params = Thread.current["vx_common_amqp_instrument_with"]
|
8
|
+
begin
|
9
|
+
Thread.current["vx_common_amqp_instrument_with"] = new_params
|
10
|
+
yield if block_given?
|
11
|
+
ensure
|
12
|
+
Thread.current["vx_common_amqp_instrument_with"] = old_params
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
def instrument(name, payload, &block)
|
7
|
-
|
17
|
+
append = Thread.current["vx_common_amqp_instrument_with"]
|
18
|
+
append ||= {}
|
19
|
+
Common::AMQP.instrument name, payload.merge(append), &block
|
8
20
|
end
|
9
21
|
|
10
22
|
end
|
@@ -44,16 +44,22 @@ module Vx
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def open
|
47
|
+
def open(options = {})
|
48
48
|
return self if open?
|
49
49
|
|
50
50
|
@@session_lock.synchronize do
|
51
51
|
self.class.resume
|
52
52
|
|
53
|
-
@conn ||= Bunny.new
|
53
|
+
@conn ||= Bunny.new(
|
54
|
+
nil, # from ENV['RABBITMQ_URL']
|
55
|
+
heartbeat: :server,
|
56
|
+
automatically_recover: false
|
57
|
+
)
|
54
58
|
|
55
59
|
instrumentation = {
|
56
|
-
info:
|
60
|
+
info: conn_info,
|
61
|
+
consumer: options[:consumer],
|
62
|
+
consumer_id: options[:consumer_id]
|
57
63
|
}
|
58
64
|
|
59
65
|
instrument("start_connecting.consumer.amqp", instrumentation)
|
@@ -135,7 +135,7 @@ module Vx
|
|
135
135
|
new_task.attempt = attempt
|
136
136
|
new_task.start_at = Time.now
|
137
137
|
new_task.freeze
|
138
|
-
instrument("
|
138
|
+
instrument("spawn_thread.consumer.ampq", task: new_task.inspect)
|
139
139
|
new_task
|
140
140
|
end
|
141
141
|
end
|
@@ -147,14 +147,10 @@ module Vx
|
|
147
147
|
task.thread.value
|
148
148
|
nil
|
149
149
|
rescue Exception => e
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
instrument("exception.consumer.amqp", payload: {
|
154
|
-
exception: e,
|
155
|
-
task: task.inspect
|
156
|
-
})
|
150
|
+
$stderr.puts "#{e.inspect} in #{task.inspect}"
|
151
|
+
$stderr.puts e.backtrace.map{|b| " #{b}" }.join("\n")
|
157
152
|
|
153
|
+
Common::AMQP.config.on_error.call(e, task: task)
|
158
154
|
e
|
159
155
|
end
|
160
156
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,13 +2,17 @@ require File.expand_path '../../lib/vx/common/amqp', __FILE__
|
|
2
2
|
|
3
3
|
require 'rspec/autorun'
|
4
4
|
|
5
|
-
ENV['VX_COMMON_AMQP_DEBUG'] = "1"
|
5
|
+
#ENV['VX_COMMON_AMQP_DEBUG'] = "1"
|
6
6
|
|
7
7
|
Dir[File.expand_path("../..", __FILE__) + "/spec/support/**.rb"].each {|f| require f}
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.mock_with :rr
|
11
11
|
|
12
|
+
config.before(:each) do
|
13
|
+
Vx::Common::AMQP.config.reset!
|
14
|
+
end
|
15
|
+
|
12
16
|
config.after(:suite) do
|
13
17
|
Vx::Common::AMQP.close
|
14
18
|
end
|
data/vx-common-amqp.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 1.9.3'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "bunny", "~> 1.1.
|
23
|
+
spec.add_runtime_dependency "bunny", "~> 1.1.1"
|
24
24
|
spec.add_runtime_dependency "vx-common-rack-builder", "~> 0.0.2"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.3"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vx-common-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01
|
11
|
+
date: 2014-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1.
|
19
|
+
version: 1.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.1.
|
26
|
+
version: 1.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: vx-common-rack-builder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|