In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the use and configuration of the gateway in the .NET CORE micro-service. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Brief introduction
In the system application of micro-service, the gateway system uses ocelot,ocelot, which is more mature at present.
Ocelot will not introduce it. After the overall introduction, we will introduce all kinds of extensions. Ocelot source code address: https://github.com/ThreeMammals/Ocelot
Ocelot is currently composed of many functional components, each of which can be extended according to its own actual situation (not to be introduced too much for the time being)
The following mainly introduces the things that individuals think should be dealt with first in the use of ocelot gateway
Health examination
In practical applications, multiple gateway projects will be deployed, and then the soft load will be carried out through nginx. In the process of updating and deploying the gateway project, the service must not be available. At this time, we need to use the health check mechanism of nginx to control it.
The gateway needs to provide a health check address to nginx. The url path address used by ocelot is used for route matching. If it fails to match, it will return 404, so we need to deal with a health check address separately.
Ocelot provides a middleware configuration replacement method OcelotPipelineConfiguration. We extend the PreErrorResponderMiddleware middleware method of OcelotPipelineConfiguration as follows:
Gateway and routing configuration
The configuration of the gateway consists of four parts, ReRoutes, DynamicReRoutes, Aggregates and GlobalConfiguration
The default way to obtain ocelot configuration is to use configuration files. As mentioned above, gateways generally deploy multiple servers, but there are still some disadvantages in using file configuration.
The configuration acquisition method of ocelot is IFileConfigurationRepository interface, so if we implement this interface, we can satisfy the extension of configuration storage mode. Mysql and redis have been extended as follows
Redis:
Mysql:
You can see that not all of the four configurations are configurable. If there is a need, you can add your own fields to implement.
Redis is stored in large json mode, while mysql is striped one by one, because configuration management is dominated by mysql and then synchronized to other storage media.
Update of gateway configuration
Where there is load, there is update. The update configured in ocelot uses its own implementation to complete the hot update of the configuration, as follows
1. The configuration file is used to reload the configuration information through the OnChange of the IOptionsMonitor of the configuration file.
2. The third-party storage method is used to obtain configuration information through the FileConfigurationPoller method implemented by default (default 1s).
So we extend the get configuration form and inject FileConfigurationPoller HostedService into it when registering. The code is as follows
When it comes to Bucket.DbContext and Bucket.Redis components, it is very simple and can be implemented by yourself.
Management of configuration
In fact, at the beginning, the consul storage configuration was used, and then the configuration was managed through the configuration interface of the gateway, but there was a problem during an upgrade of ocelot (loss of configuration information). Although the ocelot source code was modified at that time to solve the problem, it was decided to expand the storage method, so the above set methods for obtaining the configuration interface were not implemented.
As mentioned above, mysql has configured the storage and synchronized it to other media, so all we have to do is maintain the mysql database.
So much for sharing about the use and configuration of gateways in .NET CORE micro-services. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.