0.1.56 • Published 2 years 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
2 years ago
0.1.56
2 years ago
0.1.52
3 years ago
0.1.53
3 years ago
0.1.54
3 years ago
0.1.51
3 years ago
0.1.50
3 years ago
0.1.47
3 years ago
0.1.46
3 years ago
0.1.45
3 years ago
0.1.44
3 years ago
0.1.43
3 years ago
0.1.42
3 years ago
0.1.39
3 years ago
0.1.38
3 years ago
0.1.37
3 years ago
0.1.36
3 years ago
0.1.35
3 years ago
0.1.34
3 years ago
0.1.33
3 years ago
0.1.32
3 years ago
0.1.31
3 years ago
0.1.30
3 years ago
0.1.29
3 years ago
0.1.28
3 years ago
0.1.27
3 years ago
0.1.26
3 years ago