Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms first, second and the like in the description and in the claims of the present application are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that embodiments of the application may be practiced in sequences other than those illustrated or described herein, and that the terms "first," "second," and the like are generally used herein in a generic sense and do not limit the number of terms, e.g., the first term can be one or more than one. In addition, "and/or" in the specification and claims means at least one of connected objects, a character "/" generally means that a preceding and succeeding related objects are in an "or" relationship.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a flowchart of a cross-cluster service invocation method provided in an embodiment of the present application, and referring to fig. 1, the cross-cluster service invocation method provided in the embodiment of the present application may include:
step 110, a first service end obtains an address of a target gateway from a first registration center;
the first server and the first registration center are located in a first cluster, the target gateway is located in a second cluster, and the first cluster and the second cluster can be different clusters; the first registration center stores service information of the second cluster in advance, and the service information comprises an address of the target gateway.
It is to be understood that, the obtaining the address of the target gateway may be that the first service end sends an address obtaining request to the first registry, and then the first registry sends the address of the target gateway to the first service end after receiving the address obtaining request. In addition, the first registry may be a database in the first cluster, and the first registry may be configured to store different data independently, for example, the first registry may store service information of the first cluster and service information of the second cluster.
Step 120, the first server sends a service calling request to the target gateway according to the target gateway address;
in the embodiment of the application, according to the address of the target gateway, a connection can be established with the target gateway first, and then the service calling request is sent to the target gateway through the connection; the service invocation request may be for invoking a service in the second cluster.
It should be understood that, if the target gateways of the first cluster and the second cluster are pre-connected, the service invocation request can be directly sent; if the connection between the target gateways of the first cluster and the second cluster is not established in advance, the service call request can be sent to the target gateways after the connection is established according to the target gateway addresses.
Step 130, the first service end receives a service calling result returned by the target gateway according to the service calling request.
According to the method for cross-cluster service calling, a first service end obtains an address of a target gateway from a first registration center; the first server side sends a service calling request to the target gateway according to the target gateway address; the first service end receives a service calling result returned by the target gateway according to the service calling request; the first server and the first registration center are located in a first cluster, the target gateway is located in a second cluster, the first registration center stores service information of the second cluster in advance, and the service information comprises an address of the target gateway. Therefore, the problem that communication between micro-services in the prior art cannot be carried out across clusters is solved by storing the service information of the second cluster in the first registration center of the first cluster in advance, then the first server of the first cluster acquires the target gateway address of the second cluster from the first registration center, then sends the service calling request to the target gateway, and receives the service calling result aiming at the service calling request, so that the services of other clusters are called as local services.
Optionally, in an embodiment of the present application, the service information may further include an identifier of a server in the second cluster; that is, the first registry not only stores the address of the target gateway of the second cluster in advance, but also stores the identifier of the server in the second cluster in advance. The identifier of the server may be used for the target gateway to find a corresponding server in the second cluster.
It should be understood that the service information may include the identities of all the servers in the second cluster, or may include the identities of some of the servers in the second cluster. In either case, the service information may include an identification of a target server in the second cluster, such that the target gateway finds the target server in the second cluster.
As shown in fig. 2, the method for cross-cluster service invocation provided in the embodiment of the present application may further include: the first service end obtains the identification of a target service end from the first registration center; correspondingly, the service call request sent to the target gateway carries the identifier of the target server. Afterstep 120, the method for cross-cluster service invocation provided by the embodiment of the present application may further include: the target gateway sends the service calling request to the target server according to the identification of the target server; the target server side obtains a service calling result according to the service calling request and returns the service calling result to the target gateway; and after receiving the service calling result, the target gateway sends the service calling result to the first service terminal.
Wherein the target Gateway (Gateway) may transparently forward the service invocation request to the target server according to the identifier of the target server; the target server side can process the service calling request to obtain a corresponding response; and the service calling result is a response obtained by processing the service calling request by the target service terminal.
For ease of understanding, the following are exemplified here:
as shown in fig. 2, a first server of a first cluster prepares to call a target server of a second cluster, may first obtain an address of a target gateway from a first registry of the first cluster, and the first registry may return the address of the target gateway of the second cluster to the first server; then the first server side can initiate calling of the target server side to a target gateway of the second cluster, and after receiving the service calling request, the target gateway can perform transparent proxy on the target server side; the target server side can process the service calling request, return a service calling result to the target gateway, and finally return the service calling result corresponding to the service calling request to the first server side by the target gateway.
Therefore, the connection with the target gateway of the second cluster can be established through the target gateway address, and then the target gateway finds the target server according to the identification of the target server, so that the aim of calling the services of other clusters like calling the local service is realized.
The cross-cluster service calling method provided by the embodiment of the present application is further described in detail below with reference to an actual application scenario. Referring to fig. 2, the cross-cluster service invoking method provided in the embodiment of the present application may specifically include the following steps:
step 210, the first service end obtains the address of the target gateway and the identification of the target service end from the first registration center;
step 220, the first server sends a service calling request to the target gateway according to the target gateway address, wherein the service calling request carries an identifier of the target server;
step 230, the target gateway sends the service call request to the target server according to the identifier of the target server;
step 240, the target server obtains a service calling result according to the service calling request, and returns the service calling result to the target gateway;
step 250, after receiving the service calling result, the target gateway sends the service calling result to the first service end.
According to the cross-cluster service calling method provided by the embodiment of the application, the target gateway address of the second cluster and the identification of the service end in the second cluster are stored in the first registration center of the first cluster in advance, then the first service end obtains the target gateway address of the second cluster from the first registration center, then the first service end establishes connection with the target gateway of the second cluster, then the service calling request is sent to the target gateway through the connection, and the service calling result aiming at the service calling request is received, so that the local service is called to call the services of other clusters, and the problem that cross-cluster communication cannot be carried out between micro-services in the prior art is solved.
Optionally, in an embodiment of the present application, beforestep 110, the method for invoking a cross-cluster service provided in the embodiment of the present application may further include: the first synchronization component (pilot component) sends a first synchronization request to the second agent component (agent component); the second agent component sends first synchronization information to the first synchronization component according to the first synchronization request, wherein the first synchronization information comprises service information of the second cluster; and the first synchronization component receives the first synchronization information sent by the second agent component and sends the first synchronization information to the first registration center.
Wherein the first synchronization component may be located in the first cluster and the second proxy component may be located in the second cluster. The first synchronization component may be configured to synchronize service information of the second cluster to the first registry of the first cluster; the second proxy component may be configured to be responsible for collecting service information of the second cluster, and provide convenience of service synchronization to the first synchronization component of the first cluster.
In this manner, the service information of the second cluster may be synchronized in real-time to the first registry of the first cluster by the first synchronization component and the second proxy component.
In the following, in combination with an actual application scenario, service synchronization and stepping in the cross-cluster service calling method provided by the embodiment of the present application are further described in detail. Referring to fig. 3, the service synchronization in the cross-cluster service invocation method provided in the embodiment of the present application may specifically include the following steps:
step 310, the second agent component obtains the service information of the second cluster from a second registry of the second cluster;
the second registry may be a database in the second cluster, and the second registry may store service information of the second cluster in advance, where the service information may include an address of a target gateway of the second cluster and an identifier of a server in the second cluster.
It is to be understood that the second registry and the first registry may be two different databases.
Step 320, the first synchronization component sending a first synchronization request to a second proxy component;
it is to be appreciated that the first synchronization component can establish a synchronization flow with the second proxy component to synchronize service information of the second cluster in an instance in which the second proxy component grants the first synchronization request. The synchronous stream (stream) can continuously push data, and is suitable for transmitting some large data or for long-time data interaction such as a server and a client. For example, a client may subscribe to a server for data, and the server may continuously push data to the client using a synchronous stream.
Step 330, the second agent sends first synchronization information to the first synchronization component according to the first synchronization request, wherein the first synchronization information includes service information of the second cluster;
in an embodiment of the application, the second proxy component may send the first synchronization information to the first synchronization component via the synchronization stream.
Step 340, the first synchronization component receives the first synchronization information sent by the second agent component, and sends the first synchronization information to the first registry.
It is to be understood that the sending of the first synchronization information by the first synchronization component to the first registry may correspond to storing the service information of the second cluster in the local database of the first cluster in advance, so that the first server may call the service of the second cluster as a local service subsequently.
According to the cross-cluster service calling method provided by the embodiment of the application, the service information of the second cluster can be synchronized to the first registration center of the first cluster in real time through the first synchronization component and the second proxy component, so that the follow-up first service end can call the service end of the second cluster as the service end of the first cluster is called.
Optionally, in an embodiment of the present application, the first registry further stores service information of the first cluster; the method for calling the cross-cluster service provided by the embodiment of the application can further comprise the following steps: the second synchronization component (pilot component) sends a second synchronization request to the first agent component (agent component); and the first proxy component sends second synchronization information to the second synchronization component according to the second synchronization request, wherein the second synchronization information comprises service information of the first cluster.
Wherein the second synchronization component can be located in the second cluster and the first proxy component can be located in the first cluster. The second synchronization component may be configured to synchronize service information of the first cluster to the second registry of the second cluster; the first proxy component may be configured to be responsible for collecting service information of the first cluster and provide service synchronization convenience for the second synchronization component of the second cluster.
In this way, the service information of the first cluster can be synchronized in real time to the second registry of the second cluster by the second synchronization component and the first proxy component.
In the following, in combination with an actual application scenario, service synchronization and stepping in the cross-cluster service calling method provided by the embodiment of the present application are further described in detail. Referring to fig. 4, the service synchronization in the cross-cluster service invocation method provided in the embodiment of the present application may further specifically include the following steps:
step 410, the first agent component obtains service information of the first cluster from a first registry of the first cluster;
the first registry may further store service information of the first cluster in advance, where the service information may include an address of a target gateway of the first cluster and an identifier of a server in the first cluster.
Step 420, the second synchronization component sends a second synchronization request to the first proxy component;
it is to be appreciated that the second synchronization component can establish a synchronization flow with the first proxy component to synchronize the service information of the first cluster in an instance in which the first proxy component grants the second synchronization request.
Step 430, the first proxy component sends second synchronization information to the second synchronization component according to the second synchronization request, where the second synchronization information includes service information of the first cluster;
in an embodiment of the application, the first proxy component may send the second synchronization information to the second synchronization component through the synchronization stream.
Step 440, the second synchronization component receives the second synchronization information sent by the first agent component, and sends the second synchronization information to the second registry.
According to the method for cross-cluster service calling, the service information of the first cluster can be synchronized to the second registration center of the second cluster in real time through the second synchronization component and the first proxy component, and therefore the purpose that a target server side of the second cluster subsequently calls the service of the first cluster like calling the local service of the second cluster is achieved.
Fig. 5 is a block diagram illustrating a structure of a cross-cluster service call system according to an embodiment of the present disclosure, and fig. 6 is a schematic diagram illustrating a structure of a cross-cluster service call system according to an embodiment of the present disclosure.
Referring to fig. 5, a cross-clusterservice invocation system 500 provided in an embodiment of the present application may include: afirst server 510 and atarget gateway 520.
Thefirst server 510 is configured to obtain an address of atarget gateway 520 from a first registry; sending a service calling request to thetarget gateway 520 according to the target gateway address; receiving a service calling result returned by thetarget gateway 520 according to the service calling request; thefirst server 520 and the first registry are located in a first cluster, thetarget gateway 520 is located in a second cluster, the first registry stores service information of the second cluster in advance, and the service information includes an address of thetarget gateway 520.
According to the system for cross-cluster service calling, a first service end obtains an address of a target gateway from a first registration center; the first server side sends a service calling request to the target gateway according to the target gateway address; the first service end receives a service calling result returned by the target gateway according to the service calling request; the first server and the first registration center are located in a first cluster, the target gateway is located in a second cluster, the first registration center stores service information of the second cluster in advance, and the service information comprises an address of the target gateway. Therefore, the problem that communication between micro-services in the prior art cannot be carried out across clusters is solved by storing the service information of the second cluster in the first registration center of the first cluster in advance, then the first server of the first cluster acquires the target gateway address of the second cluster from the first registration center, then sends the service calling request to the target gateway, and receives the service calling result aiming at the service calling request, so that the services of other clusters are called as local services.
Optionally, in an embodiment, as shown in fig. 6, the cross-clusterservice invocation system 500 provided in the embodiment of the present application may further include: atarget server 530; the service information may further include an identification of a server in the second cluster; thefirst server 510 may further be configured to: acquiring the identifier of thetarget server 530 from the first registry; correspondingly, the service invocation request sent to thetarget gateway 520 may carry an identifier of thetarget server 530; thetarget gateway 520 may be configured to send the service invocation request to thetarget server 530 according to the identifier of thetarget server 530; thetarget server 530 may be configured to obtain a service invocation result according to the service invocation request, and return the service invocation result to thetarget gateway 520; thetarget gateway 520 may also be configured to: after receiving the service calling result, the service calling result is sent to thefirst service end 510.
Optionally, in an embodiment, as shown in fig. 6, the cross-clusterservice invocation system 500 provided in the embodiment of the present application may further include: afirst synchronization component 540 and asecond proxy component 550; thefirst synchronization component 540, which may be configured to send a first synchronization request to thesecond proxy component 550; thesecond proxy component 550 may be configured to send first synchronization information to thefirst synchronization component 540 according to the first synchronization request, where the first synchronization information may include service information of the second cluster; thefirst synchronization component 540 may also be configured to: receiving the first synchronization information sent by thesecond agent 550 and sending the first synchronization information to the first registry; wherein thefirst synchronization component 540 can be located in the first cluster and thesecond proxy component 550 can be located in the second cluster.
Optionally, in one embodiment, thesecond proxy component 550 may also be configured to: acquiring service information of the second cluster from a second registration center of the second cluster; the second registry may store the service information of the second cluster in advance.
Optionally, in an embodiment, the first registry may further store service information of the first cluster; as shown in fig. 6, the cross-clusterservice invocation system 500 provided in the embodiment of the present application may further include: asecond synchronization component 560 and afirst proxy component 570; thesecond synchronization component 560 may be configured to send a second synchronization request to thefirst proxy component 570; thefirst proxy component 570 may be configured to send second synchronization information to thesecond synchronization component 560 according to the second synchronization request, where the second synchronization information may include service information of the first cluster; wherein thesecond synchronization component 560 can be located in the second cluster and thefirst agent component 570 can be located in the first cluster.
It should be noted that the system for cross-cluster service invocation provided by the embodiment of the present application corresponds to the above-mentioned method for cross-cluster service invocation. The related content may refer to the above description of the method for cross-cluster service invocation, and is not described herein again.
In addition, an embodiment of the present application further provides a server, where the server includes: memory, a processor and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the method as claimed in any one of the preceding claims. For example, the computer program when executed by the processor implements the process of: the first service end obtains the address of the target gateway from the first registration center; the first server side sends a service calling request to the target gateway according to the target gateway address; the first service end receives a service calling result returned by the target gateway according to the service calling request; the first server and the first registration center are located in a first cluster, the target gateway is located in a second cluster, the first registration center stores service information of the second cluster in advance, and the service information comprises an address of the target gateway. Therefore, the problem that communication between micro-services in the prior art cannot be carried out across clusters is solved by storing the service information of the second cluster in the first registration center of the first cluster in advance, then the first server of the first cluster acquires the target gateway address of the second cluster from the first registration center, then sends the service calling request to the target gateway, and receives the service calling result aiming at the service calling request, so that the services of other clusters are called as local services.
Embodiments of the present application also provide a computer-readable storage medium, on which a computer program is stored, which, when executed by the processor, implements the steps of the method as described in any one of the above. For example, the computer program when executed by the processor implements the process of: the first service end obtains the address of the target gateway from the first registration center; the first server side sends a service calling request to the target gateway according to the target gateway address; the first service end receives a service calling result returned by the target gateway according to the service calling request; the first server and the first registration center are located in a first cluster, the target gateway is located in a second cluster, the first registration center stores service information of the second cluster in advance, and the service information comprises an address of the target gateway. Therefore, the problem that communication between micro-services in the prior art cannot be carried out across clusters is solved by storing the service information of the second cluster in the first registration center of the first cluster in advance, then the first server of the first cluster acquires the target gateway address of the second cluster from the first registration center, then sends the service calling request to the target gateway, and receives the service calling result aiming at the service calling request, so that the services of other clusters are called as local services.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.