combi 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/combi/queue_service.rb +11 -4
- data/lib/combi/version.rb +1 -1
- data/spec/lib/combi/buses/queue_spec.rb +42 -7
- data/spec/support/rabbitmq_server.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4b7f86ff2d0ee05ef90a678b852c529bf126517
|
4
|
+
data.tar.gz: d42e6f431566d2a2665a34ebd247b967c745e0d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fc53639816bcaa94dd0f430f331960b78c12dd992abbc048c9c7d1ad110bdf2075f7990f4471abb170b5e47db4bc4aa88cd5e71542a56d34e65958a9dce9a02
|
7
|
+
data.tar.gz: 9d21649b35a445d472d419e7e211324d5289cd30a62dae65663424ee5d1dd4c9be1e4e01d804b81425892d4cc1c1e3f759bd34c80dbfa34861a2d6df12e8f90a
|
data/lib/combi/queue_service.rb
CHANGED
@@ -11,9 +11,11 @@ module Combi
|
|
11
11
|
@options = options
|
12
12
|
@rpc_queue = nil
|
13
13
|
@ready_defer = EventMachine::DefaultDeferrable.new
|
14
|
+
@ready_callbacks = []
|
14
15
|
end
|
15
16
|
|
16
17
|
def ready(&block)
|
18
|
+
@ready_callbacks << block
|
17
19
|
@ready_defer.callback &block
|
18
20
|
end
|
19
21
|
|
@@ -23,25 +25,30 @@ module Combi
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def start
|
28
|
+
@config[:on_tcp_connection_failure] = Proc.new { EM.add_timer(4 * rand) { start } }
|
26
29
|
connect @config do
|
27
30
|
if @options[:rpc] == :enabled
|
28
31
|
create_rpc_queue
|
29
32
|
else
|
30
|
-
puts "ready"
|
31
33
|
@ready_defer.succeed
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
def connect(config, &after_connect)
|
39
|
+
puts "[INFO] trying to connect to queue"
|
37
40
|
@amqp_conn = AMQP.connect(config) do |connection, open_ok|
|
38
41
|
@channel = AMQP::Channel.new @amqp_conn
|
39
42
|
@channel.auto_recovery = true
|
40
43
|
@exchange = @channel.direct ''
|
41
44
|
after_connect.call
|
42
45
|
connection.on_tcp_connection_loss do |conn, settings|
|
43
|
-
puts "[
|
44
|
-
|
46
|
+
puts "[ERROR] Connection failed, resetting for reconnect"
|
47
|
+
@ready_defer = EventMachine::DefaultDeferrable.new
|
48
|
+
@ready_callbacks.each do |callback|
|
49
|
+
@ready_defer.callback &callback
|
50
|
+
end
|
51
|
+
start
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
@@ -87,7 +94,7 @@ module Combi
|
|
87
94
|
def call(kind, message, options = {})
|
88
95
|
log "sending request #{kind} #{message.inspect[0..500]} with options #{options.inspect}"
|
89
96
|
raise "RPC is not enabled or reply_to is not included" if (@rpc_queue.nil? || @rpc_queue.name.nil?) && options[:reply_to].nil?
|
90
|
-
options[:expiration] = (options[:timeout] || RPC_DEFAULT_TIMEOUT) * 1000
|
97
|
+
options[:expiration] = ((options[:timeout] || RPC_DEFAULT_TIMEOUT) * 1000).to_i
|
91
98
|
options[:routing_key] ||= 'rcalls_queue'
|
92
99
|
options[:reply_to] ||= @rpc_queue.name
|
93
100
|
request = {
|
data/lib/combi/version.rb
CHANGED
@@ -6,6 +6,12 @@ require 'combi/buses/queue'
|
|
6
6
|
describe 'Combi::Queue' do
|
7
7
|
include EventedSpec::SpecHelper
|
8
8
|
|
9
|
+
before(:all) do
|
10
|
+
RabbitmqServer.instance.stop! if ENV['CLEAN']
|
11
|
+
RabbitmqServer.instance.start!
|
12
|
+
end
|
13
|
+
after(:all) { RabbitmqServer.instance.stop! if ENV['CLEAN'] }
|
14
|
+
|
9
15
|
context 'can be instanitated via ServiceBus' do
|
10
16
|
When(:bus) { Combi::ServiceBus.init_for(:queue, {init_queue: false}) }
|
11
17
|
Then { Combi::Queue === bus }
|
@@ -23,19 +29,48 @@ describe 'Combi::Queue' do
|
|
23
29
|
:frame_max => 131072
|
24
30
|
}
|
25
31
|
end
|
26
|
-
Given(:provider) { Combi::ServiceBus.init_for(:queue, { amqp_config: amqp_config } ) }
|
27
|
-
Given(:consumer) { Combi::ServiceBus.init_for(:queue, { amqp_config: amqp_config } ) }
|
32
|
+
Given(:provider) { Combi::ServiceBus.init_for(:queue, { amqp_config: amqp_config.merge(role: 'provider') } ) }
|
33
|
+
Given(:consumer) { Combi::ServiceBus.init_for(:queue, { amqp_config: amqp_config.merge(role: 'consumer') } ) }
|
28
34
|
Given(:prepare) do
|
29
35
|
provider.start!
|
30
36
|
consumer.start!
|
31
37
|
true
|
32
38
|
end
|
33
39
|
|
34
|
-
it_behaves_like 'standard_bus'
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
it_behaves_like 'standard_bus'
|
41
|
+
|
42
|
+
Given(:null_service) do
|
43
|
+
Module.new do
|
44
|
+
def actions; [:null]; end
|
45
|
+
def do_it(params)
|
46
|
+
"null"
|
47
|
+
end
|
38
48
|
end
|
39
|
-
after(:all) { RabbitmqServer.instance.stop! if ENV['CLEAN'] }
|
40
49
|
end
|
50
|
+
|
51
|
+
context "it resist a reconnection" do
|
52
|
+
puts "VERY UNSTABLE TEST"
|
53
|
+
When(:service) { provider.add_service null_service }
|
54
|
+
Then do
|
55
|
+
em do
|
56
|
+
prepare
|
57
|
+
EM::add_timer(0.1) do
|
58
|
+
`killall ssh`
|
59
|
+
end
|
60
|
+
EM::add_timer(0.2) do
|
61
|
+
RabbitmqServer.instance.start_forwarder!
|
62
|
+
end
|
63
|
+
EM::add_timer(2) do
|
64
|
+
EM.synchrony do
|
65
|
+
service_result = EM::Synchrony.sync consumer.request(:null, :do_it, {}, { timeout: 2 })
|
66
|
+
service_result.should eq "null"
|
67
|
+
done
|
68
|
+
provider.stop!
|
69
|
+
consumer.stop!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
41
76
|
end
|
@@ -45,7 +45,7 @@ class RabbitmqServer
|
|
45
45
|
container_line = `docker ps | grep #{NAME}`
|
46
46
|
port_match = container_line.match(/:([0-9]+)->5672/)
|
47
47
|
if port_match
|
48
|
-
return port_match[1]
|
48
|
+
return port_match[1].to_i
|
49
49
|
else
|
50
50
|
puts "Container not running yet, sleeping"
|
51
51
|
sleep 0.2
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- German Del Zotto
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|