Microservice Concerns

The course is part of this learning path

Health Checks

In this course, we will learn the concepts of microservice and spring framework and focus on Microservice concerns.

Learning Objectives

  • Health Checks
  • Alerts
  • Error Handling
  • Security

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud


  • Basic Java knowledge

Hello, dear friends.

In this lesson, we will learn how to check and report the health of a microservice. For this, we will use microprofile health. It's included in the microprofile main dependency. If you add a microprofile to your project in this manner, it will already be included. If you do not include the main microprofile dependency in your project, you can add the microprofile health dependency only like this. It allows you to check the liveness and readiness of a service. When we start a service, you can see the health check URL of the service. It ends with the health keyword. 

It returns both readiness and liveness status of the service. When we curl it, it returns up. By the way, there are two more paths that you can add to it: live and ready. As you see here, we can get the live or ready status of the service, ready and live are almost the same expressions. The difference is that a service may be up but not ready to handle requests because of some inadequacies. We can write a readiness or liveness health check special to our project.

To do this, we need to implement the health check interface of microprofile and use one or both of the annotations: readiness, and liveness. Let's write a specialized health check for our citizen service. First, stop the number service. Okay, stopped. I go to the resource page of the citizen service project. Right-click and select new class. Give it a name like readiness check resource. I define a path variable and add readiness annotation. Because I want to find a readiness check, if I can reach the number service from citizen service, then the readiness of citizen service will be okay. Otherwise, it will be down. I implement health check and import the needed library. Now, I should override the call function.

To keep it simple, I will use a simple try-catch block. If I get the number from the national identification number service, then it will be okay. It means citizen service is ready. If I can't get the number, then it's a problem and returns a downstate. Okay, I will write the function. Now, I am starting citizen service. I won't start the number service deliberately to cause an exception. Let's check the ready status. I copied the link from the console and append ready keyword to see ready status. Okay. As you see, citizen readiness is down. Let's start the number service. Okay, it started. Now, let's check again for the ready status. As you see it is up now. Well, that was easy enough. See you in the next lesson.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.