kimchi 0.0.2 → 0.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 692b1c5b73b1c9aca217219ad4fa844e95c00ba8
|
4
|
+
data.tar.gz: 529260fb62c822cfd3b579ae748dffa6292165a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b6f5f6b8fd1f64e0fd6ff966ba2c84f809fb4363bc3d066fd38cbb459dec36b4e09ec1dab446d9d1cbcdbe9818e22026b4c7194d093c2e61710ba55fe68ad22
|
7
|
+
data.tar.gz: 6dcb65f0b93c370be8d6da1576acc27766f3eaae43b9b7a800a9ced8fb9028a2e1da01949497f5b6571b54b3167591d02a51d5e2844959fa9f067633326df288
|
data/lib/kimchi/version.rb
CHANGED
data/lib/wire.rb
CHANGED
@@ -5,13 +5,15 @@ require "bunny"
|
|
5
5
|
module Wire
|
6
6
|
|
7
7
|
class Function
|
8
|
-
def initialize(name, signature = nil,
|
8
|
+
def initialize(name, signature = nil, result_type = nil, native_type = nil)
|
9
9
|
@name = name
|
10
10
|
@signature = signature
|
11
|
-
@
|
11
|
+
@result_type = result_type
|
12
|
+
@native_type = native_type
|
12
13
|
end
|
14
|
+
|
13
15
|
def to_json
|
14
|
-
"{\"endpoint\": \"#{@name}\"" + ((@signature == nil) ? "" : ", \"signature\": #{@signature}") + ((@
|
16
|
+
"{\"endpoint\": \"#{@name}\"" + ((@signature == nil) ? "" : ", \"signature\": #{@signature}") + ((@result_type == nil) ? "" : ", \"resultType\": \"#{@result_type}\"") + ((@native_type == nil) ? "" : ", \"nativeType\": \"#{@native_type}\"") + "}"
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -21,8 +23,34 @@ module Wire
|
|
21
23
|
@arguments = arguments
|
22
24
|
@contexts = contexts
|
23
25
|
end
|
26
|
+
|
24
27
|
def to_json
|
25
|
-
|
28
|
+
"{\"address\": #{@function.to_json}, \"body\": #{@arguments.to_json}, \"contexts\": #{@contexts}}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class MessageCallback
|
33
|
+
def initialize (message_hash, message_id, callback, timeout_seconds)
|
34
|
+
@semaphore = Mutex.new
|
35
|
+
@callback = callback
|
36
|
+
@result = nil
|
37
|
+
|
38
|
+
Thread.new do
|
39
|
+
sleep(timeout_seconds)
|
40
|
+
message_hash.delete(message_id)
|
41
|
+
@semaphore.synchronize do
|
42
|
+
if @result.nil?
|
43
|
+
callback.timeout
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_result (result)
|
50
|
+
@semaphore.synchronize do
|
51
|
+
@result = result
|
52
|
+
@callback.complete(@result)
|
53
|
+
end
|
26
54
|
end
|
27
55
|
end
|
28
56
|
|
@@ -34,6 +62,8 @@ module Wire
|
|
34
62
|
@uuid = UUID.new
|
35
63
|
@caller_id = @uuid.generate
|
36
64
|
|
65
|
+
@message_hash = {}
|
66
|
+
|
37
67
|
request_channel = @connection.create_channel
|
38
68
|
@request_exchange = request_channel.topic("#{service_name}.request")
|
39
69
|
|
@@ -43,15 +73,39 @@ module Wire
|
|
43
73
|
response_queue = response_channel.queue("#{response_queue_name}", {:durable => false, :exclusive => true, :auto_delete => true})
|
44
74
|
|
45
75
|
response_queue.bind(response_exchange, :routing_key => "#{@caller_id}").subscribe do |delivery_info, metadata, payload|
|
46
|
-
|
47
|
-
|
76
|
+
if (message_callback = @message_hash[metadata[:correlation_id]]) != nil
|
77
|
+
result_body = JSON.parse(payload)
|
78
|
+
message_callback.set_result(result_body)
|
79
|
+
end
|
48
80
|
end
|
49
81
|
end
|
50
82
|
|
51
83
|
def transmit_in_only(version, invocation_signal)
|
84
|
+
@request_exchange.publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{@uuid.generate}", :timestamp => Time.new.to_i)
|
85
|
+
end
|
52
86
|
|
53
|
-
|
87
|
+
def transmit(version, invocation_signal, callback, timeout_seconds)
|
88
|
+
message_id = "#{@uuid.generate}".freeze
|
89
|
+
@message_hash[message_id] = MessageCallback.new(@message_hash, message_id, callback, timeout_seconds)
|
90
|
+
@request_exchange.publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{message_id}", :timestamp => Time.new.to_i)
|
54
91
|
end
|
55
92
|
end
|
56
93
|
|
57
|
-
|
94
|
+
class HttpTransport
|
95
|
+
def initialize (host, port)
|
96
|
+
@host = host
|
97
|
+
@port = port
|
98
|
+
end
|
99
|
+
def transmit (version, invocation_signal, callback, timeout_seconds)
|
100
|
+
uri = URI("#{@host}:#{@port}/api/message")
|
101
|
+
headers = {"Content-Type" => "application/json", "X-Icix-Version" => "#{version}"}
|
102
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
103
|
+
|
104
|
+
res = http.post(uri.path, invocation_signal.to_json, headers)
|
105
|
+
res.code.should == '200'
|
106
|
+
|
107
|
+
response = JSON.parse res.body
|
108
|
+
callback.complete(response)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kimchi
|
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
|
- Taylor Gautier
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -80,10 +80,9 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- kimchi.gemspec
|
83
|
-
- lib/
|
83
|
+
- lib/cucumber/features/step_definitions/common.rb
|
84
84
|
- lib/kimchi/version.rb
|
85
85
|
- lib/wire.rb
|
86
|
-
- src/main/ruby/kimchi/wire/foo.rb
|
87
86
|
homepage: http://www.icix.com
|
88
87
|
licenses:
|
89
88
|
- MIT
|
File without changes
|