vx-lib-consumer 0.2.2 → 0.3.0

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: e19e0cdf508eeb00ef09591c6846ad6e59fd903e
4
- data.tar.gz: f4face1e09a11cf6239727c256d8b1100f14893c
3
+ metadata.gz: 6608092d8377c6b8f5a270f962489a5b334db63e
4
+ data.tar.gz: cb6ded459721df23d54fd4291c2ab9d46c0fd3d8
5
5
  SHA512:
6
- metadata.gz: 7d4830e292303a83ef069c233c7fd31c6f72b92ee15a5aee62ee7ae28449e47d2cf8dc4eb7a7e880491d93e30d8b6c153b3b54e24ac4016e062d8741d0d518bb
7
- data.tar.gz: 41212e084f4d4f57a2fafccb1c1cf1583bded3581cf3e86940839ad0e73f1dbe3cd2c2636d8e8d95f80014e4b9949e63bb6d865914a5ea4d1b3d9639b9e7bc8b
6
+ metadata.gz: 6b25277ae9e0d282e9792acbd81b8d5f5a4a68bf0d0eb257b87394edeaf99d5a9b3d9414c5e605a0e50026a8fff6cc557ed8ebe410adfd47f06845dbb2f87acf
7
+ data.tar.gz: b5bb94f0eeb0800d44f5cdfdfb746f0027f41eccbf9c27544468f308f2899e658f6d4cff1db949f6d8a79b122b286ac0ac2ab703d0cb6ee1ae7f7d861e89781f
@@ -2,7 +2,6 @@
2
2
  version
3
3
  error
4
4
  configuration
5
- instrument
6
5
  session
7
6
  params
8
7
  serializer
@@ -25,12 +24,10 @@ module Vx
25
24
 
26
25
  def self.included(base)
27
26
  base.extend ClassMethods
28
- base.extend Instrument
29
27
  base.extend Publish
30
28
  base.extend Subscribe
31
29
  base.extend Rpc
32
30
  base.send :include, Ack
33
- base.send :include, Instrument
34
31
  end
35
32
 
36
33
  module ClassMethods
@@ -4,36 +4,19 @@ module Vx
4
4
  module Ack
5
5
 
6
6
  def ack(multiple = false)
7
- instrumentation = {
8
- consumer: self.class.params.consumer_name,
9
- properties: properties,
10
- multiple: multiple,
11
- channel: _channel.id
12
- }
13
7
  if _channel.open?
14
8
  _channel.ack delivery_info.delivery_tag, multiple
15
- instrument("ack", instrumentation)
16
9
  true
17
10
  else
18
- instrument("ack_failed", instrumentation)
19
11
  false
20
12
  end
21
13
  end
22
14
 
23
15
  def nack(multiple = false, requeue = false)
24
- instrumentation = {
25
- consumer: self.class.params.consumer_name,
26
- properties: properties,
27
- multiple: multiple,
28
- requeue: requeue,
29
- channel: channel.id
30
- }
31
16
  if _channel.open?
32
17
  _channel.ack delivery_info.delivery_tag, multiple, requeue
33
- instrument("nack", instrumentation)
34
18
  true
35
19
  else
36
- instrument("nack_failed", instrumentation)
37
20
  false
38
21
  end
39
22
  end
@@ -10,7 +10,7 @@ module Vx
10
10
 
11
11
  attr_accessor :default_exchange_options, :default_queue_options,
12
12
  :default_publish_options, :default_exchange_type, :pool_timeout,
13
- :heartbeat, :spawn_attempts, :content_type, :instrumenter, :debug,
13
+ :heartbeat, :spawn_attempts, :content_type, :debug,
14
14
  :on_error, :builders, :prefetch
15
15
 
16
16
  def initialize
@@ -40,7 +40,6 @@ module Vx
40
40
  @content_type = 'application/json'
41
41
  @prefetch = 1
42
42
 
43
- @instrumenter = nil
44
43
  @on_error = ->(e, env){ nil }
45
44
 
