vx-consumer 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c09af6eb8d570916b1ea57a6c5968ef05da1d93
4
- data.tar.gz: 60fd28a772622324cdf571152465d3a2775b3468
3
+ metadata.gz: a4ba824b3b9047df1c4d5fe74e531bdc1f884535
4
+ data.tar.gz: f31036250c862fb2975c7ff2bb52cf8674812351
5
5
  SHA512:
6
- metadata.gz: 5a6913319e7df53244e328531db53defd613c305f8848e5d2cb6093792e23f8101bc093ef277e3d3754f31d51b0209dcf5c1b18a49a8ea5e80f93ddecc30a2b1
7
- data.tar.gz: 063f23c5b56403293ff4a5cd8cb0499caf0cd8104d215ebefcb404b802373ef623c9d70203ce000ebcdeced6041207f4b5dd10dc8daef4eadd087fdc4b607444
6
+ metadata.gz: b6b60d2dd3c3bdc6aeeced8807b354aff3d0815e35d87b1d2f0cd76d895981dc0c532f80343dc854f26ecfcff825980bcecce03b2acc1db1ff9545daa4a1049b
7
+ data.tar.gz: bde55043df8b5d64668643cfedaeeb8caacb48bbbabf5d2f9ace3c47bc5f2b1d7aef062f03b9314b4ab079f18e79871a25ee894962c4137f871e3d038abbce26
data/.travis.yml CHANGED
@@ -2,9 +2,8 @@ services:
2
2
  - rabbitmq
3
3
 
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
5
+ - 2.0
6
+ - 2.1
8
7
  - jruby
9
8
 
10
9
  matrix:
data/README.md CHANGED
@@ -27,3 +27,4 @@ TODO: Write usage instructions here
27
27
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
28
  4. Push to the branch (`git push origin my-new-feature`)
29
29
  5. Create new Pull Request
30
+
@@ -7,6 +7,7 @@ module Vx
7
7
  consumer: self.class.params.consumer_name,
8
8
  properties: properties,
9
9
  multiple: multiple,
10
+ channel: _channel.id
10
11
  }
11
12
  if _channel.open?
12
13
  _channel.ack delivery_info.delivery_tag, multiple
@@ -24,6 +25,7 @@ module Vx
24
25
  properties: properties,
25
26
  multiple: multiple,
26
27
  requeue: requeue,
28
+ channel: channel.id
27
29
  }
28
30
  if _channel.open?
29
31
  _channel.ack delivery_info.delivery_tag, multiple, requeue
@@ -24,8 +24,8 @@ module Vx
24
24
  }
25
25
 
26
26
  with_middlewares :pub, instrumentation do
27
- instrument("process_publishing", instrumentation) do
28
- session.with_channel do |ch|
27
+ with_channel do |ch|
28
+ instrument("process_publishing", instrumentation.merge(channel: ch.id)) do
29
29
  encoded = encode_payload(payload, options[:content_type])
30
30
  x = session.declare_exchange ch, name, params.exchange_options
31
31
  x.publish encoded, options
@@ -36,6 +36,10 @@ module Vx
36
36
 
37
37
  private
38
38
 
39
+ def with_channel
40
+ yield session.pub_channel
41
+ end
42
+
39
43
  def encode_payload(payload, content_type)
40
44
  Serializer.pack(content_type, payload)
41
45
  end
@@ -40,9 +40,9 @@ module Vx
40
40
  def close
41
41
  if open?
42
42
  @@session_lock.synchronize do
43
- instrument("closing_collection", info: conn_info)
43
+ instrument("closing_connection", info: conn_info)
44
44
 
45
- instrument("close_collection", info: conn_info) do
45
+ instrument("close_connection", info: conn_info) do
46
46
  begin
47
47
  conn.close
48
48
  while conn.status != :closed
@@ -98,10 +98,23 @@ module Vx
98
98
  end
99
99
  end
100
100
 
101
- def with_channel
101
+ def pub_channel
102
102
  assert_connection_is_open
103
103
 
104
- conn.with_channel { |ch| yield ch }
104
+ key = :vx_consumer_session_pub_channel
105
+ ch = Thread.current[key]
106
+
107
+ if ch and ch.closed?
108
+ ch = nil
109
+ end
110
+
111
+ unless ch
112
+ ch = conn.create_channel
113
+ assign_error_handlers_to_channel(ch)
114
+ ch
115
+ end
116
+
117
+ ch
105
118
  end
106
119
 
107
120
  def declare_exchange(ch, name, options = nil)
@@ -118,6 +131,11 @@ module Vx
118
131
  ch.queue name, options
119
132
  end
120
133
 
134
+ def assign_error_handlers_to_channel(ch)
135
+ ch.on_uncaught_exception {|e, c| ::Vx::Consumer.exception_handler(e, consumer: c) }
136
+ ch.on_error {|e, c| ::Vx::Consumer.exception_handler(e, consumer: c) }
137
+ end
138
+
121
139
  private
122
140
 
123
141
  def assert_connection_is_open
@@ -27,6 +27,7 @@ module Vx
27
27
  consumer: params.consumer_name,
28
28
  payload: payload,
29
29
  properties: properties,
30
+ channel: channel.id
30
31
  }
31
32
 
32
33
  with_middlewares :sub, instrumentation do
