micro-rb 0.1.0.rc2 → 0.1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -0
- data/README.md +11 -8
- data/lib/micro/clients/rpc.rb +2 -2
- data/lib/micro/clients/tcp.rb +39 -0
- data/lib/micro/configuration.rb +10 -10
- data/lib/micro/examples/fib.rb +4 -2
- data/lib/micro/examples/sum.rb +4 -2
- data/lib/micro/examples/sum_tcp.rb +24 -0
- data/lib/micro/request_manager.rb +79 -0
- data/lib/micro/servers/tcp.rb +48 -0
- data/lib/micro/servers/web.rb +9 -120
- data/lib/micro/service_configuration.rb +61 -0
- data/lib/micro/version.rb +1 -1
- data/lib/microrb.rb +5 -0
- data/micro-rb.gemspec +1 -0
- data/templates/bin/app +5 -2
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1b9ae456a543d65ed8a7d4d65edded21fffdf94
|
4
|
+
data.tar.gz: 03e81e3baa4a7985dd955d041347c9bc8140edcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f1f7428fc1e2b9339e2ea837b8ecff2bf43a28a6c29b5aa13470c66fdfe5f0f8aa50cb5d3f8b04f849564ec65ec8e92f2e1575b52c2cbef71953a2cde09b62
|
7
|
+
data.tar.gz: 65e6b5381fe0c9f9c57f24afd047596986cf6af00355fc8c8db8c111e1d302af742ba6cb7aa0c1f8a7006d3bd27328c2eede70a295c3d9a4fa936c265944b2dd
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -67,8 +67,10 @@ class MyHandler
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
service_config = MicroRb::ServiceConfiguration.new(name: :test)
|
71
|
+
service_config.add_handler(MyHandler.new)
|
72
|
+
|
73
|
+
server = MicroRb::Servers::Web.new(service_config)
|
72
74
|
server.start!
|
73
75
|
|
74
76
|
```
|
@@ -81,7 +83,7 @@ Configuration has the following defaults for sidecar endpoint.
|
|
81
83
|
|
82
84
|
`Registy: "/registry"`
|
83
85
|
|
84
|
-
Configuration has the following defaults for api
|
86
|
+
Configuration has the following defaults for the micro api.
|
85
87
|
|
86
88
|
`Host: http://127.0.0.1`
|
87
89
|
|
@@ -97,9 +99,9 @@ MicroRb::Configuration.configure do |c|
|
|
97
99
|
c.sidecar_port = '8080'
|
98
100
|
c.sidecar_registry = '/awesome_registry'
|
99
101
|
|
100
|
-
c.
|
101
|
-
c.
|
102
|
-
c.
|
102
|
+
c.api_host = 'http://mysite.com'
|
103
|
+
c.api_port = '8080'
|
104
|
+
c.api_rpc = '/awesome_micro_rb'
|
103
105
|
end
|
104
106
|
```
|
105
107
|
|
@@ -108,7 +110,8 @@ This works with thin etc because we just pass the options along to the rack serv
|
|
108
110
|
|
109
111
|
```ruby
|
110
112
|
require 'rack/handler/puma'
|
111
|
-
|
113
|
+
service_config = MicroRb::ServiceConfiguration.new(name: :test, server: :puma)
|
114
|
+
server = MicroRb::Servers::Web.new(service_config)
|
112
115
|
```
|
113
116
|
|
114
117
|
Every handler must setup the following requirements at a minimum.
|
@@ -123,7 +126,7 @@ Every handler must include a prtobuf module that has `Request` and `Response` co
|
|
123
126
|
![alt text](https://github.com/amedeiros/micro-rb/blob/master/sum.png)
|
124
127
|
|
125
128
|
|
126
|
-
## Micro API
|
129
|
+
## Micro API
|
127
130
|
|
128
131
|
`micro api --address 0.0.0.0:3002`
|
129
132
|
|
data/lib/micro/clients/rpc.rb
CHANGED
@@ -6,10 +6,10 @@ module MicroRb
|
|
6
6
|
class Rpc
|
7
7
|
include Base
|
8
8
|
|
9
|
-
base_uri MicroRb::Configuration.instance.
|
9
|
+
base_uri MicroRb::Configuration.instance.api_uri
|
10
10
|
|
11
11
|
def self.call(service:, method:, params:, klass_response: nil)
|
12
|
-
response = post(MicroRb::Configuration.instance.
|
12
|
+
response = post(MicroRb::Configuration.instance.api_rpc,
|
13
13
|
options(service: service, method: method, request: params))
|
14
14
|
|
15
15
|
return klass_response.new(response.to_h.symbolize_keys!) if klass_response
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'celluloid/current'
|
5
|
+
require 'celluloid/io'
|
6
|
+
|
7
|
+
module MicroRb
|
8
|
+
module Clients
|
9
|
+
class TCP
|
10
|
+
attr_reader :host, :port
|
11
|
+
|
12
|
+
def initialize(host, port)
|
13
|
+
@host = host
|
14
|
+
@port = port
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(service:, method:, params:, klass_response: nil)
|
18
|
+
response = nil
|
19
|
+
|
20
|
+
Celluloid::IO::TCPSocket.open(host, port) do |sock|
|
21
|
+
msg = { service: service, method: method, params: params }
|
22
|
+
json = MultiJson.encode(msg)
|
23
|
+
sock.write(json)
|
24
|
+
response = MultiJson.decode(sock.readpartial(4096))
|
25
|
+
end
|
26
|
+
|
27
|
+
return klass_response.new(response.to_h.symbolize_keys!) if klass_response
|
28
|
+
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.call(service:, method:, params:, host:, port:, klass_response: nil)
|
33
|
+
new(host, port)
|
34
|
+
.call(service: service, method: method,
|
35
|
+
params: params, klass_response: klass_response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/micro/configuration.rb
CHANGED
@@ -8,8 +8,8 @@ module MicroRb
|
|
8
8
|
# Sidecar settings
|
9
9
|
attr_accessor :sidecar_registry, :sidecar_host, :sidecar_port
|
10
10
|
|
11
|
-
# API
|
12
|
-
attr_accessor :
|
11
|
+
# Micro API settings
|
12
|
+
attr_accessor :api_host, :api_port, :api_rpc
|
13
13
|
|
14
14
|
def self.configure
|
15
15
|
yield(instance) if block_given?
|
@@ -23,12 +23,12 @@ module MicroRb
|
|
23
23
|
"#{sidecar_uri}#{sidecar_registry}"
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
"#{
|
26
|
+
def api_uri
|
27
|
+
"#{api_host}:#{api_port}"
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
"#{
|
30
|
+
def api_rpc_uri
|
31
|
+
"#{api_uri}#{api_rpc}"
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -41,10 +41,10 @@ module MicroRb
|
|
41
41
|
self.sidecar_registry ||= '/registry'
|
42
42
|
self.sidecar_port ||= '8081'
|
43
43
|
|
44
|
-
# Default API
|
45
|
-
self.
|
46
|
-
self.
|
47
|
-
self.
|
44
|
+
# Default micro API settings
|
45
|
+
self.api_host ||= 'http://127.0.0.1'
|
46
|
+
self.api_rpc ||= '/rpc'
|
47
|
+
self.api_port ||= '3002'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/micro/examples/fib.rb
CHANGED
@@ -37,8 +37,10 @@ class FibHandler
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
service_config = MicroRb::ServiceConfiguration.new(name: :test, metadata: { example: 'Fib Service' }, server: :puma)
|
41
|
+
service_config.add_handler(FibHandler.new)
|
42
|
+
|
43
|
+
server = MicroRb::Servers::Web.new(service_config)
|
42
44
|
server.start!
|
43
45
|
|
44
46
|
# MicroRb::Clients::Rpc.call(service: :test, method: 'FibHandler.fibonacci', params: { n: 15 } )
|
data/lib/micro/examples/sum.rb
CHANGED
@@ -17,6 +17,8 @@ class MyHandler
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
service_config = MicroRb::ServiceConfiguration.new(name: :test, metadata: { example: 'Service' })
|
21
|
+
service_config.add_handler(MyHandler.new)
|
22
|
+
|
23
|
+
server = MicroRb::Servers::Web.new(service_config)
|
22
24
|
server.start!
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../../../lib/microrb'
|
5
|
+
require_relative '../examples/proto/sum_pb'
|
6
|
+
|
7
|
+
class TcpSumExample
|
8
|
+
include MicroRb::Handler
|
9
|
+
include MicroRb::SumHandler
|
10
|
+
|
11
|
+
handler name: :test, metadata: { hello: 'Micro-Rb' }, rpc_method: :sum
|
12
|
+
|
13
|
+
def sum(request: Request.new, response: Response.new)
|
14
|
+
response.total = request.a + request.b
|
15
|
+
|
16
|
+
response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
service_config = MicroRb::ServiceConfiguration.new(name: :tcp_example)
|
21
|
+
service_config.add_handler(TcpSumExample.new)
|
22
|
+
|
23
|
+
server = MicroRb::Servers::TCP.new(service_config)
|
24
|
+
server.start!
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module MicroRb
|
5
|
+
class RequestManager
|
6
|
+
attr_reader :handler_manager
|
7
|
+
|
8
|
+
REQUIRED_TYPES = { method: [String], params: [Hash, Array],
|
9
|
+
id: [String, Integer, NilClass] }.freeze
|
10
|
+
|
11
|
+
REQUIRED_KEYS = ['method'].freeze
|
12
|
+
|
13
|
+
def initialize(handler_manager = MicroRb::HandlerManager.new)
|
14
|
+
@handler_manager = handler_manager
|
15
|
+
# Add the default debug handler
|
16
|
+
handler_manager.add_handler(MicroRb::Handlers::Debug.new)
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle_request(request)
|
20
|
+
response = nil
|
21
|
+
|
22
|
+
begin
|
23
|
+
request = decode(request)
|
24
|
+
response = create_response(request) if valid_request?(request)
|
25
|
+
response ||= error_response(MicroRb::Servers::Error::InvalidRequest.new, request)
|
26
|
+
rescue MultiJson::ParseError => e
|
27
|
+
MicroRb.logger.warn(e)
|
28
|
+
response = error_response(MicroRb::Servers::Error::ParseError.new)
|
29
|
+
rescue StandardError => e
|
30
|
+
MicroRb.logger.warn(e)
|
31
|
+
response = error_response(MicroRb::Servers::Error::InternalError.new(e), request)
|
32
|
+
end
|
33
|
+
|
34
|
+
MultiJson.encode(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_response(request)
|
40
|
+
method = request[:method].strip.to_sym
|
41
|
+
params = Array.wrap(request[:params]).map(&:symbolize_keys)
|
42
|
+
|
43
|
+
unless handler_manager.rpc_method?(method)
|
44
|
+
return error_response(MicroRb::Servers::Error::MethodNotFound.new(method), request)
|
45
|
+
end
|
46
|
+
|
47
|
+
response = handler_manager.call_rpc_method(method, params)
|
48
|
+
|
49
|
+
success_response(request, response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_request?(request)
|
53
|
+
return false unless request.is_a?(Hash)
|
54
|
+
|
55
|
+
REQUIRED_KEYS.each do |key|
|
56
|
+
return false unless request.key?(key)
|
57
|
+
end
|
58
|
+
|
59
|
+
REQUIRED_TYPES.each do |key, types|
|
60
|
+
return false if request.key?(key) &&
|
61
|
+
types.none? { |type| request[key].is_a?(type) }
|
62
|
+
end
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def success_response(request, result)
|
68
|
+
{ result: result, id: request['id'] }
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_response(error, request = {})
|
72
|
+
{ error: error.to_h, id: request['id'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
def decode(request)
|
76
|
+
MultiJson.decode(request).with_indifferent_access
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'celluloid/current'
|
5
|
+
require 'celluloid/io'
|
6
|
+
|
7
|
+
module MicroRb
|
8
|
+
module Servers
|
9
|
+
class TCP
|
10
|
+
include Celluloid::IO
|
11
|
+
|
12
|
+
attr_reader :server, :service_config
|
13
|
+
|
14
|
+
finalizer :shutdown
|
15
|
+
|
16
|
+
def initialize(service_config)
|
17
|
+
@service_config = service_config
|
18
|
+
@server = TCPServer.new(service_config.host, service_config.port)
|
19
|
+
end
|
20
|
+
|
21
|
+
def shutdown
|
22
|
+
@server&.close
|
23
|
+
end
|
24
|
+
|
25
|
+
def start!
|
26
|
+
service_config.register!
|
27
|
+
loop { async.handle_connection @server.accept }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def handle_connection(socket)
|
33
|
+
_, port, host = socket.peeraddr
|
34
|
+
MicroRb.logger.debug("*** Received connection from #{host}:#{port}")
|
35
|
+
|
36
|
+
loop do
|
37
|
+
request = socket.readpartial(4096)
|
38
|
+
response = service_config.request_manager.handle_request(request)
|
39
|
+
socket.write(response)
|
40
|
+
socket.flush
|
41
|
+
end
|
42
|
+
rescue EOFError => e
|
43
|
+
MicroRb.logger.debug("*** #{host}:#{port} disconnected", e)
|
44
|
+
socket.close
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/micro/servers/web.rb
CHANGED
@@ -4,70 +4,21 @@
|
|
4
4
|
require 'rack'
|
5
5
|
require 'rack/request'
|
6
6
|
require 'rack/response'
|
7
|
-
require 'multi_json'
|
8
7
|
|
9
8
|
module MicroRb
|
10
9
|
module Servers
|
11
10
|
class Web
|
12
|
-
attr_accessor :
|
13
|
-
:handler_manager, :name, :node_id, :server
|
11
|
+
attr_accessor :service_config, :server
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
REQUIRED_KEYS = ['method'].freeze
|
19
|
-
|
20
|
-
def initialize(name, opts = {})
|
21
|
-
self.port = opts.delete(:port) || 3000
|
22
|
-
self.host = opts.delete(:host) || '0.0.0.0'
|
23
|
-
self.metadata = opts.delete(:metadata) || {}
|
24
|
-
self.version = opts.delete(:version) || '0.0.1'
|
25
|
-
self.debug = opts.delete(:debug)
|
26
|
-
self.name = name
|
27
|
-
self.node_id = "#{name}-#{SecureRandom.uuid}"
|
28
|
-
self.handler_manager = MicroRb::HandlerManager.new
|
29
|
-
|
30
|
-
server_opts = opts.merge(Host: host, Port: port, app: self)
|
13
|
+
def initialize(service_config)
|
14
|
+
self.service_config = service_config
|
15
|
+
server_opts = service_config.options.merge(Host: service_config.host, Port: service_config.port, app: self)
|
31
16
|
self.server = Rack::Server.new(server_opts)
|
32
17
|
end
|
33
18
|
|
34
|
-
def add_handler(handler)
|
35
|
-
handler_manager.add_handler(handler)
|
36
|
-
end
|
37
|
-
|
38
19
|
def start!
|
39
|
-
|
40
|
-
add_handler(MicroRb::Handlers::Debug.new)
|
41
|
-
|
42
|
-
# Value will raise an error on anything not 2XX
|
43
|
-
MicroRb::Clients::Sidecar.register(self).response.value
|
44
|
-
|
45
|
-
if debug
|
46
|
-
MicroRb.logger
|
47
|
-
.debug("Registered #{name}:#{host}:#{port} with sidecar.")
|
48
|
-
end
|
49
|
-
|
50
|
-
add_finalizer_hook!
|
20
|
+
service_config.register!
|
51
21
|
server.start
|
52
|
-
rescue Net::HTTPFatalError => e
|
53
|
-
msg = "Sidecar error: #{e.message}"
|
54
|
-
MicroRb.logger.warn(msg)
|
55
|
-
|
56
|
-
raise MicroRb::Servers::Error::ServerError.new(-32_000, msg)
|
57
|
-
end
|
58
|
-
|
59
|
-
def to_h
|
60
|
-
{
|
61
|
-
version: version,
|
62
|
-
metadata: metadata,
|
63
|
-
name: name,
|
64
|
-
nodes: [{ id: node_id, address: host, port: port }],
|
65
|
-
endpoints: handler_manager.endpoints
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
def to_json
|
70
|
-
to_h.to_json
|
71
22
|
end
|
72
23
|
|
73
24
|
#
|
@@ -79,73 +30,11 @@ module MicroRb
|
|
79
30
|
|
80
31
|
return resp.finish unless req.post?
|
81
32
|
|
82
|
-
|
83
|
-
|
84
|
-
end
|
33
|
+
request = req.body.read
|
34
|
+
response = service_config.request_manager.handle_request(request)
|
85
35
|
|
86
|
-
|
87
|
-
|
88
|
-
params = request['params'].map(&:symbolize_keys!)
|
89
|
-
|
90
|
-
return error_response(Error::MethodNotFound.new(method), request) unless handler_manager.rpc_method?(method)
|
91
|
-
|
92
|
-
response = handler_manager.call_rpc_method(method, params)
|
93
|
-
|
94
|
-
success_response(request, response)
|
95
|
-
end
|
96
|
-
|
97
|
-
def handle_request(request)
|
98
|
-
request = parse_request(request)
|
99
|
-
response = nil
|
100
|
-
|
101
|
-
begin
|
102
|
-
response = create_response(request) if valid_request?(request)
|
103
|
-
response ||= error_response(Error::InvalidRequest.new, request)
|
104
|
-
rescue MultiJson::ParseError => e
|
105
|
-
MicroRb.logger.warn(e)
|
106
|
-
response = error_response(Error::ParseError.new)
|
107
|
-
rescue StandardError => e
|
108
|
-
MicroRb.logger.warn(e)
|
109
|
-
response = error_response(Error::InternalError.new(e), request)
|
110
|
-
end
|
111
|
-
|
112
|
-
MultiJson.encode(response)
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def valid_request?(request)
|
118
|
-
return false unless request.is_a?(Hash)
|
119
|
-
|
120
|
-
REQUIRED_KEYS.each do |key|
|
121
|
-
return false unless request.key?(key)
|
122
|
-
end
|
123
|
-
|
124
|
-
REQUIRED_TYPES.each do |key, types|
|
125
|
-
return false if request.key?(key) &&
|
126
|
-
types.none? { |type| request[key].is_a?(type) }
|
127
|
-
end
|
128
|
-
|
129
|
-
true
|
130
|
-
end
|
131
|
-
|
132
|
-
def success_response(request, result)
|
133
|
-
{ result: result, id: request['id'] }
|
134
|
-
end
|
135
|
-
|
136
|
-
def error_response(error, request = {})
|
137
|
-
{ error: error.to_h, id: request['id'] }
|
138
|
-
end
|
139
|
-
|
140
|
-
def add_finalizer_hook!
|
141
|
-
at_exit do
|
142
|
-
MicroRb.logger.debug("Shutting down #{name}:#{host}:#{port}") if debug
|
143
|
-
MicroRb::Clients::Sidecar.remove(self)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def parse_request(request)
|
148
|
-
MultiJson.decode(request)
|
36
|
+
resp.write(response)
|
37
|
+
resp.finish
|
149
38
|
end
|
150
39
|
end
|
151
40
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module MicroRb
|
5
|
+
class ServiceConfiguration
|
6
|
+
attr_accessor :name, :port, :host, :metadata,
|
7
|
+
:version, :node_id, :options, :request_manager
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
self.port = options.delete(:port) || 3000
|
11
|
+
self.host = options.delete(:host) || '0.0.0.0'
|
12
|
+
self.metadata = options.delete(:metadata) || {}
|
13
|
+
self.version = options.delete(:version) || '0.0.1'
|
14
|
+
self.name = options.delete(:name)
|
15
|
+
self.node_id = "#{name}-#{SecureRandom.uuid}"
|
16
|
+
self.options = options
|
17
|
+
self.request_manager = MicroRb::RequestManager.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_handler(handler)
|
21
|
+
request_manager.handler_manager.add_handler(handler)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_h
|
25
|
+
{
|
26
|
+
version: version,
|
27
|
+
metadata: metadata,
|
28
|
+
name: name,
|
29
|
+
nodes: [{ id: node_id, address: host, port: port }],
|
30
|
+
endpoints: request_manager.handler_manager.endpoints
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_json
|
35
|
+
to_h.to_json
|
36
|
+
end
|
37
|
+
|
38
|
+
def register!
|
39
|
+
# Value will raise an error on anything not 2XX
|
40
|
+
MicroRb::Clients::Sidecar.register(self).response.value
|
41
|
+
|
42
|
+
MicroRb.logger.debug("Registered #{name}:#{host}:#{port} with sidecar.")
|
43
|
+
|
44
|
+
add_finalizer_hook!
|
45
|
+
rescue Net::HTTPFatalError => e
|
46
|
+
msg = "Sidecar error: #{e.message}"
|
47
|
+
MicroRb.logger.warn(msg)
|
48
|
+
|
49
|
+
raise MicroRb::Servers::Error::ServerError.new(-32_000, msg)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def add_finalizer_hook!
|
55
|
+
at_exit do
|
56
|
+
MicroRb.logger.debug("Shutting down #{name}:#{host}:#{port}")
|
57
|
+
MicroRb::Clients::Sidecar.remove(self)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/micro/version.rb
CHANGED
data/lib/microrb.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'active_support/all'
|
6
6
|
require 'semantic_logger'
|
7
|
+
require 'multi_json'
|
7
8
|
|
8
9
|
module MicroRb
|
9
10
|
include SemanticLogger::Loggable
|
@@ -15,12 +16,16 @@ end
|
|
15
16
|
|
16
17
|
require 'micro/version'
|
17
18
|
require 'micro/configuration'
|
19
|
+
require 'micro/service_configuration'
|
18
20
|
require 'micro/clients/base'
|
19
21
|
require 'micro/clients/sidecar'
|
20
22
|
require 'micro/clients/rpc'
|
21
23
|
require 'micro/clients/http'
|
24
|
+
require 'micro/clients/tcp'
|
22
25
|
require 'micro/handler'
|
23
26
|
require 'micro/handler_manager'
|
27
|
+
require 'micro/request_manager'
|
24
28
|
require 'micro/servers/web'
|
25
29
|
require 'micro/servers/error'
|
30
|
+
require 'micro/servers/tcp'
|
26
31
|
require 'micro/handlers/debug'
|
data/micro-rb.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
28
|
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
|
29
29
|
spec.add_development_dependency 'shoulda', '~> 3.5'
|
30
|
+
spec.add_development_dependency 'mocha', '~> 1.2'
|
30
31
|
|
31
32
|
spec.add_runtime_dependency 'activesupport', '~> 5.1', '>= 5.1.0'
|
32
33
|
spec.add_runtime_dependency 'httparty', '~> 0.14.0'
|
data/templates/bin/app
CHANGED
@@ -12,6 +12,9 @@ ActiveRecord::Base.establish_connection(
|
|
12
12
|
password: ENV[:DB_PASSWORD]
|
13
13
|
)
|
14
14
|
<% end %>
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
service_config = MicroRb::ServiceConfiguration(name: :example_service)
|
17
|
+
service_config.add_handler(<%= @class_name %>::ExampleHandler.new)
|
18
|
+
|
19
|
+
server = MicroRb::Servers::Web.new(service_config)
|
17
20
|
server.start!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Medeiros
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: activesupport
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,6 +235,7 @@ files:
|
|
221
235
|
- lib/micro/clients/http.rb
|
222
236
|
- lib/micro/clients/rpc.rb
|
223
237
|
- lib/micro/clients/sidecar.rb
|
238
|
+
- lib/micro/clients/tcp.rb
|
224
239
|
- lib/micro/configuration.rb
|
225
240
|
- lib/micro/examples/fib.rb
|
226
241
|
- lib/micro/examples/proto/fib.proto
|
@@ -228,14 +243,18 @@ files:
|
|
228
243
|
- lib/micro/examples/proto/sum.proto
|
229
244
|
- lib/micro/examples/proto/sum_pb.rb
|
230
245
|
- lib/micro/examples/sum.rb
|
246
|
+
- lib/micro/examples/sum_tcp.rb
|
231
247
|
- lib/micro/handler.rb
|
232
248
|
- lib/micro/handler_manager.rb
|
233
249
|
- lib/micro/handlers/debug.rb
|
234
250
|
- lib/micro/project_generator.rb
|
235
251
|
- lib/micro/proto/debug.proto
|
236
252
|
- lib/micro/proto/debug_pb.rb
|
253
|
+
- lib/micro/request_manager.rb
|
237
254
|
- lib/micro/servers/error.rb
|
255
|
+
- lib/micro/servers/tcp.rb
|
238
256
|
- lib/micro/servers/web.rb
|
257
|
+
- lib/micro/service_configuration.rb
|
239
258
|
- lib/micro/version.rb
|
240
259
|
- lib/microrb.rb
|
241
260
|
- micro-rb.gemspec
|