This module has been written for Swanest back-end. It eases the use of messaging between services. We use RabbitMQ as the underlying broker service. This library is using amqplib (0.9.1) as a core dependency but we do use some parameters that are only RabbitMQ related so it might not work with other AMQP 0.9.1 brokers.
Supported version of NodeJS 8+
yarn add micromessaging
npm install micromessaging --save
Full API documentation is at: swanest.github.io/micromessaging
Special thanks to TypeDoc that enabled it.
import { Messaging } from 'micromessaging';
// Server
const server = new Messaging('server');
await server.handle('request-name', (message) => {
// message.body = {how: {are: 'you?'}}
message.reply({im: 'fine'});
});
await server.connect(); // Connect can be before or after the handlers it doesnt matter.
// Client
const client = new Messaging('client');
await client.connect(); // Connection needs to be established before...
const response = await client.request('server', 'request-name', {how: {are: 'you?'}});
// response = {im: 'fine'}
v3.0 is a full breaking changes and CANT be used with an other modules using an earlier version.
About what it does:
.request
/ .handle
).emit
/ .listen
).task
/ .handle
)serviceName
(in new Messaging(serviceName[, serviceOptions])
)Qos.ts
)HeavyEL
for event-loop management and the MemoryPressure
module to know about memory usage and pressure.PeerStatus.ts
)getStatus
of a service (to know if the service is accepting workload)new require('micromessaging').Messaging(...)
and new require('micromessaging').Service(...)
(to ease backward compatibility but Service
should log a warning to tell it's deprecated...)typedoc
generates a cool and easy doc..stop()
on the return of emit
and handle
=> see ReturnHandler.Generated using TypeDoc