How to open multiple connection and use in their respective modules?
See original GitHub issueHello, is it possible to create multiple connection and use in their respective modules? I tried like
@Module({ imports: [ RabbitMQModule.forRoot(RabbitMQModule, { exchanges: [ { name: 'exchange1', type: 'headers', }, ], uri: 'amqp://username:password@server1:5672', enableControllerDiscovery: true, }) ], controllers: [FirstController] }) export class FirstController {}
@Module({ imports: [ RabbitMQModule.forRoot(RabbitMQModule, { exchanges: [ { name: 'exchange2', type: 'headers', }, ], uri: 'amqp://username:password@server2:5672', enableControllerDiscovery: true, }), ], controllers: [SecondController], }) export class SecondController {}
it created 2 connection but same queues on both rmq server without respecting modules.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)

Top Related StackOverflow Question
@andrewda The way it is working right now only contains a single connection which means that in order to support multiple you need to adapt (https://github.com/golevelup/nestjs/blob/18ca7996ca66d9681ff763658cfc5256f9d26405/packages/rabbitmq/src/rabbitmq.module.ts#L64) the factory to push new connections to an array of connections rather than a single connection object. The implementation should be something like we did for the channels if you look at the merged PR’s where you always have a default connection and we can specify named connections/URL and simply pick that
Great, thanks for the details @underfisk! I’ll see what I can do.