Creates a new instance of Tentacoli, which is a
Duplex
stream and inherits from multiplex
It accepts the following option:
codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
This capability is provided by
net-object-stream.
maxInflight: max number of concurrent requests in
flight at any given moment.
instance.request(message, callback(err, res))
Sends a request to the remote peer.
message is a standard JS object, but all streams contained in its
streams property will be multiplexed and forwarded to the other
peer.
callback will be called if an error occurred or a response is
available. The res.streams property will contain all streams
passed by the other peer.
instance.fire(message, callback(err))
Sends a fire and forget request to the remote peer.
message is a standard JS object, but all streams contained in its
streams property will be multiplexed and forwarded to the other
peer.
callback will be called if there is an error while sending the message, or after the message has been sent successfully.
instance.on('request', callback(req, reply))
The 'request' event is emitted when there is an incoming request.
req is the standard JS object coming from request,
and all the streams contained in its
streams property will have been multiplexed and forwarded from
the other peer.
reply is the function to send a reply to the other peer, and it
follows the standard node callback pattern: reply(err, res).
The res.streams property should contain all the streams
that need to be forwarded to the other peer.
TODO
battle test it, you can definitely help! I am particularly
concerned about error handling, I do not want tentacoli to crash
your process.
figure out how to handle reconnects.
[x] provide examples, with WebSockets (via
websocket-stream net, SSL, etc..
provide an example where a request is forwarded sender -> router
-> receiver. With streams!
tentacoli needs a microservice framework as its companion, but it
is framework agnostic. We should build a
seneca transport and probably something more
lean too.
In the Browser
You will use websocket-stream to
wire tentacoli to the websocket.
This library would not be possible without the great work of
@mafintosh,
@substack and
@maxodgen. This library is fully based on
their work, look at package.json!
Another great source of inspriation was jschan
from which I borrowed a lot of ideas. Thanks Adrian
Roussow for all the discussions
around microservices, streams and channels.
Many thanks to @mcdonnelldean for
providing an excuse to write this random idea out.