reactivesocket3.3.1 • Public • Published
ReactiveSocket Protocol for Client/Server for JS. Also comes with a CLI.
npm install -g reactivesocket
This library only supports the
interactions. More interactions are coming soon.
The transport for this library is built entirely on top of the Node.js Stream API. As a result, it is agnostic to the underlying transport mechanism. As long as you pass in a transport stream that is a Node.js Duplex stream, this library will work.
Using streams means that this library natively supports backpressure regardless of the transport implementation.
Connection Quick Start
This library supports 3 classes of clients. A fully managed load balancer, which automatically manages a pool of connections and takes care of automatically reconnecting and load-balancing connections from the pool. A fully managed single TCP connection, which can be configured to automatically reconnect if the TCP connection disconnects. Lastly a "raw" ReactiveSocket connection, which doesn't include any retry or transport logic. You provide a transport stream to plug in to the connection. This is the most flexible client, as you can use it with any transport mechanism. Examples for TCP and WebSockets are provided.
TCP Client Side Load Balancer
var bunyan = ;var reactiveSocket = ;var connectionPool = reactiveSocket;connectionPool;
var bunyan = ;var reactiveSocket = ;var tcpConnection = reactiveSocket;tcpConnection;
var net = ;var bunyan = ;var reactiveSocket = ;// Create any transport stream that's a Node.js Duplex Stream.var transportStream = net;
var bunyan = ;var reactiveSocket = ;var Ws = ;var WSStream = ;var websocket = 'ws://localhost:1337';// Create any transport stream that's a Node.js Duplex Streamvar transportStream =log: bunyanws: websocket;// Wait for Websocket to establish connection, before we create an RS Connectionwebsocket;
As a convenience for the user, the ReactiveSocket client provide 'timeout' events. Below is an example of how to listen to those events.
var socket = ...;var client = reactiveSocket;client;
ReactiveSocket client allows you to specify if you want to honor the lease semantic.
If you don't, it means that the
ReactiveSocket is ready as
soon as the connection is established, and you can start sending messages.
But if you do, it means the client has to wait for a
LEASE frame from the
server before sending messages.
Note that nothing is preventing the client to send requests to the server before
LEASE reception only update the return value of
availability method (number between 0 and 1.0).
availability method gives precious information to a potential higher
level library (e.g. load-balancing library) about the capability of the
More details about the lease semantic are available in the protocol Spec.
ReactiveSocket uses the metrix library to collect and export metrics. By default, the library doesn't collect any metrics, and then its usage doesn't have any impact on the performance of ReactiveSocket.
To enable the collection, you need to pass a
Recorder when creating a ReactiveSocket, and
listen to this
Recorder with an
var RECORDER = metrix;var AGGREGATOR = metrix;var client = reactiveSocket;;
This library comes with a CLI. You can use it by installing this module.
$ npm install -g reactivesocket
There are two versions of the client CLI. The simple CLI makes one request to a server.
$ rs -o req tcp://localhost:1337 'if you didnt care what happened to me, And I didnt care for you'
There is also a benchmarking CLI in the vein of Apache Bench
$ rb -c 10 -n 10000000 -s 1000 tcp://localhost:1337
Simple echo servers are also available for both TCP and Websocket.
$ HOST=localhost PORT=1337 rs-tcp-server
$ HOST=localhost PORT=1337 rs-ws-server
Contributions welcome, please ensure
make check runs clean.
Copyright 2016 Yunong J Xiao