combi 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/combi/buses/http.rb +5 -1
- data/lib/combi/buses/in_process.rb +2 -1
- data/lib/combi/buses/queue.rb +7 -3
- data/lib/combi/buses/web_socket.rb +7 -3
- data/lib/combi/queue_service.rb +1 -2
- data/lib/combi/response_store.rb +1 -1
- data/lib/combi/version.rb +1 -1
- data/spec/shared_examples/standard_bus.rb +92 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38eced61f795b66ed4f2eafe663e8dd5a204b99a
|
4
|
+
data.tar.gz: e0793e82d4b75ba93ddc5a835a9bea71d1453117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8bddb984ae14b2c28329dc152873cd580dd70e3bc13a641fb1da673d0edf6c2835b59d52ec87acc2552cab6124e79f33a4be8829eecba68e05ce6667b90e124
|
7
|
+
data.tar.gz: 756143cca67900ca14a5c038ab14eda751ebda96a68c956634c8b5fcf3885f396bd6f88ec9e9b00ce7f4c2cbf8978344748079cf2b4145e9cac241f7fa4f5fff
|
data/lib/combi/buses/http.rb
CHANGED
@@ -54,7 +54,11 @@ module Combi
|
|
54
54
|
kind = message['kind']
|
55
55
|
if service_instance.respond_to? kind
|
56
56
|
message['payload'] ||= {}
|
57
|
-
|
57
|
+
begin
|
58
|
+
response = service_instance.send(kind, message['payload'])
|
59
|
+
rescue Exception => e
|
60
|
+
response = {error: true, message: e.message}
|
61
|
+
end
|
58
62
|
{result: 'ok', response: response}
|
59
63
|
end
|
60
64
|
end
|
@@ -26,9 +26,10 @@ module Combi
|
|
26
26
|
rescue Timeout::Error => e
|
27
27
|
log "ERROR"
|
28
28
|
waiter.fail RuntimeError.new(Timeout::Error)
|
29
|
-
rescue e
|
29
|
+
rescue Exception => e
|
30
30
|
log "other ERROR"
|
31
31
|
log e.inspect
|
32
|
+
waiter.fail({'error' => true, 'message' => e.message})
|
32
33
|
end
|
33
34
|
waiter
|
34
35
|
end
|
data/lib/combi/buses/queue.rb
CHANGED
@@ -69,17 +69,21 @@ module Combi
|
|
69
69
|
return
|
70
70
|
end
|
71
71
|
log "generating response for #{service_instance.class}#{service_instance.actions.inspect}.#{kind} #{payload.inspect}"
|
72
|
-
|
72
|
+
begin
|
73
|
+
response = service_instance.send(kind, payload)
|
74
|
+
rescue Exception => e
|
75
|
+
response = {error: true, message: e.message}
|
76
|
+
end
|
73
77
|
|
74
78
|
if response.respond_to? :succeed
|
75
79
|
log "response is deferred"
|
76
80
|
response.callback do |service_response|
|
77
81
|
log "responding with deferred answer: #{service_response.inspect}"
|
78
|
-
queue_service.respond(service_response, delivery_info)
|
82
|
+
queue_service.respond(service_response.to_json, delivery_info)
|
79
83
|
end
|
80
84
|
else
|
81
85
|
log "responding with inmediate answer: #{response.inspect}"
|
82
|
-
queue_service.respond(response, delivery_info) unless response.nil?
|
86
|
+
queue_service.respond(response.to_json, delivery_info) unless response.nil?
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -170,17 +170,21 @@ module Combi
|
|
170
170
|
kind = message['kind']
|
171
171
|
payload = message['payload'] || {}
|
172
172
|
payload['session'] = session
|
173
|
-
|
173
|
+
begin
|
174
|
+
response = invoke_service(service_name, kind, payload)
|
175
|
+
rescue Exception => e
|
176
|
+
response = {error: true, message: e.message}
|
177
|
+
end
|
174
178
|
|
175
179
|
msg = {result: 'ok', correlation_id: message['correlation_id']}
|
176
180
|
|
177
181
|
if response.respond_to? :succeed
|
178
182
|
response.callback do |service_response|
|
179
|
-
msg[:response] = service_response
|
183
|
+
msg[:response] = service_response.to_json
|
180
184
|
ws.send(msg.to_json)
|
181
185
|
end
|
182
186
|
else
|
183
|
-
msg[:response] = response
|
187
|
+
msg[:response] = response.to_json
|
184
188
|
ws.send(msg.to_json)
|
185
189
|
end
|
186
190
|
end
|
data/lib/combi/queue_service.rb
CHANGED
@@ -49,7 +49,6 @@ module Combi
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def publish(*args, &block)
|
52
|
-
args[0] = args[0].to_json unless args[0].is_a? String
|
53
52
|
@exchange.publish *args do
|
54
53
|
log "Sent to network drivers: #{args.inspect}"
|
55
54
|
block.call if block_given?
|
@@ -95,7 +94,7 @@ module Combi
|
|
95
94
|
payload: message,
|
96
95
|
options: {}
|
97
96
|
}
|
98
|
-
publish(request, options)
|
97
|
+
publish(request.to_json, options)
|
99
98
|
end
|
100
99
|
|
101
100
|
end
|
data/lib/combi/response_store.rb
CHANGED
data/lib/combi/version.rb
CHANGED
@@ -20,6 +20,24 @@ shared_examples_for "standard_bus" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
Given(:echo_service) do
|
24
|
+
Module.new do
|
25
|
+
def actions; [:echo_this]; end
|
26
|
+
def do_it(params)
|
27
|
+
params['data']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Given(:broken_service) do
|
33
|
+
Module.new do
|
34
|
+
def actions; [:shout_error]; end
|
35
|
+
def do_it(params)
|
36
|
+
raise params['message']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
23
41
|
Given(:finalize) do
|
24
42
|
provider.stop!
|
25
43
|
consumer.stop!
|
@@ -59,4 +77,78 @@ shared_examples_for "standard_bus" do
|
|
59
77
|
end
|
60
78
|
end
|
61
79
|
end
|
80
|
+
|
81
|
+
context 'return the same data type returned by service' do
|
82
|
+
Given(:result_container) { {} }
|
83
|
+
Given(:params) { { data: data } }
|
84
|
+
When(:service) { provider.add_service echo_service }
|
85
|
+
When('service is called') do
|
86
|
+
em do
|
87
|
+
prepare
|
88
|
+
EM.synchrony do
|
89
|
+
result_container[:result] = EM::Synchrony.sync consumer.request(:echo_this, :do_it, params)
|
90
|
+
done
|
91
|
+
finalize
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'for string' do
|
97
|
+
Given(:data) { "a simple string" }
|
98
|
+
Then { result_container[:result].should eq data}
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'for numbers' do
|
102
|
+
Given(:data) { 237.324 }
|
103
|
+
Then { result_container[:result].should eq data}
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'for arrays' do
|
107
|
+
Given(:data) { [1, 2, 3.0, "4", "cinco"]}
|
108
|
+
Then { result_container[:result].should eq data}
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'for symbols always return a string' do
|
112
|
+
Given(:data) { :some_symbol }
|
113
|
+
Then { result_container[:result].should eq data.to_s}
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'for maps' do
|
117
|
+
Given(:data) { {'a' => 1, 'b' => 'dos'} }
|
118
|
+
Then { result_container[:result].should eq data}
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'for objects returns their json version' do
|
122
|
+
Given(:custom_json) { {val: 'value'} }
|
123
|
+
Given(:custom_class) do
|
124
|
+
Class.new do
|
125
|
+
def initialize(custom_json)
|
126
|
+
@custom_json = custom_json
|
127
|
+
end
|
128
|
+
def to_json
|
129
|
+
@custom_json
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
Given(:data) { custom_class.new(custom_json).to_json}
|
134
|
+
Then { result_container[:result].should eq JSON.parse(custom_json.to_json)}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'return something when service raise an error' do
|
139
|
+
Given(:error_message) { 'service is broken' }
|
140
|
+
When(:service) { provider.add_service broken_service }
|
141
|
+
Then do
|
142
|
+
em do
|
143
|
+
prepare
|
144
|
+
EM.synchrony do
|
145
|
+
service_result = EM::Synchrony.sync consumer.request(:shout_error, :do_it, {message: error_message}, { timeout: 0.1 })
|
146
|
+
service_result['error'].should be_true
|
147
|
+
service_result['message'].should eq error_message
|
148
|
+
done
|
149
|
+
finalize
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
62
154
|
end
|
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.7
|
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-05-
|
12
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
@@ -196,8 +196,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
version: '0'
|
197
197
|
requirements: []
|
198
198
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.2.
|
199
|
+
rubygems_version: 2.2.0
|
200
200
|
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: Mini Bus for microservices
|
203
203
|
test_files: []
|
204
|
+
has_rdoc:
|