前方:
开源地址:https://github.com/cyq1162/Taurus.MVC
Microservices are involved in the planning,After hard work and constant code and repeated stress testing in recent days,Finally a simple stable version is out.
Taurus.MVC Microservice framework description:
1、The framework comes with the following functions integrated:
1、服务端:网关、注册中心 2、客户端:微服务应用程序.
因此,That is, it can run as a server,Can also run as a client,A simple demonstration is given below:
新建空项目,引入Taurus.MVC微服务框架
1、Create an arbitrary empty spaceWeb项目,以NET6为示例,在Nuget上引用Taurus.MVC,Introduce each2个的NETCore版本.
2、Program.cs Manually add startup code:
var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseUrls(CYQ.Data.AppConfig.GetApp("Host"));//The startup port is externalized to the configuration file. builder.Services.AddHttpContext();//必要1
builder.Services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true).Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);//必要2:开启同步IO读取,对POSTRequest is useful. var app = builder.Build(); app.UseHttpContext();//必要3 app.UseTaurusMvc(app.Environment);//必要4 app.Run();
补充说明:如果是.net framework 版本,When referenced, it will be in by defaultweb.configThe following launch configuration is automatically generated:
<configuration> <system.web> <httpModules> <!--Taurus IIS应用程序池:经典模式(下运行,开启此配置)--> <add name="Taurus.Core" type="Taurus.Core.UrlRewrite,Taurus.Core" /> </httpModules> </system.web> <system.webServer> <modules> <!--Taurus IIS应用程序池:集成模式(下运行,开启此配置)--> <add name="Taurus.Core" type="Taurus.Core.UrlRewrite,Taurus.Core" /> </modules> </system.webServer> </configuration>
1、注册中心:Configured as a registry
appsettings.json 配置项:
{ "AppSettings": { "MicroService.Server.Name": "RegCenter",//Set to run on the server side:注册中心
"MicroService.App.RunUrl": "http://localhost:9000",//Set the running address for startup,Can trigger default microservice startup.
"Host": "http://*:9000" } }
发布运行,become the registry(Also has a gateway function)
It is successful if you see the output information on the first and second lines.
Registry failover:
Make a copy of the registry program,修改端口,Then add the configuration pointing to the main address:
"MicroService.Server.RegUrl": "http://localhost:9000",//注册中心地址
2、网关:Configured as a gateway
Here will be the post-published project,复制一份,改一下配置文件:
{ "AppSettings": { "MicroService.Server.Name": "Gateway",//服务名称 "MicroService.Server.RegUrl": "http://localhost:9000",//注册中心地址 "MicroService.App.RunUrl": "http://localhost:9001", "Host": "http://*:9001" } }
运行,It becomes the gateway center
See the first two lines of output,即为成功,And periodically read the service list from the registry.
3、微服务应用
Copy a project as a microservice application,直接使用Taurus.MVC的WebAPIfunction to add oneHello的控制器.
Do client application configuration:
{ "AppSettings": { //The name of the assembly where the controller is located "Taurus.Controllers": "WebAPI", "MicroService.Client.Name": "Hello",//Configure the module name to be registered,Multiple commas can be separated,Domain names can be registered(Implement domain name binding) "MicroService.Client.RegUrl": "http://localhost:9000",//The address of the registration center "MicroService.App.RunUrl": "http://localhost:9002", "Host": "http://*:9002" } }
然后发布,运行即可:
Look at the first and second lines,运行成功后,The client will periodically keep the registration synchronized.
微服务负载均衡:
Only the client is required,复制多份,修改启动端口,直接运行,The gateway will automatically use round-robin load balancing.
整体运行效果:
1、直接访问应用程序:
2、通过网关访问:
3、访问注册中心(The registry can also be used as a gateway)
总结:
This article introduces the most basic use of the microservice framework,on any development framework,引用Taurus.MVC的Nuget包,Plus the simplest few lines of configuration,You can become either end of a microservice.
V3.0.3 已实现的功能:
------------------V3.0.3【Added built-in microservices(网关和注册中心)功能】---------------- 1、新增:注册中心服务注册.(2022-07-23) 2、新增:Gateway proxy forwarding.(2022-07-23) 3、新增:Gateway Security Validation([MicroService]The interface only allows inter-microservice calls when the attribute is marked).(2022-07-24) 4、新增:网关集群.(2022-07-25) 5、新增:Registry failover.(2022-07-25) 6、新增:Inter-service invocation method is provided.(2022-07-26) 7、优化:Routing is compatible with proxy forwarding.(2022-07-27) 8、优化:Unified log monitoring solution,方便问题定位.(2022-07-28) 9、新增:File proxy forwarding,Support as a website gateway.(2022-07-29) 10、优化:Taurus.Core.Controller Remove methods and properties:方法【CheckFormat】、属性【Sort、Order】.(2022-07-29) 11、新增:KestrelThe request is triggered after the next gateway and service are started(配置项:MicroService.App.RunUrl).(2022-07-29) 12、新增:Kestrel Realize multi-domain binding and forwarding.(2022-07-29) 13、优化:Registration performance optimization and concurrency testing of a large number of microservices.(2022-07-30) 14、优化:Server and client are independent.(2022-07-31) 15、新增:兼容微软mvcThe framework reference can become the micro server side.(2022-08-01) 16、新增:完成Web的Cookie转发.(2022-08-01) 17、新增:控制台日志输出,方便调试.(2022-08-01)
Additional content details for microservices,It will be covered in subsequent tutorial articles.
后续,针对Taurus.MVC ,Three series of tutorials will be re-supplemented:
1、Taurus.MVC WebAPI 入门开发教程 系列. 2、Taurus.MVC 微服务框架 入门开发教程 系列. 3、Taurus.MVC Web应用程序 入门开发教程 系列.