NATS microservice and client not reconnecting
See original GitHub issueBug Report
Current behavior
If a microservice app or client can’t connect to NATS server, or disconnects after connected, it throws an error but never tries to reconnect.
Input Code
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
transport: Transport.NATS,
options: {
url: 'nats://localhost:4222',
maxReconnectAttempts: -1,
},
});
Expected behavior
It should reconnect according to the connect options which sets maxReconnectAttempts
and reconnectTimeWait
.
Further things
- The app never starts if there is no connection, instead it should retry until connected and then continue to start
- If connection is lost after initially connected,
ClientProxy.send()
throws an error on first call, but then does not throw an error anymore. It shows an log in console “NatsError: Connection closed” but does not throw an error. - I dont see any hooks for logging. E.g. when the connection is lost I want to log an error and when the connection is back I want to log that, too. -> EDIT: Hooks are there but not accessible, see #6692
Environment
Nest version: 8.0.0-alpha.3
For Tooling issues:
- Node version: 15.6.0
- Platform: macOS Big Sur
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Connection / Type Error in a hyprid App with NATS · Issue #1765
I start a hypride service with NATS in a docker env. If this has to connect to a url that is not localhost,...
Read more >Automatic Reconnections - NATS Docs
Upon re-connection the client library will automatically re-establish all the subscriptions, there is nothing for the application programmer to do.
Read more >Building a microservices architecture with NATS - Medium
Instead of connecting microservices in a point to point manner, NATS uses a hub-and-spoke topology where all the microservices are connected ...
Read more >NATS Messaging - ThinkMicroservices.com
NATS clients connect and communicate with NATS servers. ... When you add a messaging dependency to your microservice architecture it is ...
Read more >IP Security For Broadcasters: Part 10 - NATS Advanced ...
... control between apps and microservices and NATS messaging helps keep ... virtualization in mind from the outset, not as an afterthought.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @ceoro9! Let’s track this here https://github.com/nestjs/nest/pull/6696
Thanks for all your afforts!