O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deregistering an application

In this section, we will deregister our application whenever the server terminates or someone kills the server. This ensures that Consul doesn't have to wait until the TTL period to actually know that the service is down. Simply add the following lines of code in Application.ts:

   process.on('SIGINT', () => {  console.log('Process Terminating. De-Registering...');  let details = { id: CONSUL_ID };  consul.agent.service.deregister(details,    (err) => {      console.log('de-registered.', err);      process.exit();    });

Now, when you check Consul server when you gracefully kill the application, you won't be able to see our Consul producer registered.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required