The content of the invention
It is a primary object of the present invention to propose that a kind of micro services provide method, apparatus and system, it is intended to solve related skillIn art in correlation technique for micro services module by container dynamic expansion and deployment when, be required for by hand go configuration andThe problem of managing the issue of micro services.
To achieve the above object, a kind of micro services provided in an embodiment of the present invention provide method, and methods described includes:In incognitoBusiness gateway receives the service access request that service consumer is sent;The micro services gateway is inquired about according to the service access requestThe service available address information list pre-set, it is determined that providing the micro services module of the service;The micro services gateway is by instituteThe address information for stating micro services module feeds back to the service consumer, and service access is carried out for the service consumer.
Preferably, the service available address that the micro services gateway is pre-set according to service access request inquiry is believedList is ceased, it is determined that providing the micro services module of the service includes:The micro services gateway is inquired about according to the service access requestThe service available address information list, it is determined that multiple micro services modules of the service can be provided;The micro services gateway passes throughPoll or hash algorithm carry out load balance process to the service access request, determine to provide from the multiple micro services moduleThe micro services module of the service.
Preferably, the service access request load by poll or hash algorithm in the micro services gatewayWeighing apparatus processing, after the determination of the multiple micro services module provides the micro services module of the service, methods described also includes:It is describedMicro services gateway is by the route service access requests by the micro services module to determination;Described in the micro services gateway receivesThe service output information that micro services module returns;The micro services gateway returns to the service consumption by output information is servicedSide.
Preferably, methods described also includes:The micro services gateway disappearing the service output information storage to internalCease middleware;The micro services gateway is held the data logging that micro services access by the record of the message-oriented middlewareLongization records.
Preferably, before the service access request that micro services gateway receives that service consumer is sent, methods described is also wrappedInclude:Micro services gateway be respectively each micro services module provide SDK (Software Development Kit,Referred to as SDK) agency's bag, wherein, the SDK agencies bag carries the interface of service dynamic registration, and the SDK acts on behalf of bag and is used forMicro services module calls the interface to complete service dynamic registration.
Preferably, it is respectively that methods described is also wrapped after each micro services module provides SDK agency's bags in micro services gatewayInclude:Micro services gateway receives the service registration information of micro services module, and service registration information dynamic is written into serviceIn registry.
Preferably, after service registration information dynamic is written in service registry storehouse, methods described also includes:Service providing state after micro services gateway is disposed to micro services module is verified;The service module is carried after being proved to be successfulThe service registration information of confession is written in service load balancing and routing table.
Preferably, after service registration information dynamic is written in service registry storehouse, methods described also includes:The micro services gateway gets the current status information of micro services module by the api interface in SDK agency's bags in real time;When the status information exception, the micro services gateway can by the service that the micro services module provides from service available addressRemoved in information list.
Another aspect according to embodiments of the present invention, additionally provide a kind of micro services and device is provided, applied to micro services netClose, methods described includes:
Receiving module, for receiving the service access request of service consumer transmission;
Determining module, for inquiring about the service available address information list pre-set according to the service access request,It is determined that provide the micro services module of the service;
Feedback module, for the address information of the micro services module to be fed back into the service consumer, for the clothesBusiness consumer carries out service access.
Another further aspect according to embodiments of the present invention, additionally provide a kind of micro services and system is provided, including:It is one or moreMicro services module, Docker containers and micro services gateway, wherein, one or more of micro services modules are respectively by describedDocker containers Dynamical Deployment or by hand deployment;
One or more of micro services modules, for service registration request to occur to the micro services gateway;
The micro services gateway, noted for receiving the service registration request of the micro services module, and according to the serviceThe registration to one or more of micro services modules is completed in volume request.
Preferably, the micro services gateway, it is additionally operable to receive the service access request that service consumer is sent, according to describedThe service available address information list that service access request inquiry is pre-set, it is determined that providing the micro services module of the service;WillThe address information of the micro services module feeds back to the service consumer, and service access is carried out for the service consumer.
By the embodiment of the present invention, micro services gateway receives the service access request that service consumer is sent;According to describedThe service available address information list that service access request inquiry is pre-set, it is determined that providing the micro services module of the service;WillThe address information of the micro services module feeds back to the service consumer, and service access, solution are carried out for the service consumerIn correlation technique of having determined for micro services module by container dynamic expansion and deployment when, be required for by hand go configuration andThe problem of managing the issue of micro services, realization service is realized from registration, and support controlling stream and data stream separation.
Embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not intended to limit the present invention.
Describe to realize the mobile terminal of each embodiment of the present invention referring now to accompanying drawing.In follow-up description, useFor represent element such as " module ", " part " or " unit " suffix only for be advantageous to the present invention explanation, itselfNot specific meaning.Therefore, " module " can be used mixedly with " part ".
With reference to the micro services framework thought of currently most main flow, the embodiment of the present invention uses for reference the core of traditional ESB service busDesign logic and construction characteristic, with reference to, for high-performance, height extends and Docker container dynamic integrities in micro services frameworkDemand, propose a kind of high performance micro services net of light weight for meeting operator's internal business systems modularization and serviceization and transformingClose.
The content bag of service access and the unified management and control, wherein management and control of all micro services modules is realized by micro services gatewayService broker is included, service safe, dynamic load leveling, service is from registration, the core competence such as service invocation message records.Pass throughMicro services gateway, the operation system modularization transformation inside operator and ability can be preferably promoted to provide.
Based on above-mentioned micro services gateway, a kind of micro services provided in an embodiment of the present invention provide method, and Fig. 2 is according to this hairThe micro services of bright embodiment provide the flow chart of method, and as indicated with 2, this method includes:
Step S202, micro services gateway receive the service access request that service consumer is sent;
Step S204, the service available address information that micro services gateway is pre-set according to service access request inquiry arrangeTable, it is determined that providing the micro services module of the service;
The address information of the micro services module is fed back to the service consumer by step S206, micro services gateway, for the clothesBusiness consumer carries out service access.
By above-mentioned steps, due to introducing micro services gateway, solve in correlation technique for micro services module logicalWhen crossing container dynamic expansion and deployment, the problem of being required for going to configure and managing the issue of micro services by hand, reality is realizedNow service supports controlling stream and data stream separation from registration.
Preferably, the service available address information that the micro services gateway is pre-set according to service access request inquiry arrangesTable, it is determined that providing the micro services module of the service includes:The micro services gateway inquires about the service according to the service access request canWith address information list, it is determined that multiple micro services modules of the service can be provided;The micro services gateway is calculated by poll or HashMethod carries out load balance process to the service access request, determines to provide the micro services mould of the service from the plurality of micro services moduleBlock.
Preferably, the service access request is carried out at load balancing by poll or hash algorithm in the micro services gatewayReason, after the determination of the plurality of micro services module provides the micro services module of the service, this method also includes:The micro services gatewayBy the route service access requests by the micro services module to determination;The micro services gateway receives the clothes of micro services module returnBusiness output information;The micro services gateway returns to the service consumer by output information is serviced.
Preferably, this method also includes:The micro services gateway is by among service output information storage to internal messagePart;The micro services gateway is by the record of the message-oriented middleware, the data logging progress persistence record that micro services are accessed.
Preferably, before the service access request that micro services gateway receives that service consumer is sent, this method also includes:Micro services gateway is respectively each micro services module offer SDK agency's bags, wherein, the SDK acts on behalf of bag and carries service dynamic noteThe interface of volume, SDK agencies bag call the interface to complete service dynamic registration for micro services module.
Preferably, it is respectively that this method is also wrapped after each micro services module provides SDK agency's bags in micro services gatewayInclude:Micro services gateway receives the service registration information of micro services module, and service registration information dynamic is written into service noteIn volume storehouse.
Preferably, after service registration information dynamic is written in service registry storehouse, this method also includes:In incognitoService providing state after business gateway is disposed to micro services module is verified;The service module is provided after being proved to be successfulService registration information is written in service load balancing and routing table.
Preferably, after service registration information dynamic is written in service registry storehouse, this method also includes:This is micro-Gateway gets the current status information of micro services module by the api interface in SDK agency's bags in real time;When the stateDuring Information abnormity, the micro services gateway can by service that the micro services module provides from service available address information list it is clearRemove.
The embodiment of the present invention additionally provides a kind of micro services and provides device, and Fig. 3 is micro services according to embodiments of the present inventionThe block diagram of device is provided, as indicated at 3, applied to micro services gateway, the device includes:
Receiving module 32, for receiving the service access request of service consumer transmission;
Determining module 34, for inquiring about the service available address information list pre-set according to the service access request,It is determined that provide the micro services module of the service;
Feedback module 36, for the address information of the micro services module to be fed back into the service consumer, disappear for the serviceFei Fang carries out service access.
The micro services framework (being substantially still the single application modularization of itself and serviceization) that the embodiment of the present invention introduces,One micro services typically completes some specific function, such as order management, customer account management etc..Each micro services are one micro-Type application, there are oneself hexagon framework, including business logic and various interfaces.Some micro services are other by exposure APIUsed in micro services or applications client;Some micro services are then realized by webpage UI.Operationally, each example is typically oneIndividual cloud virtual machine or Docker containers.
The main of the core of micro services framework includes, and one forms the small application of an independence (from DB to UI) enough, itsIt can only be interacted between the application of two micro services by Service API, thirdly typically operating in cloud virtual machine or lighterOn Docker containers.
In order to solve the above problems, a core emphasis is just the introduction of cloud platform and SOA core architecture thought, will passMultiple micro services modules for self-government are broken in the polymeric monomer application of system, to realize high-performance and resilient expansion ability.
In the implementation process of operation system modularization and serviceization, because operation system has been broken up as multiple autonomiesMicro services module, can only interact and communicate by exposed service between each micro services module, in such a scenarioQuantity of service can be exponentially growth.
A kind of micro services being additionally provided according to embodiments of the present invention system being provided, Fig. 4 is according to embodiments of the present invention micro-The schematic diagram of service system, as shown in figure 4, including:One or more micro services modules, Docker containers and micro services netClose, wherein, one or more micro services modules are disposed by the Docker containers Dynamical Deployment or by hand respectively;
One or more micro services modules, for service registration request to occur to the micro services gateway;
The micro services gateway, for receiving the service registration request of the micro services module, and according to the service registration requestComplete the registration to one or more micro services modules.
Preferably, the micro services gateway, it is additionally operable to receive the service access request that service consumer is sent, according to the serviceThe service available address information list that access request inquiry is pre-set, it is determined that providing the micro services module of the service;This is micro-The address information of service module feeds back to the service consumer, and service access is carried out for the service consumer.
By being wrapped in SDK service brokers built in micro services inside modules, realize micro services module automatic by DockerWhen deployment, the registration service dynamically provided by micro services gateway carries out the registration of micro services module.By in incognitoLoad-balancing algorithm built in business intra-gateway (including polling algorithm and HASH algorithms realize the dynamic to micro services call requestLoad balancing).By being wrapped in SDK service brokers built in micro services inside modules, the quasi real time heartbeat to micro services module is realizedDetection, once micro services module provides service fault, i.e., it is registered in inventory from available service and disabled.Realize that micro services accessThe separation of controlling stream and data flow, i.e., call for micro services and carried out by the two-stage, the first stage conducts interviews control, authenticatesAnd route;Second stage carries out actual data flow and accesses and transmit.
Include as shown in figure 4, service dynamic registration is realized:When micro services Development of Module, micro services gateway can carryMicro services Development of Module side is given for SDK agency's bags of a local.This is acted on behalf of SDK and provides the Rest API for calling micro services gatewayService the interface of dynamic registration.Micro services module is designed and developed.Micro services module can after the completion of designing and developingTo carry out Dynamical Deployment by Docker containers, also support module is disposed by hand.When micro services module starts, meetingThe service registry interface in SDK bags is called in triggering, and the interface can get the IP address of the micro services module of Dynamical Deployment completionInformation, there is provided Rest api interface address informations etc..After micro services gateway receives log-on message again, reversely service registry is believedBreath dynamic is written in service registry storehouse.After service registry is successfully written, micro services gateway is disposed to micro services moduleService providing state afterwards is verified, the service registration information that the service module provides is written into service after being proved to be successful(table is managed by the caching management module of gateway, i.e., dynamically refreshes in micro services gateway for load balancing and routing tableAvailable service list cache information.
Illustrate below and service registry process is described in detail.
Connect as currently there are OrderManage order management micro services modules to provide QueryOrderInfoSrv services APIMouthful.I.e. whole interior logic is as follows when the micro services module is registered first:
OrderManage components are packaged as independent EAR or WAR bags, built-in wherein micro services SDK bags.OrderManage components complete the automatically dispose of micro services module by Docker containers.
It is the module assignment dynamic IP addressing information after the completion of the deployment of Docker containers, such as 10.0.0.1, SDK bags pass throughGetModuleIP api interfaces get the dynamic IP addressing information of micro services module.
SDK bags call the dynamic Service registration interface of micro services gateway, it is assumed that and the address of micro services gateway is 12.0.0.1,I.e. call request is http://12.0.0.1/Register/Service.jsonIP=10.0.0.1&name=QueryOrderInfoSrv&AddressPath=***.
Registration request is written in available service registration table by micro services gateway after call request is received.When in incognitoModule of being engaged in is because under big concurrent access request, when there is dynamic expansion, i.e. OrderManage passes through Docker automatic deploymentsOne new calculate node, it is same that order data inquiry API service ability is provided.OrderManage components (node 2) pass throughDocker containers complete the automatically dispose of micro services module.After the completion of the deployment of Docker containers for the module assignment dynamic IPLocation information, such as 10.0.0.2, the dynamic IP addressing that SDK bags get micro services module by GetModuleIP api interfaces are believedBreath.
SDK bags call the dynamic Service registration interface of micro services gateway, it is assumed that and the address of micro services gateway is 12.0.0.1,I.e. call request is http://12.0.0.1/Register/Service.jsonIP=10.0.0.2&name=QueryOrderInfoSrv&AddressPath=***.
Registration request is written in available service registration table by micro services gateway after call request is received.CompleteAfter above step, being serviced for QueryOrderInfoSrv in service can be with information in registration table:
And the address that now micro services gateway is exposed to outside is:http://12.0.0.1/OrderManage/QueryOrderInfoSrv, i.e., when consumer calls gateway address, it be able to will be taken come dynamic according to load-balancing algorithmBusiness request is forwarded in available micro services module.As balanced dynamic by request assignment to 10.0.0.1 or 10.0.0.2 it is differentMicro services module.
The implementation process (record data daily record scene) of micro services consumption mainly includes:Service and visit under log sceneThe controlling stream and data flow asked all will be by micro services gateways.The micro services that service consumer calls micro services gateway to provide provideRest API address informations.For micro services gateway after service access request is received, dynamic inquiry can currently provide the clothesThe micro services module's address information list of business.Micro services gateway enters service access request by poll or HASH algorithms and loadedEquilibrium, i.e., service access request is evenly distributed to different multiple micro services modules.Micro services gateway is by service accessMessage storage is inputted to the message-oriented middleware of intra-gateway.The step is asynchronous process, and the calling for not interfering with normal service is rungShould.Micro services gateway after load balancing by route service access requests by providing module to original micro services.Micro servicesThere is provided module to be handled according to service response request, and return to service output information and give micro services gateway.Micro services gateway willReturn information storage is serviced to internal message-oriented middleware.Service return information is returned to final service and disappeared by micro services gatewayFei Fang.Micro services gateway is by the record of message-oriented middleware, the data logging progress persistence record (file that micro services are accessedOr database table)
Service access controlling stream and data stream separation under the scene.It is micro- that service consumer calls micro services gateway to provideService provides Rest API address informations.For micro services gateway after service access request is received, dynamic inquiry currently can be withThe micro services module's address information list of the service is provided.Micro services gateway enters service access request by poll or HASH algorithmsLoad balancing is carried out, by the original micro services API address informations for needing finally to access to service consumption after load balancing is carried outSide.The address information that service message root returns according to micro services module, the consumption and access of micro services are directly carried out, getting needsThe service to be returned output.
Micro services gateway dynamic monitors, and the local SDK that micro services gateway provides acts on behalf of bag can be with micro services module togetherDeployment.SDK agency's bags provide the probe api interface of the currently available state of service of micro services module offer.Micro services gatewayThe current health status of micro services module quasi real time can be got by the api interface.When the status information exception of acquisitionWait, micro services gateway can remove the service that the micro services module provides from service available address list information.
By the embodiment of the present invention, following effect is realized:Because using Docker, easily and service arrangement process is closeCarry out, realize service from registration;Controlling stream and data stream separation, current ESB buses is supported not to support the pattern;Realize to micro-Quasi real time healthy heartbeat detection and the failure transfer of service.
It should be noted that herein, term " comprising ", "comprising" or its any other variant are intended to non-rowHis property includes, so that process, method, article or device including a series of elements not only include those key elements, andAnd also include the other element being not expressly set out, or also include for this process, method, article or device institute inherentlyKey element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that including thisOther identical element also be present in the process of key element, method, article or device.
The embodiments of the present invention are for illustration only, do not represent the quality of embodiment.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment sideMethod can add the mode of required general hardware platform to realize by software, naturally it is also possible to by hardware, but in many casesThe former is more preferably embodiment.Based on such understanding, technical scheme is substantially done to prior art in other wordsGoing out the part of contribution can be embodied in the form of software product, and the computer software product is stored in a storage mediumIn (such as ROM/RAM, magnetic disc, CD), including some instructions to cause a station terminal equipment (can be mobile phone, computer, clothesBusiness device, air conditioner, or network equipment etc.) perform the method that each embodiment of the present invention is somebody's turn to do.
The preferred embodiments of the present invention are these are only, are not intended to limit the scope of the invention, it is every to utilize this hairThe equivalent structure or equivalent flow conversion that bright specification and accompanying drawing content are made, or directly or indirectly it is used in other related skillsArt field, is included within the scope of the present invention.