mather-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/mather-rb-server +42 -0
- data/src/lib/mather.rb +9 -0
- data/src/svc/mather.rb +53 -0
- data/src/svc/proto/mather.proto +27 -0
- data/src/svc/proto/mather_pb.rb +30 -0
- data/src/svc/proto/mather_services_pb.rb +24 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae32fb0c47fb2d4ec9edb4c7bf64b29f133e8be9b979754a3b1e28fea897fe59
|
4
|
+
data.tar.gz: 0b8f3103cd7d9de21b8bed68d083b2016c8c02d3acea6871496e2c5c352be55e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bcf2aa53787ac399ab1d749f184a9a9edecb42b1bfc5c0de558c28de459ed211be258c48c7cbed28bea60bcc2f942b40fb89dd749422011fb0315716b9d16ae
|
7
|
+
data.tar.gz: 8fff21bc48d5d844cf3cd9723ad975ba1729045f29cf9f7d9ea59bf7d85cd1e76f4ce4793e2e1dafb75cc5f560edfd807b01fdddcc05315604650b9e4383e4fe
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
3
|
+
lib_dir = File.join(this_dir, '..', 'src', 'svc')
|
4
|
+
$LOAD_PATH.unshift(lib_dir)
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'grpc'
|
9
|
+
require 'mather'
|
10
|
+
require 'commander'
|
11
|
+
|
12
|
+
class MatherServer
|
13
|
+
include Commander::Methods
|
14
|
+
|
15
|
+
def run
|
16
|
+
program :name, 'Mather Server (in Ruby)'
|
17
|
+
program :version, '1.0.0'
|
18
|
+
program :description,
|
19
|
+
'A simple math gRPC microservice, for the purpose of learning and evaluating Ruby and gRPC.'
|
20
|
+
|
21
|
+
command :start do |c|
|
22
|
+
c.syntax = 'mather-rb-server start'
|
23
|
+
c.description = 'Starts the server'
|
24
|
+
c.option '--port PORT', String, "Server's port (by default :30000)"
|
25
|
+
|
26
|
+
c.action do |args, options|
|
27
|
+
port = options.port || ':30000'
|
28
|
+
|
29
|
+
s = GRPC::RpcServer.new
|
30
|
+
s.add_http2_port("0.0.0.0#{port}", :this_port_is_insecure)
|
31
|
+
s.handle(MatherService)
|
32
|
+
|
33
|
+
puts "Server started on port #{port}"
|
34
|
+
s.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT'])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
run!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
MatherServer.new.run
|
data/src/lib/mather.rb
ADDED
data/src/svc/mather.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
2
|
+
proto_dir = File.join(this_dir, 'proto')
|
3
|
+
lib_dir = File.join(this_dir, '..', 'lib')
|
4
|
+
$LOAD_PATH.unshift(proto_dir)
|
5
|
+
$LOAD_PATH.unshift(lib_dir)
|
6
|
+
|
7
|
+
require 'mather_services_pb'
|
8
|
+
require 'grpc'
|
9
|
+
require 'mather'
|
10
|
+
|
11
|
+
class MatherService < Mather::Math::Service
|
12
|
+
def add(req, _)
|
13
|
+
if req.First == 0
|
14
|
+
raise GRPC::BadStatus.new(
|
15
|
+
GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
16
|
+
'Could not add, `First` has not been provided'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
if req.Second == 0
|
21
|
+
raise GRPC::BadStatus.new(
|
22
|
+
GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
23
|
+
'Could not add, `Second` has not been provided'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Adding #{req.First} to #{req.Second}"
|
28
|
+
|
29
|
+
Mather::MathAddReply.new(Result: MatherLib.new.add(req.First, req.Second))
|
30
|
+
end
|
31
|
+
|
32
|
+
def subtract(req, _)
|
33
|
+
if req.First == 0
|
34
|
+
raise GRPC::BadStatus.new(
|
35
|
+
GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
36
|
+
'Could not add, `First` has not been provided'
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
if req.Second == 0
|
41
|
+
raise GRPC::BadStatus.new(
|
42
|
+
GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
43
|
+
'Could not add, `Second` has not been provided'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
puts "Subtracting #{req.First} from #{req.Second}"
|
48
|
+
|
49
|
+
Mather::MathSubtractReply.new(
|
50
|
+
Result: MatherLib.new.subtract(req.First, req.Second)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package mather;
|
4
|
+
|
5
|
+
// Service math adds and subtracts numbers
|
6
|
+
service Math {
|
7
|
+
rpc Add(MathAddArgs) returns (MathAddReply) {};
|
8
|
+
rpc Subtract(MathSubtractArgs) returns (MathSubtractReply) {};
|
9
|
+
}
|
10
|
+
|
11
|
+
// MathAddArgs are the arguments for an addition
|
12
|
+
message MathAddArgs {
|
13
|
+
int64 First = 1;
|
14
|
+
int64 Second = 2;
|
15
|
+
}
|
16
|
+
|
17
|
+
// MathAddReply is the reply for an addition
|
18
|
+
message MathAddReply { int64 Result = 3; }
|
19
|
+
|
20
|
+
// MathSubtractArgs are the arguments for a subtraction
|
21
|
+
message MathSubtractArgs {
|
22
|
+
int64 First = 1;
|
23
|
+
int64 Second = 2;
|
24
|
+
}
|
25
|
+
|
26
|
+
// MathSubtractReply is the reply for a subtraction
|
27
|
+
message MathSubtractReply { int64 Result = 3; }
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: mather.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("mather.proto", :syntax => :proto3) do
|
8
|
+
add_message "mather.MathAddArgs" do
|
9
|
+
optional :First, :int64, 1
|
10
|
+
optional :Second, :int64, 2
|
11
|
+
end
|
12
|
+
add_message "mather.MathAddReply" do
|
13
|
+
optional :Result, :int64, 3
|
14
|
+
end
|
15
|
+
add_message "mather.MathSubtractArgs" do
|
16
|
+
optional :First, :int64, 1
|
17
|
+
optional :Second, :int64, 2
|
18
|
+
end
|
19
|
+
add_message "mather.MathSubtractReply" do
|
20
|
+
optional :Result, :int64, 3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Mather
|
26
|
+
MathAddArgs = Google::Protobuf::DescriptorPool.generated_pool.lookup("mather.MathAddArgs").msgclass
|
27
|
+
MathAddReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("mather.MathAddReply").msgclass
|
28
|
+
MathSubtractArgs = Google::Protobuf::DescriptorPool.generated_pool.lookup("mather.MathSubtractArgs").msgclass
|
29
|
+
MathSubtractReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("mather.MathSubtractReply").msgclass
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: mather.proto for package 'mather'
|
3
|
+
|
4
|
+
require 'grpc'
|
5
|
+
require 'mather_pb'
|
6
|
+
|
7
|
+
module Mather
|
8
|
+
module Math
|
9
|
+
# Service math adds and subtracts numbers
|
10
|
+
class Service
|
11
|
+
|
12
|
+
include GRPC::GenericService
|
13
|
+
|
14
|
+
self.marshal_class_method = :encode
|
15
|
+
self.unmarshal_class_method = :decode
|
16
|
+
self.service_name = 'mather.Math'
|
17
|
+
|
18
|
+
rpc :Add, MathAddArgs, MathAddReply
|
19
|
+
rpc :Subtract, MathSubtractArgs, MathSubtractReply
|
20
|
+
end
|
21
|
+
|
22
|
+
Stub = Service.rpc_stub_class
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mather-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felix Pojtinger
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: grpc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.25'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.25'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: grpc-tools
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.25'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.25'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ptools
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: os
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- felix@pojtinger.com
|
114
|
+
executables:
|
115
|
+
- mather-rb-server
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- exe/mather-rb-server
|
120
|
+
- src/lib/mather.rb
|
121
|
+
- src/svc/mather.rb
|
122
|
+
- src/svc/proto/mather.proto
|
123
|
+
- src/svc/proto/mather_pb.rb
|
124
|
+
- src/svc/proto/mather_services_pb.rb
|
125
|
+
homepage: https://pojntfx.github.io/mather-rb/
|
126
|
+
licenses:
|
127
|
+
- AGPL-3.0
|
128
|
+
metadata:
|
129
|
+
allowed_push_host: https://rubygems.org/
|
130
|
+
homepage_uri: https://pojntfx.github.io/mather-rb/
|
131
|
+
source_code_uri: https://github.com/pojntfx/mather-rb
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- src
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Simple gRPC microservice that does math.
|
151
|
+
test_files: []
|