46
45
  @builders = {
@@ -17,20 +17,18 @@ module Vx
17
17
 
18
18
  name = params.exchange_name
19
19
 
20
- instrumentation = {
20
+ env = {
21
21
  payload: payload,
22
22
  exchange: name,
23
23
  consumer: params.consumer_name,
24
24
  properties: options,
25
25
  }
26
26
 
27
- with_middlewares :pub, instrumentation do
27
+ with_middlewares :pub, env do
28
28
  session.with_pub_channel do |ch|
29
- instrument(:process_publishing, instrumentation.merge(channel: ch.id)) do
30
- encoded = encode_payload(payload, options[:content_type])
31
- x = session.declare_exchange ch, name, params.exchange_options
32
- x.publish encoded, options
33
- end
29
+ encoded = encode_payload(payload, options[:content_type])
30
+ x = session.declare_exchange ch, name, params.exchange_options
31
+ x.publish encoded, options
34
32
  end
35
33
  end
36
34
  end
@@ -97,7 +97,7 @@ module Vx
97
97
  payload = ::JSON.parse(payload)
98
98
  end
99
99
 
100
- instrumentation = {
100
+ env = {
101
101
  consumer: consumer.params.consumer_name,
102
102
  queue: @q.name,
103
103
  rpc: REP,
@@ -106,18 +106,15 @@ module Vx
106
106
  properties: properties
107
107
  }
108
108
 
109
- consumer.with_middlewares :sub, instrumentation do
110
- consumer.instrument(:start_processing, instrumentation)
111
- consumer.instrument(:process, instrumentation) do
112
- call_id = properties[:correlation_id]
113
- c = @mutex.synchronize{ @await.delete(call_id) }
114
- if c
115
- @mutex.synchronize do
116
- @await[call_id] = [properties, payload]
117
- end
118
- @wakeup.synchronize do
119
- c.signal
120
- end
109
+ consumer.with_middlewares :sub, env do
110
+ call_id = properties[:correlation_id]
111
+ c = @mutex.synchronize{ @await.delete(call_id) }
112
+ if c
113
+ @mutex.synchronize do
114
+ @await[call_id] = [properties, payload]
115
+ end
116
+ @wakeup.synchronize do
117
+ c.signal
121
118
  end
122
119
  end
123
120
  end
@@ -141,7 +138,7 @@ module Vx
141
138
  consumer.session.with_pub_channel do |ch|
142
139
  exch = ch.exchange RPC_EXCHANGE_NAME
143
140
 
144
- instrumentation = {
141
+ env = {
145
142
  payload: message,
146
143
  rpc: REQ,
147
144
  exchange: exch.name,
@@ -152,16 +149,14 @@ module Vx
152
149
 
153
150
  @mutex.synchronize { @await[call_id] = cond }
154
151
 
155
- consumer.with_middlewares :pub, instrumentation do
156
- consumer.instrument(:process_publishing, instrumentation) do
157
- exch.publish(
158
- message.to_json,
159
- routing_key: routing_key,
160
- correlation_id: call_id,
161
- reply_to: q.name,
162
- content_type: JSON_CONTENT_TYPE
163
- )
164
- end
152
+ consumer.with_middlewares :pub, env do
153
+ exch.publish(
154
+ message.to_json,
155
+ routing_key: routing_key,
156
+ correlation_id: call_id,
157
+ reply_to: q.name,
158
+ content_type: JSON_CONTENT_TYPE
159
+ )
165
160
  end
166
161
 
167
162
  @wakeup.synchronize{
@@ -192,13 +187,6 @@ module Vx
192
187
  end
193
188
 
194
189
  def cancel
195
- instrumentation = {
196
- consumer: consumer.params.consumer_name,
197
- rpc: 'consume'
198
- }
199
-
200
- consumer.instrument('cancel_consumer', instrumentation)
201
-
202
190
  if subscriber?
203
191
  @subscriber.cancel
204
192
  @subscriber = nil
@@ -6,8 +6,6 @@ module Vx
6
6
  module Consumer
7
7
  class Session
8
8
 
9
- include Instrument
10
-
11
9
  @@session_lock = Mutex.new
12
10
 
13
11
  @@shutdown_lock = Mutex.new
@@ -41,17 +39,13 @@ module Vx
41
39
  def close
42
40
  if open?
43
41
  @@session_lock.synchronize do
44
- instrument("closing_connection", info: conn_info)
45
-
46
- instrument("close_connection", info: conn_info) do
47
- begin
48
- conn.close
49
- while conn.status != :closed
50
- sleep 0.01
51
- end
52
- rescue Bunny::ChannelError, Bunny::ClientTimeout => e
53
- Consumer.exception_handler(e, {})
42
+ begin
43
+ conn.close
44
+ while conn.status != :closed
45
+ sleep 0.01
54
46
  end
47
+ rescue Bunny::ChannelError, Bunny::ClientTimeout => e
48
+ Consumer.exception_handler(e, {})
55
49
  end
56
50
  @conn = nil
57
51
  end
@@ -71,15 +65,9 @@ module Vx
71
65
  automatically_recover: false
72
66
  )
73
67
 
74
- instrumentation = { info: conn_info }.merge(options)
75
-
76
- instrument("start_connecting", instrumentation)
77
-
78
- instrument("connect", instrumentation) do
79
- conn.start
80
- while conn.connecting?
81
- sleep 0.01
82
- end
68
+ conn.start
69
+ while conn.connecting?
70
+ sleep 0.01
83
71
  end
84
72
  end
85
73
  end
@@ -25,19 +25,16 @@ module Vx
25
25
  def handle_delivery(channel, delivery_info, properties, payload)
26
26
  payload = decode_payload properties, payload
27
27
 
28
- instrumentation = {
28
+ env = {
29
29
  consumer: params.consumer_name,
30
30
  payload: payload,
31
31
  properties: properties,
32
32
  channel: channel.id
33
33
  }
34
34
 
35
- with_middlewares :sub, instrumentation do
36
- instrument("start_processing", instrumentation)
37
- instrument("process", instrumentation) do
38
- allocate_pub_channel do
39
- run_instance delivery_info, properties, payload, channel
40
- end
35
+ with_middlewares :sub, env do
36
+ allocate_pub_channel do
37
+ run_instance delivery_info, properties, payload, channel
41
38
  end
42
39
  end
43
40
  end
@@ -59,10 +56,6 @@ module Vx
59
56
  def bind(options = {})
60
57
  qname = options[:queue] || params.queue_name
61
58
 
62
- instrumentation = {
63
- consumer: params.consumer_name
64
- }
65
-
66
59
  session.open
67
60
 
68
61
  ch = session.conn.create_channel
@@ -78,22 +71,8 @@ module Vx
78
71
 
79
72
  q = session.declare_queue ch, qname, params.queue_options
80
73
 
81
- instrumentation.merge!(
82
- exchange: x_name,
83
- queue: q.name,
84
- queue_options: params.queue_options,
85
- )
86
-
87
74
  if x_name != ''
88
- instrumentation.merge!(
89
- exchange_options: params.exchange_options,
90
- bind: params.bind_options
91
- )
92
- instrument("bind_queue", instrumentation) do
93
- q.bind(x, params.bind_options)
94
- end
95
- else
96
- instrument("using_default_exchange", instrumentation)
75
+ q.bind(x, params.bind_options)
97
76
  end
98
77
 
99
78
  [ch, q]
@@ -6,8 +6,6 @@ module Vx
6
6
  module Consumer
7
7
  class Subscriber < Bunny::Consumer
8
8
 
9
- include Instrument
10
-
11
9
  attr_accessor :vx_consumer_name, :queue_name
12
10
 
13
11
  def initialize(*args)
@@ -16,17 +14,14 @@ module Vx
16
14
  end
17
15
 
18
16
  def graceful_shutdown
19
- instrument('try_graceful_shutdown_consumer', consumer: vx_consumer_name)
20
17
  in_progress do
21
18
  cancel
22
- instrument('graceful_shutdown_consumer', consumer: vx_consumer_name)
23
19
  end
24
20
  end
25
21
 
26
22
  def try_graceful_shutdown
27
23
  if @lock.try_lock
28
24
  begin
29
- instrument('graceful_shutdown_consumer', consumer: vx_consumer_name)
30
25
  cancel
31
26
  ensure
32
27
  @lock.unlock
@@ -55,7 +50,6 @@ module Vx
55
50
  end
56
51
 
57
52
  def cancel
58
- instrument('cancel_consumer', consumer: vx_consumer_name, channel: channel.id)
59
53
  unless closed?
60
54
  super
61
55
  channel.close unless closed?
@@ -1,7 +1,7 @@
1
1
  module Vx
2
2
  module Lib
3
3
  module Consumer
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'bunny', '= 1.6.3'
21
+ spec.add_runtime_dependency 'bunny', '= 1.6.3'
22
22
  spec.add_runtime_dependency 'vx-lib-rack-builder', '>= 0.0.2'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-lib-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
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-12-04 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -98,7 +98,6 @@ files:
98
98
  - lib/vx/lib/consumer/ack.rb
99
99
  - lib/vx/lib/consumer/configuration.rb
100
100
  - lib/vx/lib/consumer/error.rb
101
- - lib/vx/lib/consumer/instrument.rb
102
101
  - lib/vx/lib/consumer/params.rb
103
102
  - lib/vx/lib/consumer/publish.rb
104
103
  - lib/vx/lib/consumer/rpc.rb
@@ -1,27 +0,0 @@
1
- module Vx
2
- module Lib
3
- module Consumer
4
- module Instrument
5
-
6
- def instrument(name, payload, &block)
7
- name = "#{name}.consumer.vx".freeze
8
-
9
- if Consumer.configuration.debug?
10
- $stdout.puts " --> #{name}: #{payload}"
11
- end
12
-
13
- if Consumer.configuration.instrumenter
14
- Consumer.configuration.instrumenter.instrument(name, payload, &block)
15
- else
16
- begin
17
- yield if block_given?
18
- rescue Exception => e
19
- Consumer.handle_exception(e, {})
20
- end
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
27
- end