Grenache is a micro-framework for connecting microservices. Its simple and optimized for performance.
Internally, Grenache uses Distributed Hash Tables (DHT, known from Bittorrent) for Peer to Peer connections. You can find more details how Grenche internally works at the Main Project Homepage
gem install grenache-ruby-http
Install Grenache Grape
: https://github.com/bitfinexcom/grenache-grape:
npm i -g grenache-grape
// Start 2 Grapes
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
This RPC Server example announces a service called rpc_test
on the overlay network. When a request from a client is received,
it replies with world
. It receives the payload hello
from the
client.
The client sends hello
and receives world
from the server.
Internally the DHT is asked for the IP of the server and then the request is done as Peer-to-Peer request via websockets.
Grape:
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
Server:
require "grenache-ruby-http"
EM.run do
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40001/")
port = 5001
c.listen("test_service", port) do |req|
"hello #{req.payload}"
end
end
Client:
require "grenache-ruby-http"
c = Grenache::Http.new(grape_address: "http://127.0.0.1:40001/")
resp, err = c.request("test_service", "world")
puts "response: #{resp}"
options
-
:grape_address
<String> -
:timeout
<Number> -
:auto_announce_interval
<Number> -
:auto_announce
<Boolean> -
:service_timeout
<Number> -
:service_host
<String> -
:key
<String> SSL: Path to key file -
:cert_pem
<String> SSL: Path to chain file -
:ca
<String> SSL: Path to ca file -
:service_host
<String> SSL: host name, used for worker -
:reject_unauthorized
SSL: Reject unauthorized certs -
:verify_mode
SSL: Verification method, defaultGrenache::SSL_VERIFY_PEER
-
name
<String> Name of the service to addresspayload
Payload to sendoptions
:timeout
Timeout for the request
Sends a single request to a RPC server/worker. Example.
data
:v
: <String> value to store
options
:timeout
Timeout for the request
Puts a value into the DHT.
hash
<String> Hash of the data to receive
Retrieves a stored value from the DHT via a hash
<String>.
name
<String> Name of the service to announceport
<Number> Port to listenoptions
Sets up a worker which connects to the DHT.
Listens on the given port
.