OpraRabbitmqModule
NestJS dynamic module that wires OPRA's RabbitMQ adapter into a NestJS application.
import { OpraRabbitmqModule } from '@opra/nestjs-rabbitmq';
forRoot(options)
Synchronous registration:
import { Module } from '@nestjs/common';
import { OpraRabbitmqModule } from '@opra/nestjs-rabbitmq';
import { OrderController } from './controllers/order.controller.js';
@Module({
imports: [
OpraRabbitmqModule.forRoot({
name: 'OrdersApi',
connection: { url: 'amqp://localhost' },
controllers: [OrderController],
}),
],
})
export class AppModule {}
Options (OpraRabbitmqModule.ModuleOptions)
| Option | Type | Description |
|---|---|---|
name | string | API name. |
description | string | Optional API description. |
scope | string | Validation scope. |
connection | RabbitmqAdapter.Config['connection'] | RabbitMQ connection configuration. |
logExtra | RabbitmqAdapter.Config['logExtra'] | Extra log context. |
defaults | RabbitmqAdapter.Config['defaults'] | Default consumer/producer settings. |
types | Type[] | Data types to register on the ApiDocument. |
references | object | Type references. |
info | object | API info metadata. |
controllers | Type[] | OPRA MQ controller classes. |
providers | Provider[] | Additional NestJS providers. |
exports | any[] | Providers to export. |
imports | any[] | Modules to import. |
global | boolean | Register globally. |
id | any | Custom module ID. |
interceptors | (InterceptorFunction | IRabbitmqInterceptor | Type<IRabbitmqInterceptor>)[] | Request interceptors. |
logger | Logger | Custom logger. |
forRootAsync(options)
Asynchronous registration:
OpraRabbitmqModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
name: 'OrdersApi',
connection: { url: config.get('RABBITMQ_URL') },
controllers: [OrderController],
}),
})
Options (OpraRabbitmqModule.AsyncModuleOptions)
| Option | Type | Description |
|---|---|---|
inject | any[] | Providers to inject into useFactory. |
useFactory | (...args) => ApiConfig | Promise<ApiConfig> | Factory returning the API configuration. |
Plus all non-API fields from ModuleOptions.