Entire NestJS Module Revamp + Handling multiple connections #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context of the revamp
Previous partial support for handling multiple AMQP connections involved using the same root
AMQPModule
and passing an array of connections.nestjs-amqp/lib/amqp.module.ts
Line 22 in b97d1d4
amqplib
connection objects were stored within the same module in a Map. When performing actions on a particular connection or channel, retrieval from the Map had to happen:nestjs-amqp/lib/amqp.service.ts
Lines 15 to 22 in b97d1d4
This deviates from what NestJS does on modules like
@nestjs/mongoose
or@nestjs/typeorm
where multiple connections are handled by different instances of the module. This is how@nestjs/mongoose
handles multiple connections:And when wanting to use a resource for a module, an Injector is provided to inject the resource for a particular connection:
This behavior also deviates from the current implementation where no injection happens, and instead, a shared "AMQPService" is provided to get access to channels. Not doing dependency injection right has implications for testing and goes against core design principles for NestJS.
(Breaking) changes made to fix this behavior
(not a comprehensive list)
AMQPModule.forRoot
now accepts two parameters. The first is for connection details (hostname, port, etc.), and the second is for connection options (exchanges, asserting queues, serviceName, etc.)AMQPCoreModule
. One for an AMQP Connection and one for an AMQP Channel.AMQPService
in favor of injectors.AMQPModule
to theAMQPModuleExplorer
.TO-DOs
// TODO:
from the code (there are still some left)README.md
with updated examples and explanations.Closes #3.