From the course: Node.js: Microservices
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Removing expired services - Node.js Tutorial
From the course: Node.js: Microservices
Removing expired services
- [Instructor] Later services will register and unregister themselves, but there may be cases when a service just shuts down non-gracefully with no chance to unregister. Let's make it a rule that services need to send some kind of a heartbeat to reregister themselves continuously, and that the service that we haven't seen for some amount of time is considered to be expired. We already have everything to build this inner registry, services can update themselves and there is already a timeout property. So all that is left is to add one function that does the work. So I go into lib registry and there right on top, I will add a new method, cleanup. So the first thing we will do is we get the current term const now = Math.floor(new Date() ) and we divided by a thousand. This gives us the Unix timestamp in seconds. So that's the time since I think January 1st, 1970 in seconds. And if you remember, we also stored this…
Contents
-
-
-
-
-
-
What's your goal for this chapter?1m 59s
-
(Locked)
Setting up the registry5m 6s
-
(Locked)
Registering services6m 55s
-
(Locked)
Creating and testing the registration route5m 9s
-
(Locked)
Unregistering services9m 27s
-
(Locked)
Querying the registry8m 23s
-
(Locked)
Removing expired services7m 18s
-
(Locked)
Registering on service on start5m 9s
-
(Locked)
Adding heartbeat and unregistering on shutdown4m 53s
-
-
-
-
-