Service-Oriented Architecture SOA preamble
In the world of. NET, when it comes to SOA, you should think of web service,wcf, and someone might also mark the Web API in. NET MVC and talk about it in general!
Indeed, Microsoft's technology is really driving the world of service-oriented development, except that Microsoft has many services-oriented open source technologies that are even better than Microsoft in some ways. So what is service-oriented and what is service-oriented presence to solve?
Talk about SOA service-oriented
SOA was a concept presented by Garnter in 1996, designed to make software resilient, responsive to business needs, and real-time enterprises. The basic idea is to connect the services and interfaces that need to be integrated in all information systems, interface neutrality, regardless of the development platform and programming language. This also makes the heterogeneous information system can be developed, "Information Island", re-build wheels and other issues in the SOA architecture.
Simply put, SOA is different services to establish different service, the service between the services can be a coarse-grained service interface classification, so loose coupling to improve the reusability of services, but also make the business logic can be combined, and each service can be based on the use of reasonable distributed deployment, so that the service becomes the specification, High performance, highly available.
So let's start by looking at what Microsoft has done in this area, and how software development is a process of change.
The development of code reuse technology
Process-oriented (in-app/process-level multiplexing)----> Object-oriented (in-app/class-level multiplexing)---> Component-oriented (in-app/component-level multiplexing)---> Distributed components (Inter-application/component-level multiplexing)----> Service-oriented (application/service-level multiplexing)
Microsoft Technology for service delivery
So for a diagram above, do a short explanation, first of all, TCP and HTTP protocol comparison , the two protocols have their own strengths:
TCP-based protocol: it can reduce the number of bytes transmitted by network, reduce the cost of internet, high efficiency, but complex, and because of the different protocols and standards, difficult to cross-platform, and easy communication between enterprises, and when the service is more and more, the load-accumulation strategy, service address management and configuration will become complex and cumbersome, There is no good open source support at the moment.
Based on the HTTP protocol: Then he compared to TCP, first he is built on the TCP/IP protocol, the efficiency is lower than TCP, the transmission byte is more than TCP, so he transmits the time to occupy the President, Of course we can also use some gzip data compression, such as data compression or similar to Hessain,thrift and so on to transmit 2 of data stream, reduce the data transmission volume reduction and TCP gap, of course, HTTP is also a lot of its own advantages, such as his existence is inherently able to solve the problem of heterogeneous calls, There are a lot of mature open source solutions to deal with high traffic and concurrency in the case of Iis,nginx,tomcat,apache and so on.
So the above two kinds of agreement, each has its own short, everyone picking good.
Various data serialization comparisons
The choice of data transfer Protocol is also based on your own needs, in the world of. NET I think JSON and XML should be widely used by everyone. Then there are those object serialization is common in network transmission, Hessian,thrift is also more commonly used. There are a lot of comparisons on the Internet, which I took down from the Internet, in fact, for reference only.
. NET uses Hessian to serialize, implementing HTTP protocol-based RPC
For the above test diagram, we can see that Hessian is also a good choice, then here I will write a. Net MVC use Hessian Small example, for everyone to learn the reference, also experience the RPC style hessian how convenient.
Hessian also supports n-multi-language, and he uses a service framework that is transmitted in binary format, which is 10 times times more efficient than soap transmissions. So lighter and faster, official website address: http://hessian.caucho.com/
Then we abandon the framework of WEBSERVICE,WCF,WEBAPI such as Microsoft, and use the open source Hessian to implement remote calls between services.
1. Service Side
Reference Hessiancsharp.dll
The implementation class inherits the Chessianhandler class, referencing the namespace using Hessiancsharp.server, while implementing the Iserverice interface, IService is provided externally.
View Code
Public interface IService { string ServerName {get; } List<d_driverinfo> getdriverinfo (); D_driverinfo Getdriverinfobyucode (string ucode); }
<system.web> <compilation debug= "true" targetframework= "4.5"/>
public static void RegisterRoutes (RouteCollection routes) { routes. Ignoreroute ("{hessian}.hessian/{*pathinfo}"); Routes. Ignoreroute ("{resource}.axd/{*pathinfo}"); Routes. MapRoute ( name: "Default", URL: "{controller}/{action}/{id}", defaults:new {controller = "Home", action = "Index", id = urlparameter.optional} );
2. Client Use service
Reference Hessiancsharp.dll, the interface of the server to write down, do not implement, remote service to implement the service caller method.
Chessianproxyfactory factory = new Chessianproxyfactory (); String url = "Http://172.18.5.61:9020/HessianService.hessian";//Modify to your server-side address iservice test = (IService) factory . Create (typeof (IService), url); Object result = Test. Getdriverinfo (); list<d_driverinfo> s = hclient.runclient<iservice> (). Getdriverinfo (); Return Json (S, jsonrequestbehavior.allowget);
Note, try it, feel it easy and quick to use it?
Talking about service routing, service load balancing and service de-centering structureFirst, if your business is not very large, the service is a single deployment, then your service address can be hard-coded into your project, but if your service is not able to handle the traffic concurrency and even poor performance, then we need a distributed deployment of our services.
At first we realized this way.
Whether you go to an old-fashioned ESB, or some proxy server, you first call the request to another server and then transfer it to the service provider.
Now, how do we do that?
The Note:soa architecture provides a Client.dll that gives the caller the ability to make the caller do not have to relate to how your transport protocol is implemented and how the load algorithm is implemented, which can be configured. Then the service on each line of a machine, will automatically register the interface address and other information to the Service Configuration Center, service monitoring system will be in a timely manner to capture the status of each service, and then update storage, the client has built-in load balancing and caching functions, according to the monitoring system to provide data, client configuration information, Find the best service to the client. However all this is released on the client side. No third-party proxy server appears.
From the above two pictures, we can also draw a message, we first assume that the use of figure one, if the proxy server or the request routing distributor, such as hanging up, then all the services can not be used, there is intermediate transfer once, performance is not as good as the second kind, the second kind of no central structure, I feel still quite diao, not write This is the right place to go.
SummarizeRelatively shallow, also relatively general, if there is anything wrong, but also hope to put forward, but also welcome to join the upper left group, we exchange learning.
Service-Oriented Architecture SOA