Service publishing method, calling method and system based on multiple registration centers
By annotating the service method in the microservice framework, and using interceptors and configuration files to dynamically read the registration center address, the flexible release of services between multiple registration centers is realized, which solves the problem that in the existing technology, services can only be released to a single registration center, improving the maintainability of the system.
Patent Information
- Application Number
- CN202411493055.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-01-21
AI Technical Summary
The existing microservice framework usually only supports publishing services to one registry center, which cannot meet the publishing needs of multiple registry centers, and different services cannot be published to different registry centers, resulting in poor system maintenance.
By annotating the method of the service to be published on the service publishing side, the annotation information is obtained and intercepted and parsed using the preset interceptor, the registration center address in the configuration file is dynamically read, a link is established and the service is published to multiple registration centers.
The flexible release of services between multiple registered centers has been achieved, the maintenance of the service registration and calling process has been improved, and the accurate identification and calling of the service in different registered centers is ensured.
Smart Images

Figure CN119342106A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of microservice technology, and in particular to a service publishing method, calling method and system based on multiple registration centers. Background Art
[0002] In the process of microservice governance, the service-side system needs to publish the services it provides to the service registry so that the caller system can discover and call them. Currently, the service registration mechanism usually supports publishing services to a specific registry or a certain type of registry. With the expansion of banking systems and the continuous increase in the demand for docking with external systems, there are two problems: (1) The current microservice framework usually only supports publishing services to one registry and cannot meet the publishing requirements of multiple registry centers; (2) Different services cannot be published to different registries.
[0003] In the prior art, bank information systems usually only support connecting to one registration center or the services of a certain type of registration center, and cannot flexibly select different registration centers for addressing according to different service requirements. When the bank connects with multiple external systems or designs a multi-registration center architecture according to business needs, the information system has poor maintainability. Summary of the invention
[0004] In view of this, the present invention provides a service publishing method, calling method and system based on multiple registration centers to solve the problem of how to improve the maintainability in the service publishing / calling process.
[0005] In a first aspect, the present invention provides a service publishing method based on multiple registration centers, which is applied to a service publishing end, and the method includes:
[0006] Annotate the methods included in each type of service to be published to obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center;
[0007] Based on the first preset interceptor, the annotation information corresponding to each method is intercepted; at the same time, the package corresponding to the service to be published is parsed and the identification information corresponding to each method is generated;
[0008] Reading addresses of registration centers respectively corresponding to the names of at least one registration center from a preset configuration file according to the name of at least one registration center in the annotation information;
[0009] A link with the registration center is established according to the address of the registration center. When the link is successfully established, each method included in the service to be published is published to the corresponding one or more registration centers using the identification information corresponding to each method, so that the service calling end obtains the service request information sent by the user and obtains the requested method corresponding to the service request information sent by the user from the services already registered in the registration center.
[0010] The embodiment of the present invention annotates each method in the service to be published, and the annotation includes the name of the registration center, so that each method can flexibly specify multiple registration centers. It solves the problem that the prior art can only publish to a single registration center, uses a first preset interceptor to intercept the annotation information of each method, centrally processes the logic of service publishing, improves the maintainability of the registration service, parses the package of the service to be published, and generates identification information corresponding to each method, so that the identification of the service in the registration center is more accurate, and also facilitates the subsequent process of calling the service. According to the annotation information, the corresponding registration center address in the configuration file is read, a link is established according to the registration center address, and each method is published to the corresponding one or more registration centers. Once the link is successfully established, the service can be published to multiple registration centers at the same time, which solves the problem that different services cannot be published to different registration centers in the prior art.
[0011] In an optional implementation, the identification information corresponding to each method includes the name of the service package to which the method belongs, the name of the class to which the method belongs, and the method name.
[0012] The embodiment of the present invention uses the service package name, class name and method name to which the method belongs as identification information, which can ensure that each method has a unique and clear identification in the registration center and accurately locate a specific method. In the scenario of multiple registration centers, different services may be published to different registration centers. Clear identification information can ensure that the service method can still be accurately called even in multiple registration centers.
[0013] In an optional implementation, the step of establishing a link with a registration center according to the address of the registration center, and when the link is successfully established, publishing each method included in the service to be published to one or more corresponding registration centers using the identification information corresponding to each method, specifically includes:
[0014] Encapsulate each method, identification information, and registration center name included in the service to be published into a service instance, wherein one service instance corresponds to one method;
[0015] Obtain the corresponding registry center component according to the registry center name in the service instance;
[0016] The service instance is registered with one or more corresponding registration centers using the registration center component.
[0017] The embodiment of the present invention encapsulates each method and its related information as a service instance, which is equivalent to modular registration. Each service instance contains the name of the registration center. By obtaining the registration center component and using it to register the service instance, if the subsequent system maintenance needs to modify or replace the registration center of a service, it is only necessary to adjust the corresponding service instance without reconstructing the entire service publishing process. Therefore, it can effectively improve the maintainability of service registration and publishing.
[0018] In a second aspect, the present invention provides a service calling method based on multiple registration centers, which is applied to a service calling end, and the method includes:
[0019] Obtain the service request information sent by the user and parse it to obtain the request instance;
[0020] Intercepting the identification information to be requested and at least one registration center name in the request instance based on a second preset interceptor;
[0021] Reading, according to the at least one registration center name, from a preset configuration file an address of a registration center corresponding to the name of at least one registration center;
[0022] Determining whether a link has been established with the registration center according to the address of the registration center;
[0023] If a link has been established, the corresponding method to be requested is obtained from the services registered in the registration center according to the identification information to be requested; wherein the registration center pre-registers the services published by the method described in the first aspect or any one of its embodiments.
[0024] In the embodiment of the present invention, a user sends service request information and parses it to obtain a request instance. By parsing the request instance, the user's specific needs can be flexibly identified. Based on the second preset interceptor, the identification information to be requested and at least one registration center name in the request instance are intercepted, and the address of the registration center corresponding to the name of at least one registration center is read from the preset configuration file. The registration center address can be read dynamically, and by checking the connection status, repeated connection requests can be avoided, resource consumption can be reduced, and the efficiency of service calls can be improved. When a registration center fails, services can still be continued to be provided through other registration centers corresponding to the method, thereby improving the maintainability of service calls.
[0025] In an optional implementation, if the link has been established, obtaining the corresponding method to be requested from the service registered in the registration center according to the identification information to be requested specifically includes:
[0026] Determine at least one corresponding registration center according to the identification information;
[0027] and acquiring all corresponding methods to be requested from the at least one registration center according to the identification information;
[0028] According to the preset service selection strategy, all the methods to be requested are traversed, and the method that meets the preset performance requirement indicators is selected as the target method to be requested.
[0029] The embodiment of the present invention determines at least one corresponding registration center according to the identification information to be requested, flexibly selects a service provider, obtains all possible service methods from multiple registration centers, traverses all the methods to be requested according to the preset service selection strategy, and selects the method that meets the preset performance requirement indicators. The performance-based selection mechanism can ensure that the selected service method meets specific business requirements in terms of response time and load capacity, thereby effectively improving the maintainability of service calls.
[0030] In an optional implementation, the method further includes: establishing an identification information-registration center address mapping table using the received identification information and the registration center address in the form of a key-value pair, and saving the mapping table as cache information;
[0031] The determining whether a link has been established with the registration center according to the address of the registration center specifically includes:
[0032] Acquire an identification information-registration center address mapping table from the cache information;
[0033] Search the identification information-registration center address mapping table according to the address of the current registration center; if the corresponding identification information does not exist for the address of the current registration center, confirm that no link has been established with the registration center, and update the identification information-registration center address mapping table with the address of the current registration center and the corresponding identification information to be requested as a new mapping relationship; store the updated identification information-registration center address mapping table in the cache information;
[0034] If the address of the current registration center has corresponding identification information and is the same as the identification information to be requested, it is confirmed that a link has been established with the registration center.
[0035] The embodiment of the present invention establishes a mapping relationship between the received identification information and the registration center address, dynamically manages the addresses of multiple registration centers, quickly searches for the corresponding registration center address, avoids the need to read from the configuration file each time, and improves the response speed. If the corresponding address and identification information exist in the mapping table, the existing connection can be directly used to avoid repeated connection requests, reduce the consumption of network resources, and improve the efficiency of service calls.
[0036] In a third aspect, the present invention provides a service publishing and calling system based on multiple registration centers, the system comprising: a service publishing end, a service calling end, and at least one registration center;
[0037] The service publishing end is used to annotate the methods included in each type of service to be published, and obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center; intercept the annotation information corresponding to each method based on the first preset interceptor; at the same time, parse the package corresponding to the service to be published and generate identification information corresponding to each method; read the address of the registration center corresponding to the name of at least one registration center from the preset configuration file according to the name of at least one registration center in the annotation information; establish a link with the registration center according to the address of the registration center, and when the link is successfully established, use the identification information corresponding to each method to publish each method included in the service to be published to the corresponding one or more registration centers;
[0038] The registration center is used for registration or forwarding services;
[0039] The service calling end is used to obtain the service request information sent by the user and parse it to obtain the request instance;
[0040] Based on the second preset interceptor, the identification information to be requested and at least one registration center name in the request instance are intercepted; according to the at least one registration center name, the addresses of the registration centers corresponding to the names of at least one registration center are read from the preset configuration file; according to the address of the registration center, it is determined whether a link has been established with the registration center; if the link has been established, the corresponding method to be requested is obtained from the services registered by the registration center according to the identification information to be requested.
[0041] In a fourth aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the service publishing method based on multiple registration centers of the first aspect or any corresponding embodiment thereof, and the service calling method based on multiple registration centers of the second aspect or any corresponding embodiment thereof by executing the computer instructions.
[0042] In a fifth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the service publishing method based on multiple registration centers of the first aspect or any corresponding embodiment thereof, or the service calling method based on multiple registration centers of the second aspect or any corresponding embodiment thereof.
[0043] In a sixth aspect, the present invention provides a computer program product, comprising computer instructions, the computer instructions being used to enable a computer to execute the service publishing method based on multiple registration centers of the first aspect or any corresponding embodiment thereof, and the service calling method based on multiple registration centers of the second aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 is a flow chart of a service publishing method based on multiple registration centers according to an embodiment of the present invention;
[0046] Figure 2 is a flow chart of another service publishing method based on multiple registration centers according to an embodiment of the present invention;
[0047] Figure 3 is a flow chart of a service calling method based on multiple registration centers according to an embodiment of the present invention;
[0048] Figure 4 is a flow chart of another service calling method based on multiple registration centers according to an embodiment of the present invention;
[0049] Figure 5 is a structural block diagram of a service publishing and calling system based on multiple registration centers according to an embodiment of the present invention;
[0050] Figure 6 This is an interactive schematic diagram of a service publishing and calling system based on multiple registration centers according to an embodiment of the present invention;
[0051] Figure 7 is a service publishing flow chart of a service publishing and calling system based on multiple registration centers according to an embodiment of the present invention;
[0052] Figure 8 is a service calling flow chart of a service publishing and calling system based on multiple registration centers according to an embodiment of the present invention;
[0053] Fig. 9 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0055] Traditional microservice frameworks usually adopt a single registration center model, which performs well in a single technology stack or small-scale deployment. In a complex IT ecosystem like a bank, especially in complex scenarios such as large-scale deployment, cross-platform integration, and coexistence of multiple protocols, the adaptability of a single registration center is insufficient and the maintainability is poor.
[0056] For example, in the single registry mode, services can only be registered in one registry. If services need to be shared between multiple registries, developers must manually register them in each system separately, which increases management complexity and poses operational risks if registration information is inconsistent.
[0057] In addition, cross-registry calls require additional adaptation and development, which increases the complexity of the system. In the existing multi-registry environment, forcing all systems to migrate to a unified registry requires large-scale transformation of existing systems, reconfiguration and testing of various dependent services, and may even bring higher business risks, which will consume a lot of time and cost.
[0058] This embodiment provides a service publishing method and calling method based on multiple registration centers, which are applied to information interaction scenarios with high security requirements and large scale, such as banks, especially information systems using microservice architecture. By adopting a multi-registration center architecture and building a unified service publishing and calling mechanism, information intercommunication across registration centers is achieved, thereby improving the maintainability of service publishing and calling.
[0059] According to an embodiment of the present invention, an embodiment of a service publishing method based on multiple registration centers is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0060] In this embodiment, a service publishing method based on multiple registration centers is provided, which is applied to a service publishing end. Figure 1 is a flow chart of a service publishing method based on multiple registration centers according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0061] Step S101 , annotating methods included in each type of service to be published to obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center.
[0062] It should be noted that in Java, annotation is a mechanism for embedding metadata in code to identify specific behaviors of classes, methods, variables, etc. Annotation information can include configuration content of metadata such as the name of the registry center.
[0063] Specifically, use the custom annotation @Publisher to annotate the service method. The annotation can be configured with the names of multiple registries to define the location where the service needs to be published.
[0064] For example, an annotation is defined for service registration. This annotation configuration allows developers to arbitrarily specify which registry centers the service is published to at the code level. The code example is as follows:
[0065] @Documented
[0066] @Target(ElementType.TYPE,ElementType.METHOD )
[0068] @Retention(RetentionPolicy.RUNTIME)
[0069] public@interface Publisher{
[0070] String[]registername()default;
[0071] }
[0072] The @Publisher annotation is defined to implement service publishing. The parameter allows multiple registry names to be specified at the same time. It is understandable that through this configuration form, services can be expanded and published to multiple registry centers, and the registry center types can also be freely expanded. By binding the name of the registry center to the method, developers can clearly specify the publishing location of the service when writing code.
[0073] Step S102, intercepting the annotation information corresponding to each method based on the first preset interceptor; at the same time, parsing the package corresponding to the service to be published and generating identification information corresponding to each method.
[0074] It should be noted that the first preset interceptor refers to a component that intercepts a node of code execution, and in this embodiment is a preset interception logic independent of the execution code itself, used to intercept annotation information. The identification information is a string used to uniquely identify each service instance.
[0075] Specifically, according to the preset interceptor, the package path is scanned and all classes and methods with @Publisher annotations are parsed. For each annotated method, corresponding unique identification information is generated, such as: xx.xxx.ServiceA.classA.methodA. This can effectively ensure that service instances can be uniquely identified in multiple registries. The use of the first preset interceptor avoids developers from manually processing annotation logic and improves the degree of automation. The generation of identification information ensures that service calls in different registries are not confused, making the calls more accurate.
[0076] Step S103: Reading addresses of registration centers corresponding to the name of at least one registration center from a preset configuration file according to the name of at least one registration center in the annotation information.
[0077] It should be noted that the configuration file is a file that stores relevant configuration parameters, such as the address of the registration center, etc. The registration center is a component used to manage service registration, publishing and calling, including Zookeeper, Eureka, nacos, etc.
[0078] Specifically, according to the registry name in the annotation, the corresponding address information is read from the system configuration file. The configuration file pre-stores the IP address, port and other information of the registry. Separating the registry information from the code logic actually facilitates maintenance and expansion. If the registry address changes, you only need to update the configuration file without modifying the code. Another purpose is to enable the interceptor to query and match the corresponding registry for service release in subsequent steps.
[0079] Step S104: Establish a link with the registration center according to the address of the registration center. When the link is successfully established, use the identification information corresponding to each method to publish each method included in the service to be published to the corresponding one or more registration centers, so that the service caller can obtain the service request information sent by the user and obtain the method to be requested corresponding to the service request information sent by the user from the services registered in the registration center.
[0080] It should be noted that the link refers to the communication channel between the server and the registry. Service publishing registers the metadata of the service instance to the registry so that other services can discover and call it.
[0081] It is worth noting that the conventional registration mode registers at the system granularity, while the multi-registration center service publishing mechanism in the embodiment of the present invention supports registration at the service granularity level. Registration at the service granularity means that the service is not limited to the entire system or module level, but is refined to the specific method level. For example, a method methodA in service A can be regarded as an independent service for registration. This makes the service publishing and registration more maintainable, because when the method is updated, only the code modification needs to be made at the method level. Accordingly, registration and publishing only need to be performed at the method level, and there is no need to republish the entire service to which the method belongs.
[0082] The embodiment of the present invention annotates each method in the service to be published, and the annotation includes the name of the registration center, so that each method can flexibly specify multiple registration centers. It solves the problem that the prior art can only publish to a single registration center, uses a first preset interceptor to intercept the annotation information of each method, centrally processes the logic of service publishing, improves the maintainability of the registration service, parses the package of the service to be published, and generates identification information corresponding to each method, so that the identification of the service in the registration center is more accurate, and also facilitates the subsequent process of calling the service. According to the annotation information, the corresponding registration center address in the configuration file is read, a link is established according to the registration center address, and each method is published to the corresponding one or more registration centers. Once the link is successfully established, the service can be published to multiple registration centers at the same time, which solves the problem that different services cannot be published to different registration centers in the prior art, and further improves the maintainability of service publishing and calling in the information system.
[0083] In this embodiment, a service publishing method based on multiple registration centers is provided, which is applied to a service publishing end. Figure 2 is a flow chart of a service publishing method based on multiple registration centers according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0084] Step S201: Annotate the methods included in each type of service to be published to obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0085] Step S202: intercepting the annotation information corresponding to each method based on the first preset interceptor; at the same time, parsing the package corresponding to the service to be published and generating identification information corresponding to each method.
[0086] In an optional implementation, the identification information corresponding to each method includes the name of the service package to which the method belongs, the name of the class to which the method belongs, and the method name.
[0087] The embodiment of the present invention uses the service package name, class name and method name to which the method belongs as identification information, which can ensure that each method has a unique and clear identification in the registration center and accurately locate a specific method. In the scenario of multiple registration centers, different services may be published to different registration centers. Clear identification information can ensure that the service method can still be accurately called even in multiple registration centers.
[0088] Step S203: Read the address of the registration center corresponding to the name of at least one registration center from the preset configuration file according to the name of at least one registration center in the annotation information. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0089] Step S204, establish a link with the registration center according to the address of the registration center. When the link is successfully established, use the identification information corresponding to each method to publish each method included in the service to be published to the corresponding one or more registration centers, so that the service caller can obtain the service request information sent by the user and obtain the requested method corresponding to the service request information sent by the user from the services already registered in the registration center.
[0090] Specifically, the above step S204 includes:
[0091] Step S2041, encapsulate each method, identification information, and registration center name included in the service to be published into a service instance, wherein one service instance corresponds to one method.
[0092] It should be noted that each service instance contains all the registration information corresponding to the method, including the service method name, class name, package name, registration center, etc., forming a complete definition of the service.
[0093] Specifically, scan the annotated classes and methods in the service, extract and encapsulate the service-related information in the annotation (such as service methods, identification information, registration center name, etc.). Using the Java reflection mechanism, dynamically obtain service methods and classes with @Publisher annotations, and encapsulate them into a service instance. The encapsulated service instance will include all information related to service publishing, such as package name, class name, method name, etc. Each service instance represents an independent service unit (corresponding to method-level service), which can be published to one or more registration centers to achieve more flexible service registration.
[0094] Step S2042: Obtain the corresponding registry center component according to the registry center name in the service instance.
[0095] Specifically, the registration center component is a specific module used to interact with the registration center, including at least service registration and service forwarding functions. Each registration center component is responsible for communicating with its corresponding registration center.
[0096] Step S2043: using the registration center component, register the service instance to one or more corresponding registration centers.
[0097] Specifically, according to the name of the registry in the encapsulated service instance, the preset registry configuration file is searched to determine the type of registry to which the service needs to be published; according to the type of the registry, the corresponding registry component is loaded; after obtaining the registry component, the service instance information is passed to the corresponding component. The registry component registers the service instance information with the registry. Among them, the registry maintains a service directory, which records the unique identification information of the service method (package name + class name + method name) and the server address where the service is located. By registering the service instance with the registry, other services can call these registered services through the service discovery mechanism. If a problem occurs in a registry, the service caller can continue to discover and call services from other registry centers to improve system stability.
[0098] The embodiment of the present invention encapsulates each method and its related information as a service instance, which is equivalent to modular registration. Each service instance contains the name of the registration center. By obtaining the registration center component and using it to register the service instance, if the subsequent system maintenance needs to modify or replace the registration center of a service, it is only necessary to adjust the corresponding service instance without reconstructing the entire service publishing process. Therefore, it can effectively improve the maintainability of service registration and publishing.
[0099] In this embodiment, a service calling method based on multiple registration centers is provided, which is applied to the service calling end. Figure 3 is a flow chart of a service calling method based on multiple registration centers according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0100] Step S301: obtain the service request information sent by the user and parse it to obtain a request instance.
[0101] It should be noted that the service request information refers to the call request initiated by the client user, which contains specific service name, parameters, target address and other information. The purpose of parsing the request instance is to convert the service request information content into a searchable object form to facilitate subsequent service search processing.
[0102] Step S302: intercepting the identification information to be requested and at least one registration center name in the request instance based on a second preset interceptor.
[0103] It should be noted that the second preset interceptor is an interception component corresponding to the first preset interceptor, which is used to intercept request responses and is also other interception operations performed independently of the main execution logic code. The purpose in this embodiment is to parse the registration center and identification of the target service before the main process, so that the accurate registration center address can be determined in the subsequent steps.
[0104] Step S303: Reading addresses of registration centers corresponding to the name of at least one registration center from a preset configuration file according to the at least one registration center name.
[0105] It should be noted that the address of the registration center refers to the network address of the specific registration center server, such as http: / / eureka-server:8761. It indicates the address of the registration center of the eureka type.
[0106] Specifically, the configuration data can be read through the configuration reading tool. The configuration data can be stored in the form of key-value pairs, and the address in the configuration file can be dynamically read. It can flexibly adapt to different registry center instances in multi-registry center scenarios. There is no need to redeploy the registry center service when the configuration is updated. The calling end can be completely independent of the server and perform updates and maintenance related to service calls separately.
[0107] Step S304: determine whether a link with the registration center has been established based on the address of the registration center.
[0108] Specifically, a connection pool technology may be used to manage the link with the registration center, or a mapping relationship between a service identifier and a connection with the registration center may be maintained through a cache.
[0109] Step S305, if the link has been established, then obtaining the corresponding method to be requested from the services registered in the registration center according to the identification information to be requested; wherein the registration center pre-registers the services published by the above-mentioned service publishing method based on multiple registration centers.
[0110] Specifically, the service method and its corresponding instance that need to be called are queried from the registration center, and the service instance corresponding to the request identification information is queried through the API call of the registration center. The method information of the service instance is returned, and the subsequent service call can be made. The registration center and the identification of the target service in the request information are intercepted by the second interceptor to ensure that the correct service instance can be called.
[0111] In the embodiment of the present invention, a user sends service request information and parses it to obtain a request instance. By parsing the request instance, the user's specific needs can be flexibly identified. Based on the second preset interceptor, the identification information to be requested and at least one registration center name in the request instance are intercepted, and the address of the registration center corresponding to the name of at least one registration center is read from the preset configuration file. The registration center address can be read dynamically, and by checking the connection status, repeated connection requests can be avoided, resource consumption can be reduced, and the efficiency of service calls can be improved. When a registration center fails, services can still be continued to be provided through other registration centers corresponding to the method, thereby improving the maintainability of service calls.
[0112] This embodiment provides a service calling method based on multiple registration centers, which is applied to the service calling end. Figure 4 is a flow chart of a service publishing method based on multiple registration centers according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:
[0113] Step S401: Obtain the service request information sent by the user and parse it to obtain the request instance. Figure 3 Step S301 of the illustrated embodiment will not be described in detail here.
[0114] Step S402: intercept the identification information to be requested and at least one registration center name in the request instance based on the second preset interceptor. Figure 3 Step S302 of the illustrated embodiment will not be described in detail here.
[0115] Step S403: Read the address of the registration center corresponding to the name of at least one registration center from the preset configuration file according to the at least one registration center name. Figure 3 Step S303 of the illustrated embodiment will not be described in detail here.
[0116] Step S404: Create an identification information-registration center address mapping table using the received identification information and registration center address in the form of key-value pairs, and save it as cache information.
[0117] Specifically, when the component is initialized, a cache mechanism is established to store the mapping relationship between the service identification information and the registration center address in the memory.
[0118] Step S405: judging whether a link with the registration center has been established according to the address of the registration center.
[0119] The above step S405 specifically includes:
[0120] Step S4051, obtaining an identification information-registration center address mapping table from the cache information.
[0121] Specifically, the component obtains the correspondence between the stored identification information and the registration center address by searching the mapping table in the cache. Through the cache mechanism, it can avoid reading the registration center address from the configuration file every time the service is called, thereby improving the response speed. In addition, it also reduces the frequent access to the configuration file.
[0122] Step S4052, search the identification information-registration center address mapping table according to the address of the current registration center. If there is no corresponding identification information for the address of the current registration center, confirm that no link has been established with the registration center, and update the address of the current registration center and the corresponding identification information to be requested as a new mapping relationship to the identification information-registration center address mapping table; store the updated identification information-registration center address mapping table in the cache information.
[0123] Specifically, the address of the registration center currently requested is compared with the mapping table in the cache. If there is no corresponding service identification information in the mapping table, it is considered that no connection has been established with the registration center. At this time, the address of the current registration center and the identification information to be requested are added to the mapping table as a new mapping relationship, and the cache information is updated.
[0124] Step S4053: If the address of the current registration center has corresponding identification information and is the same as the identification information to be requested, it is confirmed that a link has been established with the registration center.
[0125] Specifically, if the corresponding identification information of the current registration center address exists in the mapping table, and the identification information is the same as the identification information to be requested, it is confirmed that a connection has been established with the registration center. At this time, the component can directly use the existing connection to call the service. By confirming the existence of the connection, the connection is effectively reused, and the delay in establishing the connection is also reduced. By updating the mapping table in real time, the corresponding registration center address can be quickly found to avoid repeated connection requests.
[0126] The embodiment of the present invention establishes a mapping relationship between the received identification information and the registration center address, dynamically manages the addresses of multiple registration centers, quickly searches for the corresponding registration center address, avoids the need to read from the configuration file each time, and improves the response speed. If the corresponding address and identification information exist in the mapping table, the existing connection can be directly used to avoid repeated connection requests, reduce the consumption of network resources, and improve the efficiency of service calls.
[0127] Step S406, if the link has been established, then obtaining the corresponding method to be requested from the services registered in the registration center according to the identification information to be requested; wherein the registration center pre-registers the services published by the above-mentioned service publishing method based on multiple registration centers.
[0128] Specifically, the above step S406 includes:
[0129] Step S4061: determine at least one corresponding registration center according to the identification information.
[0130] Specifically, the corresponding identification information-registration center address mapping table is first read from the cache. If the registration center address associated with the identification information exists in the cache, the target registration center can be directly located. If the relevant information does not exist in the cache, the mapping relationship between the new address and the identification information is updated in the cache.
[0131] Step S4062, and obtain all corresponding methods to be requested from the at least one registration center according to the identification information.
[0132] Specifically, requests are sent to multiple registration centers to obtain all service methods corresponding to the service identification information, including indicators of different versions, different load capacities or different resource requirements. Through the components of the registration center, all registered service instances are traversed and related call checks are performed to ensure service availability.
[0133] Step S4063, traverse all the methods to be requested according to the preset service selection strategy, and select a method that meets the preset performance requirement index as the target method to be requested.
[0134] Specifically, traversal and screening are performed based on performance requirement indicators (such as response time, load capacity, protocol format, technology stack, etc.). The preset selection strategy may include giving priority to instances with lower loads, or selecting instances with optimal response time, or selecting instances with the same technology stack and protocol format.
[0135] In an optional implementation, the selection strategy is dynamically adjusted according to the real-time network resource occupancy information, for example, load information corresponding to each method is balanced among multiple service methods based on the network resource occupancy information.
[0136] The embodiment of the present invention determines at least one corresponding registration center according to the identification information to be requested, flexibly selects a service provider, obtains all possible service methods from multiple registration centers, traverses all the methods to be requested according to the preset service selection strategy, and selects the method that meets the preset performance requirement indicators. The performance-based selection mechanism can ensure that the selected service method meets specific business requirements in terms of response time and load capacity, thereby effectively improving the maintainability of service calls.
[0137] In an optional implementation, a service calling method based on multiple registration centers provided by an embodiment of the present invention further includes: before calling the target service, performing a health check on the corresponding instance through the registration center component to verify the operating status of the target service instance, and when any information in the operating status does not meet the target indicator, the target service instance is confirmed to be in a fault state; or, a timeout period is set for the service or globally, and when the request is not responded to within the set time, the target service instance is confirmed to be in a fault state.
[0138] Further, when it is confirmed that the target service instance is in a fault state, the target service instance is replied to be in a normal state through an automatic retry mechanism, and the automatic retry mechanism includes a combination of at least one of the following operations:
[0139] A1, set a fixed upper limit on the number of retries, and the component will retry within the preset number of times;
[0140] A2 uses an exponential backoff strategy. The waiting time increases exponentially between each retry, which improves the retry success rate in network jitter scenarios.
[0141] A3, idempotency check: During the retry process, a unique identifier is used to ensure the idempotency of the transaction and avoid repeated execution of the business.
[0142] A4, fast failure: The component determines the load and failure type of the current service through the registration center instance, and chooses to skip retry and perform fast failure processing based on the actual situation.
[0143] In a multi-registry or multi-instance environment, if the component detects that the target service instance or registry is unavailable, the component will automatically switch to other healthy instances or backup registry through the registry instance to continue to complete the service call. By adding multiple fault handling and optimization strategies, the feasibility of service calls can be improved.
[0144] In this embodiment, a service publishing and calling system based on multiple registration centers is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the system described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0145] This embodiment provides a service publishing and calling system based on multiple registration centers, such as Figure 5 As shown, it includes: a service publishing end, a service calling end, and at least one registration center;
[0146] The service publishing end is used to annotate the methods included in each type of service to be published, and obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center; intercept the annotation information corresponding to each method based on the first preset interceptor; at the same time, parse the package corresponding to the service to be published and generate identification information corresponding to each method; read the address of the registration center corresponding to the name of at least one registration center from the preset configuration file according to the name of at least one registration center in the annotation information; establish a link with the registration center according to the address of the registration center, and when the link is successfully established, use the identification information corresponding to each method to publish each method included in the service to be published to the corresponding one or more registration centers;
[0147] The registration center is used for registration or forwarding services;
[0148] The service calling end is used to obtain the service request information sent by the user and parse it to obtain the request instance;
[0149] Based on the second preset interceptor, the identification information to be requested and at least one registration center name in the request instance are intercepted; according to the at least one registration center name, the addresses of the registration centers corresponding to the names of at least one registration center are read from the preset configuration file; according to the address of the registration center, it is determined whether a link has been established with the registration center; if the link has been established, the corresponding method to be requested is obtained from the services registered by the registration center according to the identification information to be requested.
[0150] The further functional description of the above system is the same as that of the above corresponding embodiment and will not be repeated here.
[0151] Furthermore, the contents of the above-mentioned embodiments of the invention have been implemented in a unified development framework. Currently, the function has been applied to multiple systems and has been verified in an online environment, demonstrating the integrity and feasibility of the present invention.
[0152] In practical applications, the overall interaction diagram of a service publishing and calling system based on multiple registration centers can be referred to Figure 6(1) The service publisher registers at the service granularity. Different services can be registered in different registries instead of registering all services in the same registry. A Java annotation is provided on the service method, allowing the developer to configure the name of the registry to which the method needs to be registered in the annotation. The annotation supports the configuration of multiple registries at the same time. Through the Java reflection mechanism, when the system starts, the interceptor will automatically intercept externally published services. Obtain the registry name corresponding to the service and generate a unique service identifier (in the format of package name + class name + method name). According to the registry name obtained by the interceptor, read the corresponding registry address from the configuration file. Establish connections with these registries and publish services to the specified registry. The same service or different services can be published to multiple different registries.
[0153] (2) When calling a specific service, the service caller can specify the name of the registry center to be called and the registration name of the service system. The interceptor will automatically obtain the service identifier (consistent with the format of the server: package name + class name + method name) and the registry center name called by the caller. The interceptor reads the corresponding registry center address from the configuration file based on the specified registry center name. Establish a connection with the registry center, and use the service identifier as the key and the connection session as the value to store it in the local cache. Before establishing a new connection, first check whether the corresponding connection already exists in the local cache. If it does, directly use the connection in the cache. If it does not exist, establish a new connection and update the cache. According to the registration name of the service provider, obtain the address information of the service provider from the registry center and initiate a request to the service provider.
[0154] The publishing process of the service publishing end can be referred to Figure 7 , including: registration scanning and parsing phase, i.e. publisher startup, package scanning and parsing, obtaining all services that need to be registered, service instance encapsulation phase, i.e. creating a unique service identifier and encapsulating it into a corresponding service instance; service instance registration phase, i.e. obtaining the corresponding registration instance service registration, until registration is completed.
[0155] The calling process of the service calling end can refer to Figure 8 , the application (user) sends a service request; the client instance resolves and obtains the corresponding instance and the corresponding registration instance. The registration center instance obtains the service instance address, cache session information, and service detection. The target service instance returns the service status and finally returns to the application after receiving the service request response.
[0156] The service publishing and calling system based on multiple registration centers in this embodiment is presented in the form of functional units, where the units refer to ASIC (Application Specific Integrated Circuit) circuits, processors and memories that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0157] The embodiment of the present invention also provides a computer device having the above Figure 5 The service publishing and calling system based on multiple registration centers is shown.
[0158] See also Fig. 9 , Fig. 9 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Fig. 9 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig. 9 A processor 10 is taken as an example.
[0159] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0160] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0161] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0162] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0163] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0164] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0165] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0166] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the defined scope.
Claims
1. A service publishing method based on multiple registration centers, characterized in that: Applied to the service publishing end, the method includes: Annotate the methods included in each type of service to be published to obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center; Based on the first preset interceptor, the annotation information corresponding to each method is intercepted; at the same time, the package corresponding to the service to be published is parsed and the identification information corresponding to each method is generated; Reading addresses of registration centers respectively corresponding to the names of at least one registration center from a preset configuration file according to the name of at least one registration center in the annotation information; A link with the registration center is established according to the address of the registration center. When the link is successfully established, each method included in the service to be published is published to the corresponding one or more registration centers using the identification information corresponding to each method, so that the service caller obtains the service request information sent by the user and obtains the requested method corresponding to the service request information sent by the user from the services already registered in the registration center.
2. The method according to claim 1, characterized in that The identification information corresponding to each method includes the name of the service package to which the method belongs, the name of the class to which the method belongs, and the method name.
3. The method according to claim 2, characterized in that The step of establishing a link with the registration center according to the address of the registration center, and when the link is successfully established, publishing each method included in the service to be published to the corresponding one or more registration centers using the identification information corresponding to each method, specifically includes: Encapsulate each method, identification information, and registration center name included in the service to be published into a service instance, wherein one service instance corresponds to one method; Obtain the corresponding registry center component according to the registry center name in the service instance; The service instance is registered with one or more corresponding registration centers using the registration center component.
4. A service calling method based on multiple registration centers, characterized in that: Applied to the service calling end, the method includes: Obtain the service request information sent by the user and parse it to obtain the request instance; Intercepting the identification information to be requested and at least one registration center name in the request instance based on a second preset interceptor; Reading, according to the at least one registration center name, from a preset configuration file an address of a registration center corresponding to the name of at least one registration center; Determining whether a link has been established with the registration center according to the address of the registration center; If the link has been established, the corresponding method to be requested is obtained from the services registered in the registration center according to the identification information to be requested; wherein the registration center pre-registers the service published by the method according to any one of claims 1-3.
5. The method according to claim 4, characterized in that If the link has been established, then obtaining the corresponding method to be requested from the service registered in the registration center according to the identification information to be requested, specifically including: Determine at least one corresponding registration center according to the identification information; and acquiring all corresponding methods to be requested from the at least one registration center according to the identification information; According to the preset service selection strategy, all the methods to be requested are traversed, and the method that meets the preset performance requirement indicators is selected as the target method to be requested.
6. The method according to claim 4, characterized in that The method further comprises: establishing an identification information-registration center address mapping table using the received identification information and registration center address in the form of key-value pairs, and saving the mapping table as cache information; The determining whether a link has been established with the registration center according to the address of the registration center specifically includes: Acquire an identification information-registration center address mapping table from the cache information; Search the identification information-registration center address mapping table according to the address of the current registration center; if the corresponding identification information does not exist for the address of the current registration center, confirm that no link has been established with the registration center, and update the identification information-registration center address mapping table with the address of the current registration center and the corresponding identification information to be requested as a new mapping relationship; store the updated identification information-registration center address mapping table in the cache information; If the address of the current registration center has corresponding identification information and is the same as the identification information to be requested, it is confirmed that a link has been established with the registration center.
7. A service publishing and calling system based on multiple registration centers, characterized in that: The system includes a service publishing end, a service calling end, and at least one registration center; The service publishing end is used to annotate the methods included in each type of service to be published, and obtain annotation information corresponding to each method, wherein the annotation information includes the name of at least one registration center; Based on the first preset interceptor, the annotation information corresponding to each method is intercepted; at the same time, the package corresponding to the service to be published is parsed and the identification information corresponding to each method is generated; according to the name of at least one registration center in the annotation information, the address of the registration center corresponding to the name of at least one registration center is read from the preset configuration file; according to the address of the registration center, a link with the registration center is established, and when the link is successfully established, each method included in the service to be published is published to the corresponding one or more registration centers using the identification information corresponding to each method; The registration center is used for registration or forwarding services; The service calling end is used to obtain the service request information sent by the user and parse it to obtain the request instance; Based on the second preset interceptor, the identification information to be requested and at least one registration center name in the request instance are intercepted; according to the at least one registration center name, the address of the registration center corresponding to the name of at least one registration center is read from the preset configuration file; according to the address of the registration center, it is determined whether a link has been established with the registration center; If the link has been established, the corresponding method to be requested is obtained from the services registered in the registration center according to the identification information to be requested.
8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the service publishing method based on multiple registration centers described in any one of claims 1-3 or the service calling method based on multiple registration centers described in any one of claims 4-6 by executing the computer instructions.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the service publishing method based on multiple registration centers described in any one of claims 1-3 or the service calling method based on multiple registration centers described in any one of claims 4-6.
10. A computer program product, characterized in that It comprises computer instructions, and the computer instructions are used to enable a computer to execute the service publishing method based on multiple registration centers described in any one of claims 1-3 or the service calling method based on multiple registration centers described in any one of claims 4-6.
Citation Information
Patent Citations
Information processing method and system, medium and computing device
CN110262902A
Service calling method and device in multi-registration-center scene
CN110377431A
Fusion method and device of multiple registration centers
CN114640657A
Method for unified management of micro-services of multiple registration centers, and apparatus, device and medium
WO2021203968A1