0.1.56 • Published 10 months ago
@microservice-stack/nest-rabbitmq v0.1.56
RabbitMQ
This library provides a module that enables the usage of RabbitMQ inside your project. It comes with support for publishing events as well as subscribing to them
Import
import { Module } from '@nestjs/common';
import { RabbitmqModule } from '@microservice-stack/nest-rabbitmq';
import { ConfigModule, ConfigService } from '@microservice-stack/nest-config';
@Module({
imports: [
RabbitmqModule.register({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
uri: configService.get('QUEUE_URL'),
}),
}),
],
})
export class AppModule {}
Publish
export interface HelloWorldEventPayload {
hello: string;
}
export const HELLO_WORLD_EVENT = new Event<HelloWorldEventPayload>('hello.world', 1);
import { RabbitmqService } from '@microservice-stack/nest-rabbitmq';
import { HELLO_WORLD_EVENT } from './constants';
export class HelloService {
constructor(private queueService: RabbitmqService) {}
public sayHello(): void {
this.queueService.publishEvent(HELLO_WORLD_EVENT, { hello: 'world' });
}
}
Subscribe
Queue controllers should be defined separately from Rest controllers as any Rest endpoints defined in them will not work.
import { Controller } from "@nestjs/common";
import { Subscribe } from "@microservice-stack/nest-rabbitmq";
import { HELLO_WORLD_EVENT, HelloWorldEventPayload } from './constants';
@Controller()
export class HelloQueueController {
static CONTROLLER_QUEUE_NAME = 'hello-queue';
@Subscribe(HELLO_WORLD_EVENT, HelloQueueController.CONTROLLER_QUEUE_NAME)
public hello(payload: HelloWorldEventPayload): void {
console.log(payload.hello);
}
}
0.1.55
10 months ago
0.1.56
10 months ago
0.1.52
1 year ago
0.1.53
1 year ago
0.1.54
1 year ago
0.1.51
1 year ago
0.1.50
1 year ago
0.1.47
1 year ago
0.1.46
1 year ago
0.1.45
1 year ago
0.1.44
1 year ago
0.1.43
1 year ago
0.1.42
1 year ago
0.1.39
1 year ago
0.1.38
1 year ago
0.1.37
1 year ago
0.1.36
1 year ago
0.1.35
1 year ago
0.1.34
1 year ago
0.1.33
1 year ago
0.1.32
1 year ago
0.1.31
1 year ago
0.1.30
1 year ago
0.1.29
1 year ago
0.1.28
1 year ago
0.1.27
1 year ago
0.1.26
1 year ago