@@ -60,7 +61,7 @@ module Vx
60
61
  session.open
61
62
 
62
63
  ch = session.conn.create_channel
63
- assign_error_handlers_to_channel(ch)
64
+ session.assign_error_handlers_to_channel(ch)
64
65
  ch.prefetch configuration.prefetch
65
66
 
66
67
  x = session.declare_exchange ch, params.exchange_name, params.exchange_options
@@ -80,11 +81,6 @@ module Vx
80
81
  [ch, q]
81
82
  end
82
83
 
83
- def assign_error_handlers_to_channel(ch)
84
- ch.on_uncaught_exception {|e, c| Consumer.exception_handler(e, consumer: c) }
85
- ch.on_error {|e, c| Consumer.exception_handler(e, consumer: c) }
86
- end
87
-
88
84
  end
89
85
  end
90
86
  end
@@ -32,11 +32,12 @@ module Vx
32
32
  def call(*args)
33
33
  in_progress do
34
34
  @on_delivery.call(*args) if @on_delivery
35
+ sleep 0
35
36
  end
36
37
  end
37
38
 
38
39
  def cancel
39
- instrument('cancel_consumer', consumer: vx_consumer_name)
40
+ instrument('cancel_consumer', consumer: vx_consumer_name, channel: channel.id)
40
41
  super
41
42
  channel.close unless channel.closed?
42
43
  end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Consumer
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -4,6 +4,10 @@ require 'spec_helper'
4
4
 
5
5
  describe Vx::Consumer do
6
6
 
7
+ before do
8
+ Bob.timeout = 0.1
9
+ end
10
+
7
11
  context "test consumer declaration" do
8
12
  context "alice" do
9
13
  subject { Alice.params }
@@ -22,7 +26,7 @@ describe Vx::Consumer do
22
26
  its(:exchange_name) { should eq 'bob_exch' }
23
27
  its(:exchange_options) { should eq(durable: false, auto_delete: true, type: :topic) }
24
28
  its(:queue_name) { should eq 'bob_queue' }
25
- its(:queue_options) { should eq(exclusive: true, durable: false) }
29
+ its(:queue_options) { should eq(durable: false, auto_delete: true) }
26
30
  its(:ack) { should be_true }
27
31
  its(:routing_key) { should be_nil }
28
32
  its(:content_type) { should eq 'application/json' }
@@ -60,7 +64,7 @@ describe Vx::Consumer do
60
64
 
61
65
  Timeout.timeout(10) do
62
66
  loop do
63
- break if Bob._collected.size == 90
67
+ break if Bob._collected.size >= 90
64
68
  sleep 0.1
65
69
  end
66
70
  end
@@ -107,20 +111,23 @@ describe Vx::Consumer do
107
111
  end
108
112
 
109
113
  it "should work with graceful shutdown" do
114
+ Bob.timeout = 1
115
+
110
116
  consumer = Bob.subscribe
111
117
  10.times do |n|
112
118
  Bob.publish a: n
113
119
  end
114
120
 
115
- sleep 0.2
116
- Timeout.timeout(1) do
121
+ sleep 0.1
122
+ Timeout.timeout(5) do
117
123
  consumer.graceful_shutdown
118
124
  end
119
125
 
120
- expect(Bob._collected).to have_at_least(2).item
126
+ expect(Bob._collected).to_not be_empty
121
127
  end
122
128
 
123
129
  it "running? should be true when consumer process task" do
130
+ Bob.timeout = 1
124
131
  consumer = Bob.subscribe
125
132
 
126
133
  expect(consumer.running?).to be_false
@@ -136,6 +143,7 @@ describe Vx::Consumer do
136
143
  consumer.cancel
137
144
  end
138
145
 
146
+ sleep 0.1
139
147
  expect(consumer.running?).to be_false
140
148
  end
141
149
 
@@ -14,13 +14,16 @@ class Bob
14
14
  include Vx::Consumer
15
15
 
16
16
  exchange 'bob_exch', durable: false, auto_delete: true
17
- queue 'bob_queue', exclusive: true, durable: false
17
+ queue 'bob_queue', durable: false, auto_delete: true
18
18
  ack
19
19
 
20
20
  @@m = Mutex.new
21
21
  @@collected = []
22
22
 
23
23
  class << self
24
+
25
+ attr_accessor :timeout
26
+
24
27
  def _collected
25
28
  @@collected
26
29
  end
@@ -40,7 +43,7 @@ class Bob
40
43
 
41
44
  def perform(payload)
42
45
  self.class._save payload
43
- sleep 0.1
46
+ sleep self.class.timeout
44
47
  ack
45
48
  end
46
49
  end
data/vx-consumer.gemspec CHANGED
@@ -18,10 +18,10 @@ 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.1.1'
21
+ spec.add_runtime_dependency 'bunny', '= 1.2.2'
22
22
  spec.add_runtime_dependency 'vx-common-rack-builder', '>= 0.0.2'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
25
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rspec", '2.14.1'
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-02-12 00:00:00.000000000 Z
11
+ date: 2014-06-17 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.1
19
+ version: 1.2.2
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.1
26
+ version: 1.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: vx-common-rack-builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.14.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.14.1
83
83
  description: ' description '
84
84
  email:
85
85
  - dima.exe@gmail.com
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.0.14
137
+ rubygems_version: 2.2.2
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: summary