SOA All functions in the architecture are defined as independent services . Services complete the overall logic of business through interaction and coordination . All the services
Connect through the service bus or process manager . This loosely coupled architecture makes it unnecessary to consider the internal implementation details of each service in the interaction process , And on what platform .
SOA The architecture divides the different functional units of the application into multiple subsystems according to the service modules , Advantages of doing so :
(1) Split the system into service modules , Each module is developed independently , Independent deployment , They don't influence each other , The coupling between modules is greatly reduced , Different technologies can be used behind each service module ;
(2) Split the project into several subprojects , Different teams are responsible for different subprojects , Greatly improve the development and production efficiency of the team ;
(3) When adding a business subsystem, you only need to add a sub application project , Calling the service can quickly assemble sub applications , Improve the reusability of the program , Business innovation can be carried out more quickly ;
(4) Flexible distributed deployment , Better support for online business .
stay SOA Architecture , Inherits various principles from object and component design , for example , Encapsulation and self-contained . Those that guarantee service flexibility 、 Design principles of loose coupling and reusability , Yes SOA Architecture is also very important . About services , Some common design principles are as follows :
(1) Clearly defined interfaces . The service requester relies on the service specification to invoke the service , therefore , The service definition must be stable for a long time , Once published , Can't change at will ; The definition of services should be as clear as possible , Reduce inappropriate use by requesters ; Don't let the requester see the private data inside the service .
(2) Self contained and modular . Services encapsulate those that are stable in business 、 Recurring activities and components , The functional entity that implements the service is completely independent , Deploy independently 、 version control 、 Self management and recovery .
SOA Key technologies in Architecture :
(1)SOAP: Simple object access protocol ,Simple Object Access Protocol
(2)WSDL:Web Service description language ,Web Services Description Language
(3)UDDI: Universal description 、 Discovery and integration ,Universal Description Discovery and Integration
WSDL Used to describe services ,UDDI To register and find services , and SOAP As the transport layer , Used to send messages between consumers and service providers , A consumer can be in UDDI Registry lookup service , Access to services WSDL describe , And then through SOAP To call the service .
(4)REST
REST The following design concepts and criteria are proposed :
① Everything on the network is abstracted as resources .
② Each resource corresponds to a unique resource ID .
③ Operate resources through common connector interface .
④ Various operations on resources will not change the resource ID .
⑤ All operations are stateless .
at present , Realization SOA There are many methods , The mainstream ways are Web Service、 Enterprise service bus and service registry .
(1)Web Service
stay Web Service(Web service ) In the solution of , There are three job roles , Service provider and service requester are necessary , The service registry is an optional role . The interaction and operation between them constitute SOA An implementation architecture of .
(2) Service registry
Service registry (service registry) Although it also has the function of runtime , But mainly in SOA Use... In design . It provides
Strategy execution point (Policy Enforcement Point,PEP), At this point , The service can be SOA Register in , So that it can be found And use . The service registry can include configurations about services and related artifacts 、 Compliance and constraint documentation . In theory , Any help Service registration 、 Discover and find service contracts 、 Metadata and policy information base 、 database 、 A directory or other node can be considered a The registry . Most commercial service registration products support service registration 、 Service location and service binding functions .
(3) Enterprise service bus ESB
yes SOA An implementation of , ESB In service-oriented architecture, it plays the role of bus , Connect and integrate various services , The main work is use :
Describe the metadata and service registration management of the service ;
Data is passed between the requester and the service provider , And the ability to convert these data , And support a Some modes, such as synchronous mode 、 Asynchronous mode, etc ;
Find out 、 route 、 The ability to match and choose , To support dynamic interaction between services , Decouple service requesters from service providers . Senior one Some ability , Including support for security 、 Service quality assurance 、 Manageability and load balancing .
5、 ... and 、 Microservice architecture
Advantages of microservices :
(1) Each microservice is small , This focuses on a specific business function or business requirement .
(2) Microservices can be developed individually by small teams , This small group is 2 To 5 The group of developers .
(3) Microservices are loosely coupled , It's a functional service , Both in the development and deployment phases are independent .
(4) Microservices can be developed in different languages .
(5) De centralization . Each microservice has its own storage capabilities , You can have your own database . You can also have a unified database .
Disadvantages of microservices :
(1) It's hard to implement functionality across services without distributed transactions
(2) Testing is more difficult
(3) Cross service implementation requires close collaboration between teams
(4) Complex deployment
In microservices , Application gateway API The role of :
(1) Provide a unified entrance
(2) It can carry out security management such as authority and identity authentication
(3) The current can be limited according to the flow
(4) Data caching
(5) Performance monitoring, etc
(6) Exception retry
(7) service degradation
6、 ... and 、 Lightweight Architecture
(1)SSH: refer to Struts2( Be a front-end controller ),Spring( Manage components at all levels ),Hibernate( Responsible for the persistence layer )
(2)SSM: refer to SpringMVC( Be a front-end controller ),Spring( Manage components at all levels ),Mybatis( Responsible for the persistence layer )
Hibernate And Mybatis difference :
① In terms of development : In the process of project development , In terms of speed ,hibernate In development ,sql The statement has been encapsulated , Directly available , Accelerate system development ;Mybatis It's semi-automatic ,sql It needs to be done by hand , A little fussy .
②sql Optimization :Hibernate Automatic generation sql, Some sentences are more complicated , It will consume more performance ;Mybatis Write by hand sql, Avoid unnecessary queries , Improve system performance ;
③ Object management :Hibernate It's a complete object - The framework of Relationship Mapping , In the development project , There's no need to pay too much attention to the underlying implementation , Just manage the object ;Mybatis You need to manage the mapping relationship yourself ;
④ Cache :Hibernate If dirty data occurs when using L2 cache , The system will report an error and prompt .Mybatis No error is reported for dirty reading .