RJR - Ruby Json Rpc Library

RJR is an implementation of the JSON-RPC
Version 2.0 Specification. It allows a developer to register custom JSON-RPC
method handlers which may be invoked simultaneously over a variety of transport
mechanisms.

# listen for methods via amqp, websockets, http, and via local calls
amqp_node=RJR::Nodes::AMQP.new:node_id=>'server',:broker=>'localhost'ws_node=RJR::Nodes::WS.new:node_id=>'server',:host=>'localhost',:port=>8080www_node=RJR::Nodes::Web.new:node_id=>'server',:host=>'localhost',:port=>8888local_node=RJR::Nodes::Local.new:node_id=>'server'multi_node=RJR::Nodes::Multi.new:nodes=>[amqp_node,ws_node,www_node,local_node]# define a rpc method called 'hello' which takes
# one argument and returns it in upper case
multi_node.dispatcher.handle("hello"){|arg|arg.upcase}# start the server and block
multi_node.listenmulti_node.join

Reference

Advanced

Upon receiving requests from eventmachine, rjr hands them off to a thread pool to free up the reactor.
It is up to the developer to ensure resources accessed in the method handlers
are protected from concurrent access.

Various metadata fields are made available to json-rpc method handlers through
instance variables. These include:

@rjr_node

@rjr_node_id

@rjr_node_type

@rjr_callback

@rjr_headers

@rjr_client_ip

@rjr_client_port

@rjr_method

@rjr_method_args

@rjr_handler

RJR implements a callback interface through which methods may be invoked on a client
after an initial server connection is established. Store and/or invoke @rjr_callback to make
use of this.

node.dispatcher.handle("register_callback")do|*args|$my_registry.invoke_me_later{# rjr callback will already be setup to send messages to the correct client
@rjr_callback.invoke'callback_method','with','custom','params'}end

RJR also permits arbitrary headers being set on JSON-RPC requests and responses. These
will be stored in the json send to/from nodes, at the same level/scope as the message
'id', 'method', and 'params' properties. Developers using RJR may set and leverage these headers
in their registered handlers to store additional metadata to extend the JSON-RPC protocol and
support any custom subsystems (an auth subsystem for example)