In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the ".net Core service governance Consul health check method is", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn ".net Core service governance Consul health check method is what" bar!
Health examination
After previous operations, my consul has supported automatic extension, and the call is also very reliable. But there is a problem. Once a service in the service list dies, consul does not know it and will return the actual invalid address to me. Even if the consul container is restarted, it will not be able to refresh to the latest state. Therefore, we need to monitor service availability and actively distinguish unavailable services, which is called health check.
Enter the coding process. The old rule is to enter the registration method that I encapsulated before and add the content of health check-up when registering:
Client.Agent.ServiceRegister (new AgentServiceRegistration () {ID = $"server {ip}: {port}", Name = "shenzhen-ma", Address = ip, Port = int.Parse (port), Tags = new string [] {weight}) Check = new AgentServiceCheck () {Interval = TimeSpan.FromSeconds (10), / / initiate a check every 10 seconds HTTP = $"http://{ip}:{port}/v1/client/base/index",// check request address Timeout = TimeSpan.FromSeconds (5) / / timeout duration 5 seconds DeregisterCriticalServiceAfter = TimeSpan.FromSeconds (10) / / failed to connect to the service after more than 10 seconds Start to log off this service}})
The discoloration part is the configuration of the health check. Based on the above configuration, consul periodically initiates health checks and automatically removes unavailable services based on the results.
This time I want to be more rigorous and use a real remote server to simulate the production environment. There are too many servers on hand, and many projects are running. Rummaging through carefully, I found that there are two relatively idle servers, one is win server, the other is centos, hey, just right. Centos is used as the consul server and win server is used as the downstream caller.
Let's start with consul:
Go in and visit:
OK, now go to another server and run a few clients. Being lazy here, just copy the runnable files over, :
Check out the consul console:
Still familiar with shenzhen-ma, the two services are firmly in the grouping list. Notice the position I framed, which indicates that the service has passed the health check. At this time, I will turn off the 5051 program and take a look again:
The 5051 status is automatically updated to failing, and after a while, it is automatically removed. 5050 if you go to visit again at this time, you will not be able to visit 5051:
Then secretly run the 5051 and call it again:
You can visit again, don't you?
The new instance is automatically discovered, the abnormal status of the instance is automatically eliminated, and the lower call does not need any adjustment, which is comfortable. At least I feel comfortable as a lazy person.
Tips: the default state of the new service is failing. A check will be initiated immediately after the registration is successful, and the status will not be changed until successful. And the service logout is not that fast, and it usually takes longer than the setup time.
Thank you for your reading. The above is the content of "what is the .net Core service governance Consul health check method". After the study of this article, I believe you have a deeper understanding of what the .net Core service governance Consul health check method is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.