streams-connector 0.6.1
Install from the command line:
Learn more about npm packages
$ npm install @joaofnds/streams-connector@0.6.1
Install via package.json:
"@joaofnds/streams-connector": "0.6.1"
About this version
With streams connector you can make events from one event emitter instance to appear in another, through Redis Streams.
You can use that, for example, to communicate NestJS applications by just emitting events. Streams connector will take care of:
- On App A:
- listening to the event
- writing it to a stream
- On App B:
- reading from the stream
- publishing the event
import {
StreamsConnectorModule,
StreamsConnectorOptions,
} from "@joaofnds/streams-connector";
@Module({
imports: [
EventEmitterModule.forRoot(),
StreamsConnectorModule.registerAsync({
inject: [EventEmitter2],
useFactory: (eventEmitter: EventEmitter2) => {
return new StreamsConnectorOptions({
eventEmitter,
redis: {
name: "myapp",
url: "redis://localhost:6379",
},
stream: {
group: "myapp",
consumer: "myapp-consumer",
readTimeout: 5000,
},
reclaim: {
count: 10,
interval: 60000,
maxDeliveries: 5,
throughputThreshold: 10,
minIdleTime: 30000,
},
sendEvents: [
{
name: "my_event",
serialize: (event) => JSON.stringify(event),
},
],
receiveEvents: [
{
name: "my_other_event",
deserialize: (str) => JSON.parse(str),
},
],
});
},
}),
],
})
export class AppModule {}If you want to now more about what each param means, please read the redis streams doc.
The reclaim will only happen when the throughput in below the provided threshold
