In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Net Core distributed micro-service framework Jimu case analysis, in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
I. Preface
Following the popularity of micro-services from the winform era to the present, I saw the surging project (another open source .net Core micro-service framework) last winter and suddenly wanted to implement one on my own (like to repeat wheels), so I read all kinds of blogs, news, comments and code online, understood the concept of micro-services, and combined with online open source code and ideas. Barely cobbled together a micro-service framework with few features-Jimu (Chinese name: building blocks).
However, the features of the framework are like cleavage, crowding still exists: Jimu is an easy-to-use micro-service framework based on .net Core 2.0. it uses a large number of open source libraries, supports distributed, high concurrency and load balancing, and implements service governance and RPC calls. In the continuous iterative development of Jimu, many features are still scheduled (such as visual monitoring and management tools, hot updates, service breakers, current limits and downgrades.). If you are not a master who is not fussy, it is not recommended to go to the production environment. As the text-building blocks, I hope to use her to develop projects as simple, fast and controllable as building blocks, so that the project is safe, reliable and stable, and the overall architecture can be expanded, highly concurrent and distributed.
II. Functional technology
Service registration: specify server address, or support other applications through extension (e.g. consul-supported, redis, zookeeper)
Service Discovery: specify server address, or support other applications through extension (e.g. consul-supported, redis, zookeeper)
Service invocation: implement RPC invocation using DotNetty or Flurl.Http
Service proxy: Microsoft.CodeAnalysis parsing service interface generates dynamic proxy
Health monitoring: Quartz.Net scheduled Socket tasks to check the server heartbeat
Load balancing: polling algorithm (not implemented: weighted polling, minimum number of connections, random, weighted random, source address hash)
Authorization authentication: jose-jwt implements JWT authorization
Serialization: Json.Net
Syslog: log4net, NLog
III. Frame diagram
As shown in the figure, there are four roles:
Client: all kinds of clients, this is an abstract term, as long as they visit ApiGateway, they all belong to the client (mobile phones, computers. If Service Server1 and Service Server2 visit ApiGateway, they also belong to the client).
ApiGateway: service gateway through which the outside can access internal services. Gateway is a very important role, it acts as an intermediary between external and internal services, responsible for receiving and responding to external requests, as well as invoking internal services, as well as service governance and other functions.
Service Discovery Server: responsible for keeping registered services, which is equivalent to the roster of services. Service Server registration service is to record their names to the roster. ApiGateway discovery service is to go to the roster to find out which registered services are available.
Service Server: this is the micro service, where all the business requirements are implemented.
4. How to use it
Service registration and discovery have been implemented in two ways:
Do not rely on third-party applications and register directly to the local service. See Quick Start on github
Depending on consul, you need to start consul first, and then the service registers consul, and ApiGateway accesses consul discovery service.
Let's use consul as a service container to demonstrate how to use Jimu to implement a distributed micro-service
1. Start consul
Download and install consul https://www.consul.io/downloads.html
Start
Consul agent-dev2. Micro service project
Create a class library project based on .net Core 2.0 and add jimu dependencies
Install-Package Jimu
Add services, reference space: using Jimu
[JimuServiceRoute ("api/ {Service}")] / / RPC call path public class UserService: IJimuService {[JimuService (CreatedBy = "grissom")] / / specify the metadata of the service. The service call path is api/user/getname?id= public string GetName (string id) {
Return $"user id {id}, name enjoy!";} 3. Microservice server project
Create a console project based on .net Core 2.0 and add Jimu.Server and Jimu.Common.Discovery.ConsulIntegration dependencies
Install-Package Jimu.ServerInstall-Package Jimu.Common.Discovery.ConsulIntegration
Add server startup code to the Main function, reference space: using Jimu.Server
Static void Main (string [] args) {
Var hostBuilder = new ServiceHostServerBuilder (new Autofac.ContainerBuilder ()) .UseLog4netLogger () .LoadServices ("QuickStart.Services"). UseDotNettyForTransfer ("127.0.0.1", 8001). UseConsulting ForDiscovery ("127.0.0.1", 8500, "JimuService"); using (var host = hostBuilder.Build ()) {host.Run (); Console.ReadLine ();} 4. Microservice client (ApiGateway) project
Create an Asp.Net Core Web application based on .net Core 2.0 (optional API project template) and add Jimu.Client and Jimu.Common.Discovery.ConsulIntegration dependencies
Install-Package Jimu.ClientInstall-Package Jimu.Common.Discovery.ConsulIntegration
Modify the code of the Startup.cs class to add support for jimu
Using Jimu.Client
Using Jimu.Client.ApiGateway
Public class Startup {
Public Startup (IConfiguration configuration) {Configuration = configuration;} public IConfiguration Configuration {get;} / / This method gets called by the runtime. Use this method to add services to the container. Public void ConfigureServices (IServiceCollection services) {/ / services.AddMvc (); services.UseJimu ();} / / This method gets called by the runtime. Use this method to configure the HTTP request pipeline. Public void Configure (IApplicationBuilder app, IHostingEnvironment env) {if (env.IsDevelopment ()) {app.UseDeveloperExceptionPage ();} / app.UseMvc () Var host = new ServiceHostClientBuilder (new Autofac.ContainerBuilder ()) .UseLog4netLogger () .UsePollingAddressSelector () .UseDotNettyForTransfer () .UseServerHealthCheck (1) .SetDiscoveryAutoUpdateJobI nterval (1) .UseConsulting ForDiscovery ("127.0.0.1", 8500, "JimuService") .build () App.UseJimu (host); host.Run ();}} 5. Start both the server and the client
Then visit: http://localhost:58156/api/user/getname?id=666 in the browser
This is the answer to the instance analysis question of .net Core distributed micro-service framework Jimu. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.