Permalink
Browse files

setup basic grpc app structure

  • Loading branch information...
theRealNG committed Feb 13, 2018
0 parents commit 12906621bc2f7dc27191d9504761a44c5a483a2d
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
.env
coverage
# Ignore bundler config.
/.bundle
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
.idea
.byebug_history
log
# vim swap files
*.swp
*.swo
#dotenv
.env
.env*
discovery.cache
/.sass-cache
# Ignore precompiled assets
*.DS_Store
# Ctags
tags
@@ -0,0 +1 @@
2.4.3@student_details_service
@@ -0,0 +1,7 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'grpc'
gem 'grpc-tools'
gem 'pry'
@@ -0,0 +1,54 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
coderay (1.1.2)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
google-protobuf (3.5.1.2)
googleapis-common-protos-types (1.0.1)
google-protobuf (~> 3.0)
googleauth (0.6.2)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
logging (~> 2.0)
memoist (~> 0.12)
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
grpc (1.8.7)
google-protobuf (~> 3.1)
googleapis-common-protos-types (~> 1.0.0)
googleauth (>= 0.5.1, < 0.7)
grpc-tools (1.8.7)
jwt (2.1.0)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
memoist (0.16.0)
method_source (0.9.0)
multi_json (1.13.1)
multipart-post (2.0.0)
os (0.9.6)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.2)
signet (0.8.1)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
PLATFORMS
ruby
DEPENDENCIES
grpc
grpc-tools
pry
BUNDLED WITH
1.16.1
3 app.rb
@@ -0,0 +1,3 @@
Dir[File.expand_path 'app/*.rb'].each do |file|
require file
end
@@ -0,0 +1,3 @@
Dir[File.expand_path './app/controllers/*.rb'].each do |file|
require file
end
@@ -0,0 +1,7 @@
class HelloController
def self.say_hello(request)
StudentsDetails::HelloResponse.new(
body: "Hello #{request.name}"
)
end
end

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,13 @@
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require './lib/protos/students_details_services_pb'
require './app'
class StudentsDetailsService < StudentsDetails::StudentsDetailsService::Service
def hello(request, _unused_call)
HelloController.say_hello(request)
end
end
@@ -0,0 +1,14 @@
syntax = 'proto3';
package students_details;
service StudentsDetailsService {
rpc Hello( HelloRequest ) returns ( HelloResponse ) {}
}
message HelloRequest {
string name = 1;
}
message HelloResponse {
string body = 1;
}
@@ -0,0 +1,32 @@
require 'rubygems'
require 'bundler/setup'
require './lib/students_details_service'
require 'logging'
Bundler.require(:default)
module GRPC
extend Logging.globally
end
Logging.logger.root.appenders = Logging.appenders.stdout
Logging.logger.root.level = :info
class StudentsDetailsServer
class << self
def start
start_grpc_server
end
private
def start_grpc_server
@server = GRPC::RpcServer.new
@server.add_http2_port('0.0.0.0:50052', :this_port_is_insecure)
@server.handle(StudentsDetailsService)
@server.run_till_terminated
end
end
end
StudentsDetailsServer.start
@@ -0,0 +1,11 @@
require './lib/protos/students_details_services_pb'
require 'grpc'
stub = StudentsDetails::StudentsDetailsService::Stub.new(
'0.0.0.0:50052', :this_channel_is_insecure
)
request = StudentsDetails::HelloRequest.new(name: "Harry")
response = stub.hello(request)
puts response.body

0 comments on commit 1290662

Please sign in to comment.