Barrister RPC

Barrister RPC

Barris RPC presentation Mumbai Ruby Users Group


Saurabh Bhatia

October 18, 2016


  1. barrister rpc Saurabh Bhatia Full Stack Developer

  2. what is rpc ? • Remote Procedure Call - In

    computer science, a remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction. Source -
  3. why use it? • Developing apps is costly, bridging legacy

    systems with newer ones is cheaper. • Any language is not fit for everything - get best of all worlds by being polygot. • Connecting & interfacing microservices
  4. barrister rpc • Combines json-rpc with an easy to use

    idl • human readable client-server implementation
  5. language compatibility • Java • node • ruby • php

    • python
  6. installation • pip install —pre barrister • gem install barrister

    • Rails - add, gem ‘barrister’ to Gemfile & bundle
  7. class • lib/calculator.rb class Calculator def initialize end def add(a,

    b) return a+b end end
  8. define idl • create - app/interfaces • place idl file

    here. • compile the json here.
  9. define idl • app/interfaces/calc.idl • barrister -t "Calculator Service" -j

    calc.json calc.idl interface Calculator { add(a float, b float) float }
  10. define idl • app/interfaces/calc.json [{"comment": "", "functions": [{"comment": "", "returns":

    {"optional": false, "is_array": false, "type": "float"}, "params": [{"is_array": false, "type": "float", "name": "a"}, {"is_array": false, "type": "float", "name": "b"}], "name": "add"}], "type": "interface", "name": "Calculator"}, {"barrister_version": "0.1.6", "type": "meta", "date_generated": 1416594045033, "checksum": "8c13de1b0fa6797b80df3f873 c86c509"}]
  11. initialize server • calc_controller.rb before_action :initialize_server def initialize_server file =

    Rails.root.join('app/interfaces/calc.json') contract = Barrister::contract_from_file(file) @server = @server.add_handler("Calculator", end
  12. respond to client call • calc_controller.rb before_action :initialize_server def add

    resp = @server.handle_json( resp render nothing: true end def initialize_server file = Rails.root.join('app/interfaces/calc.json') contract = Barrister::contract_from_file(file) @server = @server.add_handler("Calculator", end
  13. route • routes.rb post 'add' => 'calc#add' Started POST "/add"

    for ::1 at 2014-11-22 08:40:07 +0530 Processing by CalcController#add as */* Parameters: {"jsonrpc"=>"2.0", "id"=>"1", "method"=>"barrister-idl", "calc"=>{"id"=>"1"}} Rendered text template (0.1ms) Completed 200 OK in 14ms (Views: 9.3ms | ActiveRecord: 0.9ms)
  14. client • calc_client.rb require 'barrister' #initialize the endpoint trans ="http://localhost:30020/add") #loads contract, and idl to the endpoint client = #rpc call puts client.Calculator.add(1, 5.1)
  15. links • • • Rails Client -

    rails • meets-old-polyglot-distributed-systems-with- barrister-rpc/
  16. Thank You * धन्यवाद * 謝謝