Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
distributed-eventemitter
Advanced tools
The ultra fast, distributed (multi process and multi server), STOMP based event emitter for Node.js!
The library solve the need of a multi process and multi server oriented messaging API in Node.js.
Using the known EventEmitter API, listeners registration and events emitting is super simple.
A new 'emitToOne' method allows one-to-one events notification, intended for request/response flows on clustered services.
The classic 'emit' method broadcast custom events to local and distributed listeners.
For non-distributed usage of this API (browser, single node process or development) developers can use: process-eventemitter
var EventEmitter = require('distributed-eventemitter');
var events = new EventEmitter(); // host: localhost, port: 61613
events.connect().then(() => {
events.on('email.send', (message, resolve, reject) => {
console.log('sending email...');
//... send email
// ...
resolve('sent');
});
});
pm2 start A.js -i 4 --node-args="--harmony"
var EventEmitter = require('distributed-eventemitter');
var events = new EventEmitter(); // host: localhost, port: 61613
events.connect().then(() => {
events.emitToOne('email.send', {
to: 'kyberneees@gmail.com',
subject: 'Hello Node.js',
body: 'Introducing easy distributed messaging for Node.js...'
}, 3000).then((response) => {
if ('sent' === response) {
console.log('email was sent!');
}
}).catch(console.log.bind());
});
node --harmony B.js
"use strict";
const EventEmitter = require('distributed-eventemitter');
const co = require('co');
const events = new EventEmitter(); // host: localhost, port: 61613
co(function* () {
try {
yield events.connect();
let response = yield events.emitToOne('email.send', {
to: 'kyberneees@gmail.com',
subject: 'Hello Node.js',
body: 'Introducing easy distributed messaging for Node.js...'
}, 3000);
if ('sent' === response) {
console.log('email was sent!');
}
yield events.disconnect();
} catch (error) {
console.log('error: ' + error);
}
});
Running STOMP compliant server instance. Default client destinations are:
/queue/distributed-eventemitter: Used for one-to-one events (emitToOne)
If the server require clients to be authenticated, you can use:
{
'host': 'localhost',
'connectHeaders': {
'heart-beat': '5000,5000',
'host': '',
'login': 'username',
'passcode': 'password'
}
}
$ npm install distributed-eventemitter
var config = {};
config.destination = 'distributed-eventemitter'; // server topic and queue destinations
config.excludedEvents = []; // events that are not distributed
config.servers = [{
'host': 'localhost',
'port': 61613,
'connectHeaders': {
'heart-beat': '5000,5000',
'host': '',
'login': '',
'passcode': ''
}
}];
config.reconnectOpts = {
maxReconnects: 10;
}
var events = new EventEmitter(config);
For more details about 'servers' and 'reconnectOpts' params please check: http://gdaws.github.io/node-stomp/api/connect-failover/
events.on('connected', (emitterId) => {
// triggered when the emitter has been connected to the network (STOMP server)
});
events.on('disconnected', (emitterId) => {
// triggered when the emitter has been disconnected from the network (STOMP server)
});
events.on('error', (error) => {
// triggered when an error occurs in the connection channel.
}):
events.on('connecting', (connector) => {
// triggered when the STOMP client is trying to connect to a server.
}):
events.on('request', (event, request, raw) => {
// triggered before invoke a listener using emitToOne feature
// request data filtering and modification is allowed
// example:
request.data = ('string' === typeof request.data) ? request.data.toUpperCase() : request.data
}):
events.on('response', (event, response, raw) => {
// triggered after invoke a listener using emitToOne feature
// response data filtering and modification is allowed
// example:
if (response.ok)
response.data = ('string' === typeof response.data) ? response.data.toUpperCase() : response.data
else
console.log('error ocurred: ' + response.data.message);
}):
getId: Get the emitter instance unique id.
events.getId(); // UUID v4 value
connect: Connect the emitter to the server. Emit the 'connected' event.
events.connect().then(()=> {
console.log('connected');
});
disconnect: Disconnect the emitter from the server. Emit the 'disconnected' event.
events.disconnect().then(()=> {
console.log('disconnected');
});
emitToOne: Notify a custom event to only one target listener (locally or in the network). The method accept only one argument as event data.
events.on('my.event', (data, resolve, reject) => {
if ('hello' === data){
resolve('world');
} else {
reject('invalid args');
}
});
// calling without timeout
events.emitToOne('my.event', 'hello').then((response) => {
console.log('world' === response);
});
// calling with timeout (ms)
events.emitToOne('my.event', {data: 'hello'}, 100).catch((error) => {
console.log('invalid args' === error);
});
$ npm install
$ npm test
FAQs
The ultra fast, distributed (multi process and multi server), STOMP based event emitter for Node.js!
The npm package distributed-eventemitter receives a total of 8 weekly downloads. As such, distributed-eventemitter popularity was classified as not popular.
We found that distributed-eventemitter 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.