Sha256: 59c305ff0a982e11f4042bae717f343776214ca5db758178925b706deb69064b
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
# coding: utf-8 # frozen_string_literal: true require_relative '../../../lib/microrb' require_relative '../examples/proto/fib_pb' require 'rack/handler/puma' # This example was to show the usage of puma as well as making RPC calls to services. class FibHandler include MicroRb::Handler include MicroRb::FibPb handler name: :fibonacci, metadata: { hello: 'Micro-Rb' }, rpc_method: :fibonacci def fibonacci(request: Request.new, response: Response.new) if (0..1).cover?(request.n) response.n = request.n return response end left = rpc_call(Request.new(n: request.n - 1)) right = rpc_call(Request.new(n: request.n - 2)) response.n = left + right response end private def rpc_call(request) MicroRb::Clients::Rpc.call(service: :test, method: 'FibHandler.fibonacci', params: request, klass_response: Response).n end end server = MicroRb::Servers::Web.new(:test, debug: true, metadata: { example: 'Fib Service' }, server: :puma) server.add_handler FibHandler.new server.start! # MicroRb::Clients::Rpc.call(service: :test, method: 'FibHandler.fibonacci', params: { n: 15 } ) # { # "n" => 610 # }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micro-rb-0.1.0.rc2 | lib/micro/examples/fib.rb |