evrone-common-amqp 0.2.2 → 0.2.3

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: b7026b69a2227f3adc9eef4d6cfd39ff0ec764ce
4
- data.tar.gz: 8811dd3fd48a5e75384d7491334e3ba7db904f8a
3
+ metadata.gz: f645ca2a91df21cc2f73e78619c0a6e156a8a9e9
4
+ data.tar.gz: 0c98ff77f1a9b95f04b5ee38a571b98d9c45964f
5
5
  SHA512:
6
- metadata.gz: 03a5921a1d9b900c30a4448caef99e68c6ecbd508f23cbe4422bb6e7c185d680bad891d92b64102f29ae95f77d2934e9219229fee75ba0ee386f2669262cbefa
7
- data.tar.gz: 90b0697c2a69f25e70e5719b500f66566c9ac41e6bc8101d8dc01d7ca08b2c104d94c060440869990ac3ba80467adc8b7760b1e1edcf4289b92a45e9cd0a1da1
6
+ metadata.gz: 724917e1aa65f511de5680fcd4b247097ca2ea9941bef1666d00d68b5d1338d0e5f036ac8b0d1eabb38f17d037591f8dc8b8a4019ef73281934da93f10a85aa2
7
+ data.tar.gz: b1c678749a8d5b3446df0a9e8c5d9d76252d8a073e946d597b1a1a2e549eb731edaf5081aa5497a158b42b235ed547e0e45da48289ee2d071900d20f9c140680
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - jruby-19mode
5
5
 
6
+
6
7
  services:
7
8
  - rabbitmq
8
9
 
@@ -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.0.0.pre6"
23
+ spec.add_runtime_dependency "bunny", ">= 1.0.0.rc2"
24
24
  spec.add_runtime_dependency "evrone-common-rack-builder"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -26,6 +26,10 @@ module Evrone
26
26
  end
27
27
  end
28
28
 
29
+ def on_error(&block)
30
+ callbacks[:on_error] = block
31
+ end
32
+
29
33
  def default_exchange_name
30
34
  "amq.#{default_exchange_type}"
31
35
  end
@@ -29,15 +29,6 @@ module Evrone
29
29
  @@classes
30
30
  end
31
31
 
32
- def consumer_name
33
- @consumer_name ||= begin
34
- id = Thread.current[:consumer_id]
35
- name = self.class.consumer_name.dup
36
- name << ".#{id}" if id
37
- name
38
- end
39
- end
40
-
41
32
  module ClassMethods
42
33
 
43
34
  include Common::AMQP::Consumer::Configuration
@@ -77,6 +77,14 @@ module Evrone
77
77
  consumer_configuration.consumer_name
78
78
  end
79
79
 
80
+ def consumer_id
81
+ if cid = Thread.current[:evrone_amqp_consumer_id]
82
+ "#{consumer_name}.#{cid}"
83
+ else
84
+ consumer_name
85
+ end
86
+ end
87
+
80
88
  def bind_options
81
89
  consumer_configuration.bind_options ||
82
90
  @@consumer_configuration_lock.synchronize do
@@ -13,7 +13,7 @@ module Evrone
13
13
 
14
14
  x = declare_exchange
15
15
 
16
- run_callbacks(:publish, message: message, exchange: x, name: consumer_name) do
16
+ run_callbacks(:publish, message: message, exchange: x, name: consumer_id) do
17
17
  m = serialize_message message, options[:content_type]
18
18
  x.publish m, options
19
19
  end
@@ -10,7 +10,7 @@ module Evrone
10
10
  x = declare_exchange
11
11
  q = declare_queue
12
12
 
13
- run_callbacks(:subscribe, exchange: x, queue: q, name: consumer_name) do
13
+ run_callbacks(:subscribe, exchange: x, queue: q, name: consumer_id) do
14
14
  debug "subscribing to #{q.name}:#{x.name} using #{bind_options.inspect}"
15
15
  q.bind(x, bind_options)
16
16
  debug "successfuly subscribed to #{q.name}:#{x.name}"
@@ -47,7 +47,7 @@ module Evrone
47
47
  def run_instance(delivery_info, properties, payload)
48
48
  payload = deserialize_message properties, payload
49
49
 
50
- run_callbacks :recieve, payload: payload, name: consumer_name do
50
+ run_callbacks :recieve, payload: payload, name: consumer_id do
51
51
  new.tap do |inst|
52
52
  inst.properties = properties
53
53
  inst.delivery_info = delivery_info
@@ -19,6 +19,16 @@ module Evrone
19
19
  rs
20
20
  end
21
21
 
