imicros-transporter
v0.0.4
Published
Two way transporter for Moleculer services (Kafka/NATS)
Downloads
21
Readme
imicros-transporter
Two way transporter for Moleculer services
Installation
$ npm install imicros-transporter --save
Requires installation of the additional modules nats and kafkajs
Usage
const { KafkaNats } = require("imicros-transporter");
const transporterSettings = {
kafka: {
brokers: ["192.168.2.124:9092"]
/* optional: additional settings
ssl: null, // refer to kafkajs documentation
sasl: null, // refer to kafkajs documentation
retry: {
initialRetryTime: 100, // default 100
retries: 8 // default 8
}
*/
},
nats: {
url: "nats://192.168.2.124:4222"
/* optional: additional settings
user: "admin",
pass: "1234"
*/
}
};
kafka = new ServiceBroker({ nodeID: uuid(), transporter: new KafkaNats(transporterSettings), disableBalancer: true });
Force emittung events always
If no running service has subscribed an event, it will not be emitted in the current moleculer version.
To force to emit always - also if no one is listening, we must add a small middleware:
const { KafkaNats } = require("imicros-transporter");
const { EventsMiddleware } = require("imicros-transporter");
kafka = new ServiceBroker({ nodeID: uuid(), transporter: new KafkaNats(transporterSettings), disableBalancer: true, middlewares: [EventsMiddleware] });