combi 0.0.3 → 0.0.4
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/bus.rb +2 -2
- data/lib/combi/buses/correlation.rb +7 -0
- data/lib/combi/buses/http.rb +1 -1
- data/lib/combi/buses/queue.rb +2 -1
- data/lib/combi/buses/web_socket.rb +1 -1
- data/lib/combi/helpers.rb +3 -2
- data/lib/combi/queue_service.rb +5 -5
- data/lib/combi/response_store.rb +10 -2
- data/lib/combi/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb9c96c293e468a51e0e8df468cd80351c8527f1
|
4
|
+
data.tar.gz: 6dae3c02ff950edb7f344023b6d3d1c474b18984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a365af34ac3944d4b4233ce02c695cd81b2c3feeda634bb8d20708e560ef941ab8e5e40d1a0d6d62b278ac87e27471b111f13e79e7e2946b10eeb199db19fc
|
7
|
+
data.tar.gz: 99931424936890d9202d184d059266190e419ed7baa10874280a0ccc38920eae919625cdcca1812dc13e72e7b7161afd4fbf4f8c59b55c44a3ee2d37f62368c3
|
data/lib/combi/buses/bus.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "combi/service"
|
2
|
+
require_relative 'correlation'
|
2
3
|
require 'yajl'
|
3
4
|
require 'yajl/json_gem' # for object.to_json, JSON.parse, etc...
|
4
5
|
|
@@ -7,7 +8,6 @@ module Combi
|
|
7
8
|
attr_reader :services
|
8
9
|
|
9
10
|
RPC_DEFAULT_TIMEOUT = 1
|
10
|
-
RPC_MAX_POLLS = 10
|
11
11
|
|
12
12
|
def initialize(options)
|
13
13
|
@options = options
|
@@ -57,7 +57,7 @@ module Combi
|
|
57
57
|
|
58
58
|
def log(message)
|
59
59
|
return unless @debug_mode ||= ENV['DEBUG'] == 'true'
|
60
|
-
puts "#{
|
60
|
+
puts "#{Time.now.to_f} #{self.class.name} #{message}"
|
61
61
|
end
|
62
62
|
|
63
63
|
protected
|
data/lib/combi/buses/http.rb
CHANGED
@@ -71,7 +71,7 @@ module Combi
|
|
71
71
|
def request(name, kind, message, options = {})
|
72
72
|
options[:timeout] ||= RPC_DEFAULT_TIMEOUT
|
73
73
|
|
74
|
-
correlation_id =
|
74
|
+
correlation_id = Combi::Correlation.generate
|
75
75
|
waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
|
76
76
|
url = "#{@options[:remote_api]}#{name}/#{kind}"
|
77
77
|
request_async = EventMachine::HttpRequest.new(url, connection_timeout: options[:timeout]).post(body: message.to_json)
|
data/lib/combi/buses/queue.rb
CHANGED
@@ -46,9 +46,10 @@ module Combi
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def request(name, kind, message, options = {})
|
49
|
+
log "Preparing request: #{name}.#{kind} #{message.inspect}\t|| #{options.inspect}"
|
49
50
|
options[:timeout] ||= RPC_DEFAULT_TIMEOUT
|
50
51
|
options[:routing_key] = name.to_s
|
51
|
-
correlation_id =
|
52
|
+
correlation_id = Combi::Correlation.generate
|
52
53
|
options[:correlation_id] = correlation_id
|
53
54
|
waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
|
54
55
|
queue_service.ready do
|
@@ -212,7 +212,7 @@ module Combi
|
|
212
212
|
kind: kind,
|
213
213
|
payload: message
|
214
214
|
}
|
215
|
-
correlation_id =
|
215
|
+
correlation_id = Combi::Correlation.generate
|
216
216
|
msg[:correlation_id] = correlation_id
|
217
217
|
waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
|
218
218
|
@ready.callback do |r|
|
data/lib/combi/helpers.rb
CHANGED
@@ -4,14 +4,15 @@ module Combi
|
|
4
4
|
|
5
5
|
def self.wait_for(defer, options = {}, &block)
|
6
6
|
options[:timeout] ||= 2
|
7
|
-
poll_time = options[:timeout] / 10
|
8
7
|
resolved = false
|
8
|
+
waiter_thread = Thread.current
|
9
9
|
defer.callback { |response|
|
10
10
|
resolved = true
|
11
11
|
block.call response
|
12
|
+
waiter_thread.wakeup
|
12
13
|
}
|
13
14
|
Timeout::timeout(options[:timeout]) do
|
14
|
-
|
15
|
+
Thread.stop
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
data/lib/combi/queue_service.rb
CHANGED
@@ -4,9 +4,6 @@ require 'amqp/utilities/event_loop_helper'
|
|
4
4
|
module Combi
|
5
5
|
class QueueService
|
6
6
|
|
7
|
-
RPC_DEFAULT_TIMEOUT = 1
|
8
|
-
RPC_WAIT_PERIOD = 0.01
|
9
|
-
|
10
7
|
attr_accessor :rpc_callback
|
11
8
|
|
12
9
|
def initialize(config, options)
|
@@ -22,7 +19,7 @@ module Combi
|
|
22
19
|
|
23
20
|
def log(message)
|
24
21
|
return unless @debug_mode ||= ENV['DEBUG'] == 'true'
|
25
|
-
puts "#{
|
22
|
+
puts "#{Time.now.to_f} #{self.class.name} #{message}"
|
26
23
|
end
|
27
24
|
|
28
25
|
def start
|
@@ -53,7 +50,10 @@ module Combi
|
|
53
50
|
|
54
51
|
def publish(*args, &block)
|
55
52
|
args[0] = args[0].to_json unless args[0].is_a? String
|
56
|
-
@exchange.publish *args
|
53
|
+
@exchange.publish *args do
|
54
|
+
log "Sent to network drivers: #{args.inspect}"
|
55
|
+
block.call if block_given?
|
56
|
+
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def queue(name, options = {}, &block)
|
data/lib/combi/response_store.rb
CHANGED
@@ -21,14 +21,22 @@ module Combi
|
|
21
21
|
|
22
22
|
class EventedWaiter
|
23
23
|
include EM::Deferrable
|
24
|
+
def self.log(message)
|
25
|
+
return unless @debug_mode ||= ENV['DEBUG'] == 'true'
|
26
|
+
puts "#{Time.now.to_f} #{self.name} #{message}"
|
27
|
+
end
|
24
28
|
|
25
29
|
def self.wait_for(key, response_store, timeout)
|
26
|
-
|
30
|
+
t1 = Time.now
|
31
|
+
log "started waiting for #{key}"
|
32
|
+
waiter = new(key, response_store, timeout)
|
27
33
|
response_store.add_waiter(key, waiter)
|
34
|
+
waiter.callback {|r| log "success waiting for #{key}: #{Time.now.to_f - t1.to_f}s" }
|
35
|
+
waiter.errback {|r| log "failed waiting for #{key}: #{Time.now.to_f - t1.to_f}s, #{r.inspect}" }
|
28
36
|
waiter
|
29
37
|
end
|
30
38
|
|
31
|
-
def initialize(key, response_store, timeout
|
39
|
+
def initialize(key, response_store, timeout)
|
32
40
|
self.timeout(timeout, RuntimeError.new(Timeout::Error))
|
33
41
|
end
|
34
42
|
|
data/lib/combi/version.rb
CHANGED
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.4
|
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-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- combi.gemspec
|
153
153
|
- lib/combi.rb
|
154
154
|
- lib/combi/buses/bus.rb
|
155
|
+
- lib/combi/buses/correlation.rb
|
155
156
|
- lib/combi/buses/http.rb
|
156
157
|
- lib/combi/buses/in_process.rb
|
157
158
|
- lib/combi/buses/queue.rb
|
@@ -195,9 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|
197
198
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.2.
|
199
|
+
rubygems_version: 2.2.2
|
199
200
|
signing_key:
|
200
201
|
specification_version: 4
|
201
202
|
summary: Mini Bus for microservices
|
202
203
|
test_files: []
|
203
|
-
has_rdoc:
|