What I Learned Series - 02

This is second post in What I Learned Series. I tried to summarize some information. I hope that it will be helpful for you.

HealthCheck

hacktoberfest.png

HealthCheck is the concept used to check whether the services are working healthily. Examples of these services are database context, ElasticSearch, RabbitMQ, Amazon S3, and so on.

I had to integrate this into our project at the company. Our project is an MVC project on the .Net Framework. As a result of our research, we found examples on .NET Core. You can easily add HealthCheck structure on .NET Core as a middleware. I will share the resources I have reviewed at the end. You can find how this is done from there. We used RimDev.AspNet.Diagnostics.HealthChecks repository for .Net Framework.

During the services works normal, the HealthCheck endpoint returns healthy (Http Status Code: 200). If one or more of the services are not working properly, it returns unhealthy (HTTP Status Code: 503). Here we can make configurations according to our needs. After we added this HealthCheck structure, we listen to this endpoint periodically using Uptime Robot and receive a notification when it is in an unhealthy status. In this case, we can go to the relevant endpoint and examine which service is unhealty and why the error occurred.

HacktoberFest

I had been joined HacktoberFest. HacktoberFest is an open source event created by Digital Ocean. There are some rules this event. You can find more information this link. Your aim is to sent valid four pull requests in open source github repositories between October 1- 31. I had been make it. 😊 That's was easy and funny. You can join it. Maybe you can win a t-shirt or plant a tree. 🌲

Programming

When I added some healthcheck services like RabbitMQ, We want to set timeout. There is a configuration property in RabbitMQ Connection Factory Configuration. That's nice. And I seted this property like this:

var factory = new ConnectionFactory
{
    Uri = new Uri("amqp://localhost"),
    UserName = "guest",
    Password = "password",
    RequestedConnectionTimeout = TimeSpan.FromSeconds(10).Milliseconds
                                // this is wrong
};

I just thought that TimeSpan.FromSeconds(10).Milliseconds returns 10000. I didn’t test it. The test is important. In order to do that, you have to use TotalMilliseconds instead of Milliseconds. StackOverflow Link

This is the correct:

var factory = new ConnectionFactory
{
    Uri = new Uri("amqp://localhost"),
    UserName = "guest",
    Password = "password",
    RequestedConnectionTimeout = TimeSpan.FromSeconds(10).TotalMilliseconds
                                // this is correct
};

Resources

No Comments Yet