Based on the. net core microservice framework and the. netcore framework
1Preface
I was surprised to hear that surging has received such strong attention. For example, some colleagues shared surging at the company's sharing conference, and other RPC frameworks and microservices on the blog, these actions make me feel a lot of pressure. After all, as an individual open-source project, it cannot be compared with a mature open-source community project, only when many like-minded friends join in R & D and improvement of surging can surging become a popular microservice framework.
This article introduces how to use surging
Open Source Address: https://github.com/dotnetcore/surging
2
, Design mode
Surging provides the following four design modes:
2.1
Proxy Mode
Use a proxy to call different microservices. In addition, rules are used to control access, as shown in:
2.2
Asynchronous Message Mode
When we re-process the problem of waiting and blocking, The microservice-based architecture will choose to use Message Queue instead of the request/response mode, as shown in:
2.3 Chain Mode
This mode will merge the responses after receiving the request, as shown in:
After receiving the request, service A communicates with service B, and service B communicates with service C. All services use Netty-based RPC communication.
2.4 Branch Mode
This mode allows you to call multiple service providers to merge data for return, as shown in:
3
, External interaction
The service mainly processes submitted data. For a single service or multiple service calls, the gateway can be used for unified access, as shown in
The Gateway provides the following functions:
2. Simple example Server
Var host = new ServiceHostBuilder (). registerServices (option => {option. initialize (); // Initialize the service option. registerServices (); // dependency injection domain service option. registerRepositories (); // dependency injection warehousing option. registerModules (); // dependency injection third-party module option. registerServiceBus (); // dependency injection ServiceBus }). registerServices (builder => {builder. addMicroService (option => {option. addServiceRuntime (); // option. useZooKeeperManager (new ConfigInfo ("127". 0.0.1: 2181 "); // use Zookeeper to manage the option. useConsulManager (new ConfigInfo ("127.0.0.1: 8500"); // use Consul to manage option. useDotNettyTransport (); // use Netty to transmit option. useRabbitMQTransport (); // use rabbitmq to transmit option. addRabbitMQAdapt (); // builder for the consumption service based on rabbitmq. register (p => new CPlatformContainer (ServiceLocator. current); // initialize the injection container });}). subscribeAt () // message subscription. useServer ("127.0.0.1", 98 )//. useServer ("127.0.0.1 ", 98, "true") // automatically generate Token //. useServer ("127.0.0.1", 98, "123456789") // fixed password Token. useStartup <Startup> (). build (); using (host. run () {Console. writeLine ($ "server started successfully, {DateTime. now }. ");}
Service route access configuration
Add the following features on the interface (Unified Method Configuration has not been implemented)
[ServiceBundle("api/{Service}")]
Service creation proxy call (dependent interface creation proxy is required)
ServiceLocator.GetService<IServiceProxyFactory>().CreateProxy<T>(key)
The service is called according to RoutePath (the interface is not required, and the coupling is low)
ServiceLocator.GetService<IServiceProxyProvider>().Invoke<string>(model, path, serviceKey)
Local module and service call
ServiceLocator.GetService<T>(key)
The above configuration allows access through the gateway. If we want to access the IUserService interface, the method is GetUser, the routing ing rule [ServiceBundle ("api/{Service}/{Method}")], the converted address should be api/User/GetUser,
The Postman test results are as follows:
4. Summary
Surging external access via Api gateway Rest, internal access via netty RPC, surging is still being improved, and the help documentation is also in progress. Please be patient. If you are interested, please pay more attention or join the QQ group: 615562965