-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing module initialization behavior for hybrid applications #2835
Labels
Comments
Let's do this. Would you like to contribute and create a PR to the docs? |
yeah absolutely, I can put up a PR for it over the next couple days |
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
some of the users of my NestJS gRPC Reflection Module package have reported confusing behavior where the module is not properly initialized when running within their Hybrid Application. The issue boils down to the fact that the
app.startAllMicroservices
method will start all of the connected microservices and properly serve requests but will not run the module lifecycle hooks. Lifecycle hooks are only run whenapp.listen
is called, however not all users will be running an HTTP server in their application and may omit thatwhen searching through the issues in this repo it seems like similar confusion has come up before in nestjs/nest#12042 and nestjs/nest#8446. I'm not 100% sure of what solution would make the most sense here so I've added a couple thoughts to start a discussion below
Describe the solution you'd like
the main pitfall here seems to be when a users hybrid application does not use an HTTP server. The Hybrid Application documentation is geared towards a "microservice + HTTP server" scenario, however users may also be running multiple multiple microservices instead without any HTTP server in which case they are not going to use the
app.listen
call and are not likely to know that they'd need to callapp.init
manuallyOption 1: the simplest solution to this seems like it would be to make the
app.startAllMicroservices
method run the module lifecycle hooks if they haven't been run already so that theapp.listen
orapp.init
calls are no longer necessary. This would also make the microservice startup better match the behavior of the HTTP service startupOption 2: alternatively we could combine the microservice startup logic into
app.listen
so that there isn't that distinction in the first place. This would likely require a method override so that the port number wouldn't be required inapp.listen
Option 3: we could add a warning to the hybrid application docs to be clear that the
app.init
orapp.listen
must be called at some point in the application when usingstartAllMicroservices
Teachability, documentation, adoption, migration strategy
will update this section after discussion
What is the motivation / use case for changing the behavior?
avoiding confusing scenarios where the application successfully starts up and can serve requests but none of the module lifecycle hooks have run, causing incomplete module configuration
The text was updated successfully, but these errors were encountered: