Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
node-serf
Advanced tools
Readme
Serf management and orchestration client.
To provide a interface for communication with Serf daemon via the RPC Protocol.
npm install --save node-serf
Just send the body. The header and Seq
values have been taken care of for you.
Commands without response bodies will invoke the callback upon acknowledgement
by the Serf agent. Commands with response bodies will invoke the callback with
the response.
var Serf = require('node-serf');
// Connection to Serf agent at the default, "127.0.0.1:7373"
var client = Serf.connect(function (err) {
assert.ifError(err);
console.log('connected');
client.join({Existing: ['127.0.0.1:7946'], Replay: false}, function (err, response) {
assert.ifError(err);
setTimeout(function() {
client.leave();
}, 1000);
});
});
Please refer to the Serf RPC documentation for authoritative information on each command.
options
<Object> Connection options. If omitted, defaults to
localhost:7373.callback
<Function> Invoked after connected and handshake completed.Returns a new Serf client.
The options
argument typically contains port
(required) and host
(defaults to 'localhost'
), but any of the socket.connect options
are allowed.
This is called automatically upon connecting. You should not call this directly.
Disconnects from the Serf agent. You must call this to close the socket so that
node.js may gracefully exit. Alternatively, call serf.leave()
to close both
the socket and the Serf agent; once called, you must restart the agent to
rejoin, however.
Returns an event emitter that can be handled with 'listen'
, 'data'
,
'error'
and 'stop'
listeners. This is not a node.js Stream, so it cannot
be piped, paused, etc. Messages are not buffered, so messages will be dropped
if listeners are not attached.
If a callback is provided, it will be added to the 'listen'
listeners.
The returned emitter has a stop
method that ends the stream. If a callback is
provided, it will be added to the 'stop'
listeners.
var stream = client.stream({Type: '*'}, function (err) {
// Called after the stream is connected
assert.ifError(err);
});
stream.on('listen', function (err) {
// Also called after the stream is connected
});
stream.on('error', console.error.bind(console)); // log errors
stream.on('data', function (result) {
// Handle streaming message
console.log(result);
// Stop streaming
stream.stop(function (err) {
// Called when the stream is stopped
});
});
stream.on('stop', function () {
// Also emitted when the stream is stopped
});
Listen using the same syntax as serf.stream
.
Issues a new query. Listen using the same syntax as serf.stream
. There are
three Type
s of responses: 'ack', 'response' and 'done'. The 'data' event is
invoked when any type of response is received. When the 'done' response is
received, the 'stop' event will also be emitted.
Note that there appears to be a bug in Serf wherein responses are sometimes
sent with the form {From: '', Payload: null, Type: 'response'}
. You should
check that Payload
is not null before attempting to access it.
body
<Object> Of the form {ID: number, Payload: string|bytes[, ...]}
Use with serf.stream
. Your response ID
property must match the query ID.
The Serf client extends node.js's socket class. In addition to handling errors
passed to the command callbacks and errors raised on streams created by the
monitor
, stream
and query
commands, you should subscribe to the client's
'error'
event, which will be invoked in case of a socket error unrelated to a
Serf command (such as a network fault). If you do not, these errors will bubble
up and become uncaught exceptions.
var client = Serf.connect({port: 7373}, function (err) {
assert.ifError(err);
/// do stuff
});
client.on('error', function (err) {
// handle error
})
FAQs
Serf management and orchestration
The npm package node-serf receives a total of 81 weekly downloads. As such, node-serf popularity was classified as not popular.
We found that node-serf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.