22
+ def run_on_error_callback(e)
23
+ if f = Common::AMQP.config.callbacks[:on_error]
24
+ begin
25
+ f.call e
26
+ rescue Exception => e
27
+ $stderr.puts "ERROR on error callback: #{e.inspect}"
28
+ end
29
+ end
30
+ end
31
+
22
32
  end
23
33
  end
24
34
  end
@@ -6,6 +6,7 @@ module Evrone
6
6
  class Supervisor::Threaded
7
7
 
8
8
  include Common::AMQP::Logger
9
+ include Common::AMQP::Callbacks
9
10
 
10
11
  POOL_INTERVAL = 0.5
11
12
 
@@ -128,8 +129,7 @@ module Evrone
128
129
  attempt = 0 if reset_attempt?(task)
129
130
  task.dup.tap do |new_task|
130
131
  new_task.thread = Thread.new(new_task) do |t|
131
- Thread.current[:consumer_id] = t.id
132
- Thread.current[:consumer_name] = t.object.to_s
132
+ Thread.current[:evrone_amqp_consumer_id] = t.id
133
133
  t.object.send t.method
134
134
  end
135
135
  new_task.thread.abort_on_exception = false
@@ -149,6 +149,7 @@ module Evrone
149
149
  rescue Exception => e
150
150
  STDERR.puts "#{e.inspect} in #{task.inspect}"
151
151
  STDERR.puts e.backtrace.join("\n")
152
+ run_on_error_callback(e)
152
153
  e
153
154
  end
154
155
  end
@@ -1,7 +1,7 @@
1
1
  module Evrone
2
2
  module Common
3
3
  module AMQP
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
6
6
  end
7
7
  end
@@ -52,10 +52,16 @@ describe "Run in multithread environment", slow: true, jruby: true do
52
52
  ths = (0..12).map do |i|
53
53
  klass = (i % 2 == 0) ? alice : bob
54
54
  Thread.new do
55
- klass.subscribe
55
+ begin
56
+ klass.subscribe
57
+ rescue Exception => e
58
+ puts "ERROR: #{e.inspect}"
59
+ raise e
60
+ end
61
+ end.tap do |th|
62
+ th.abort_on_exception = true
56
63
  end
57
64
  end
58
- ths.each{|t| t.abort_on_exception = true }
59
65
  sleep 0.5
60
66
 
61
67
  num_messages.times do |n|
@@ -17,5 +17,16 @@ describe Evrone::Common::AMQP::Config do
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ context "on_error" do
22
+ it "should be success" do
23
+ config.on_error do |e|
24
+ e
25
+ end
26
+ val = config.callbacks[:on_error].call "value"
27
+ expect(val).to eq 'value'
28
+ end
29
+ end
20
30
  end
31
+
21
32
  end
@@ -32,16 +32,15 @@ describe Evrone::Common::AMQP::Consumer do
32
32
  its(:config) { should be_an_instance_of(Evrone::Common::AMQP::Config) }
33
33
  its(:consumer_name) { should eq 'test_consumer' }
34
34
 
35
- context "instance consumer_name" do
36
- subject { consumer.consumer_name }
35
+ context "consumer_id" do
37
36
 
38
- it { should eq 'test_consumer' }
39
-
40
- context "when Thread.current has key :consumer_id" do
41
- before do
42
- mock(Thread.current).[](:consumer_id){ '99' }
37
+ it "should be success" do
38
+ expect(consumer_class.consumer_id).to eq 'test_consumer'
39
+ th = Thread.new do
40
+ Thread.current[:evrone_amqp_consumer_id] = '99'
41
+ consumer_class.consumer_id
43
42
  end
44
- it { should eq 'test_consumer.99' }
43
+ expect(th.value).to eq 'test_consumer.99'
45
44
  end
46
45
  end
47
46
 
@@ -29,7 +29,7 @@ describe Evrone::Common::AMQP::Supervisor::Threaded, jruby: true do
29
29
  let(:len) { 1 }
30
30
  let(:runner) {
31
31
  Proc.new do
32
- id = Thread.current[:consumer_id]
32
+ id = Thread.current[:evrone_amqp_consumer_id]
33
33
  mutex.synchronize do
34
34
  collected.push id
35
35
  end
@@ -73,7 +73,7 @@ describe Evrone::Common::AMQP::Supervisor::Threaded, jruby: true do
73
73
  let(:runner) {
74
74
  Proc.new do
75
75
  sleep 0.1
76
- id = Thread.current[:consumer_id]
76
+ id = Thread.current[:evrone_amqp_consumer_id]
77
77
  mutex.synchronize do
78
78
  collected.push id
79
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evrone-common-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.pre6
19
+ version: 1.0.0.rc2
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.0.0.pre6
26
+ version: 1.0.0.rc2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: evrone-common-rack-builder
29
29
  requirement: !ruby/object:Gem::Requirement