Created
November 1, 2016 14:25
-
-
Save matiasinsaurralde/5899b5b40f028f31242ceb757df0b5b3 to your computer and use it in GitHub Desktop.
server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require '../../bindings/ruby/dispatcher' | |
require '../../bindings/ruby/coprocess_session_state_pb' | |
require 'json' | |
class SampleServer < Coprocess::Dispatcher::Service | |
# Implements a dynamic dispatcher for CP objects, this class should provide methods for your hooks (see MyPreMiddleware). | |
def dispatch(coprocess_object, _unused_call) | |
begin | |
if self.respond_to?(coprocess_object.hook_name) | |
coprocess_object = self.send(coprocess_object.hook_name, coprocess_object) | |
else | |
raise Coprocess::Dispatcher::HookNotImplemented | |
end | |
rescue Coprocess::Dispatcher::HookNotImplemented | |
puts "Hook not implemented: #{coprocess_object.hook_name}" | |
rescue Exception => e | |
puts "Couldn't dispatch: #{e}" | |
end | |
return coprocess_object | |
end | |
def MyPreMiddleware(coprocess_object) | |
coprocess_object.request.set_headers["rubyheader"] = "rubyvalue" | |
return coprocess_object | |
end | |
end | |
def main | |
s = GRPC::RpcServer.new | |
s.add_http2_port('0.0.0.0:5555', :this_port_is_insecure) | |
s.handle(SampleServer) | |
s.run_till_terminated | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment