This package provides a NestJS module for integrating with NATS Streaming (STAN), enabling publish-subscribe messaging in a microservices architecture. It offers automatic connection management, message publishing, and subscription handling with manual acknowledgment support.
- 📡 Seamless NATS Streaming Integration
- 🔄 Automatic Reconnection Handling
- ✅ Manual Acknowledgment Support
- ⚡ Efficient Pub/Sub Mechanism
- 🚀 Easy to Use in Any NestJS Application
Install the package using npm:
npm install nest-nats-management
import { Module } from '@nestjs/common';
import { NatsManagementModule } from 'nest-nats-management';
@Module({
imports: [NatsManagementModule.forRoot('test-cluster', 'client-123', 'nats://localhost:4222')],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { NatsManagementService } from 'nest-nats-management';
@Injectable()
export class PersonnesService {
constructor(private readonly natsService: NatsManagementService) {}
async create(person: CreatePersonnesDto) {
//Your logic here
//publishing message
await this.natsService.publish('person:created', person);
}
}
import { Controller } from '@nestjs/common';
import { NatsManagementService } from 'nest-nats-management';
@Controller('personnes')
export class PersonnesController {
constructor(private readonly natsService: NatsManagementService) {
this.subscribeToPersonCreated();
}
private subscribeToPersonCreated() {
this.natsService.subscribe('person:created', (message) => {
console.log('📩 Received event in controller: person.created', message);
//message reatment here
});
}
}
this.natsService.unsubscribe('person:created');
This project is licensed under the ISC License.