Waterway is a Node.js microservice communication framework powered by redis pub/sub. It is designed to be as minimalistic as possible, exposing 3 different methods of communication:
Events: An event is a single uni-directional message that is broadcast by the sender and receives no response. It is designed for reporting state and actions in scenarios where you do not want a response.
Requests: A request is a an event with a response. Each request has a unique ID assigned to it and the sender will only receive the first response for each unique request.
Streams: A stream is a continuous flow of events, wrapped up in Node's Stream API. This allows you to stream any size and type of data between services.
All messages in Waterway are organised by their key. A key is an ordered sequence of parameters which internally gets converted into a redis pub/sub channel. Keys are used when creating and receiving messages. For example, this is how you would send and receive a simple event:
waterwayReceiverevent"foo" "bar";waterwaySenderevent"foo" "bar"; // -> "baz"
Since internally keys just converted into a redis channel you can use wildcards for matching:
waterwayReceiverevent"foo" "*";waterwaySenderevent"foo" "bar"; // -> "baz"waterwaySenderevent"foo" "baz"; // -> "bar"
Returns a new Waterway instance. Redis config options are those supported by the node redis client.
var waterway =redis:port: 1234;
Returns a new Waterway event.
Returns a new Waterway request.
Returns a new Waterway stream.
Emits the event, optionally with data provided.
Registers a callback for the event. The callback will be invoked with the event data and matching event key. The matching key is provided incase any parameters matched by wildcards are needed in the callback.
Unregisters an event. If callback is provided only that callback will be unregistered.
Sends the request, optionally with data provided. Returns a promise.
Registers a responder for the request. The callback will be invoked with the request data and matching request key. The matching key is provided incase any parameters matched by wildcards are needed in the callback. The callback can return a promise or regular data in order to respond with data to the requester.
A WaterwayStream is an implementation of Node's stream.Duplex class. This means you can use it to transfer any type of continuous or large data between services. Note that only one instance of Waterway should be writing to a specific key otherwise you risk polluting the data.
:lipstick:when improving the format/structure of the code
:racehorse:when improving performance
:non-potable_water:when plugging memory leaks
:memo:when writing docs
:penguin:when fixing something on Linux
:apple:when fixing something on Mac OS
:checkered_flag:when fixing something on Windows
:bug:when fixing a bug
:fire:when removing code or files
:green_heart:when fixing the CI build
:white_check_mark:when adding tests
:lock:when dealing with security
:arrow_up:when upgrading dependencies
:arrow_down:when downgrading dependencies