1 , preface
Surging by everyone so much attention, I am very surprised, such as a colleague in the company sharing the surging, as well as in the blog with other RPC framework, micro-service to do the comparison, and so on, these actions have made me feel very stressed, after all, as a personal open-source project, It is not possible to compare with the mature open source community projects, but also wait until there are many like-minded friends to join together to develop and perfect surging, so as to make surging a popular micro-service framework.
This article describes how to use the surging
Open Source Address: https://github.com/dotnetcore/surging
2
, Design Patterns
The surging offers the following four design modes
2.1
Proxy Mode
Different microservices are called by proxy. and the needle controls its access for the rule, as shown in:
2.2
Asynchronous Message Pattern
The MicroServices-based architecture chooses to use Message Queuing instead of the request/response pattern when dealing with waiting and blocking issues, as shown in:
2.3 Chain Mode
This mode responds to each other when the request is received, as shown in the following:
Service a receives the request and communicates with service B, and Service B communicates with service C. Communication between all services uses Netty-based RPC traffic.
2.4 Branch Mode
This mode allows multiple service providers to be called to merge data for return, as shown in:
3
, external how to interact
Services are processed primarily for submitted data, and are processed in the form of unified access to a single service or multiple service calls, as shown in
The gateway includes the following features:
- Secure Identity authentication
- Unified Access
- Flow control
- Shunt control
- Data monitoring
- Cache blocking
2. Simple Example Server
var host = new Servicehostbuilder (). Registerservices (option=> {option. Initialize (); Initializes the service option. Registerservices ();//Dependency Injection domain service option. Registerrepositories ();//Dependency Injection warehousing option. Registermodules ();//dependency inject 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 option. Useconsulmanager (New Configinfo ("127.0.0.1:8500"));//Use Consul to manage option. Usedotnettytransport ();//Use Netty to transfer option. Userabbitmqtransport ();//Use RABBITMQ to transfer option. ADDRABBITMQADAPT ()///RABBITMQ-based consumption service is adaptable to builder. Register(p = new Cplatformcontainer (servicelocator.current));//Initialize injection container}); }) . Subscribeat ()//message subscription. Useserver ("127.0.0.1", 98)//. Useserver ("127.0.0.1", 98, "true")//Automatically generate tokens//. Useserver ("127.0.0.1", 98, "123456789")//fixed password token. Usestartup<startup> (). Build (); using (host. Run ()) {Console.WriteLine ($ "Server started successfully, {DateTime.Now}. "); }
Service Routing Access configuration
On the interface, add the following attribute (the Uniform method configuration is not yet implemented)
[Servicebundle ("api/{service}")]
Service creation proxy call (requires interface creation proxy)
Servicelocator.getservice<iserviceproxyfactory> (). Createproxy<t> (Key)
The service is called according to Routepath (no dependency interface, low coupling)
Servicelocator.getservice<iserviceproxyprovider> (). Invoke<string> (model, PATH, Servicekey)
Local module and service invocation
Servicelocator.getservice<t> (Key)
Through the above configuration, can be accessed through the gateway, if we want to access the interface Iuserservice, the method is GetUser, the rules of the route map [Servicebundle ("api/{service}/{method }"), the converted address should be api/user/getuser,
The effect of using the Postman test is as follows:
4. Summary
Surging external through the API Gateway Rest Access, internal through the Netty RPC access, surging is still constantly improving, help documents are also in the rush, please wait patiently. If interested please pay more attention or join QQ Group: 615562965
Based on the. NET Core MicroServices Framework-an analysis of how to use surging