A service invocation method, apparatus, device, and storage medium

By using AOP interceptors and load balancing strategies in the Dubbo service framework, the enterprise type and service call address are automatically determined based on the enterprise ID annotation, which solves the problem of high configuration complexity of enterprise services and achieves the effects of simplified configuration and flexible response to changes in enterprise type.

CN119396493BActive Publication Date: 2025-10-31YIQIQIFUNETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411507827.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-10-31
Estimated Expiration
2044-10-25

AI Technical Summary

Technical Problem

In the Dubbo service framework, the configuration complexity of enterprise services is high and it is difficult to cope with changes in enterprise type. Each service needs to be configured separately, resulting in high maintenance costs.

Method used

The system obtains the target method in the enterprise service request by using a preset AOP interceptor, determines the enterprise number annotation based on the parameter list, uses enterprise service tools to determine the target enterprise type, and determines the service call address through the target load balancing strategy, thus simplifying the configuration process.

Benefits of technology

It reduces configuration complexity and maintenance costs, allows for flexible responses to changes in enterprise type, and makes code implementation more concise.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396493B_ABST
    Figure CN119396493B_ABST
Patent Text Reader

Abstract

This application discloses a service invocation method, apparatus, device, and storage medium, relating to the field of communication technology. The method includes: obtaining the target method in an enterprise service request using a preset AOP interceptor; determining the enterprise number corresponding to a preset enterprise number annotation based on the parameter list of the target method; determining the target enterprise type based on the enterprise number and a preset enterprise service tool; storing the target enterprise type in the target context; the target context being the context information passed during a remote procedure call; running a pre-written target load balancing strategy through a preset service provisioning mechanism; obtaining the target enterprise type from the target context using the target load balancing strategy; and determining the target service invocation address based on the target enterprise type to invoke the corresponding enterprise service. Determining the target service invocation address based on the target enterprise type obtained from the enterprise number corresponding to the preset enterprise number annotation and the target load balancing strategy reduces the complexity of service configuration and maintenance costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and in particular to a service invocation method, apparatus, device, and storage medium. Background Technology

[0002] Currently, Dubbo (a service framework) routing rule configuration files specify thresholds based on the number of employees in an enterprise to route requests to different service clusters. However, each service requires separate configuration, resulting in extremely high complexity and maintenance costs, and making it difficult to handle changes in enterprise types, such as the addition of new enterprise types.

[0003] As can be seen from the above, simplifying the configuration of enterprise services during service invocation is an urgent problem to be solved. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide a service invocation method, apparatus, device, and storage medium that can simplify the configuration of enterprise services during the service invocation process. The specific solution is as follows:

[0005] Firstly, this application provides a service invocation method, including:

[0006] The target method in the enterprise service request is obtained by using a preset AOP interceptor, and the enterprise number corresponding to the preset enterprise number annotation is determined based on the parameter list in the target method.

[0007] Based on the enterprise ID and the preset enterprise service tool, the corresponding target enterprise type is determined and stored in the target context; the target context is the context information passed during the remote procedure call.

[0008] The pre-written target load balancing strategy is executed through a preset service provision mechanism, and the target enterprise type is obtained from the target context using the target load balancing strategy.

[0009] Based on the target enterprise type, the corresponding target service call address is determined, so as to call the corresponding enterprise service through the target service call address.

[0010] Optionally, the method of obtaining the target in the enterprise service request using a preset AOP interceptor includes:

[0011] Use pre-defined AOP interceptors to capture enterprise service requests;

[0012] Obtain the target method from the enterprise service request that meets the preset request conditions, and perform wrap processing on the target method.

[0013] Optionally, determining the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method includes:

[0014] The parameter list in the target method is traversed;

[0015] If the data type of a parameter in the parameter list is numeric and is marked with a preset enterprise number annotation, then the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number;

[0016] If the data type of the parameter in the parameter list is non-numeric and is marked by the preset enterprise number annotation, then the annotation value corresponding to the parameter is used as the target expression. The target expression is run to obtain the target attribute value marked by the preset enterprise number annotation, and the data type corresponding to the target attribute value is converted to an integer type to obtain the enterprise number.

[0017] If the data type of the parameter in the parameter list is an object type and is not marked by the enterprise number annotation, then each attribute in the parameter is traversed, and the corresponding recursive operation is performed based on the traversal result to obtain the enterprise number.

[0018] Optionally, determining the corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and storing the target enterprise type in the target context, includes:

[0019] Determine whether the target enterprise type corresponding to the enterprise number exists in the local cache;

[0020] If the target enterprise type corresponding to the enterprise number exists in the local cache, then the target enterprise type is retrieved from the local cache;

[0021] If the target enterprise type corresponding to the enterprise number does not exist in the local cache, the corresponding enterprise service profile is invoked using the enterprise number, and the corresponding target enterprise type is obtained from the enterprise service profile. The target enterprise type is then stored in the local cache to obtain the updated local cache.

[0022] When the next enterprise number is obtained, the process jumps to the step of determining whether the target enterprise type corresponding to the enterprise number exists in the local cache.

[0023] Optionally, before running the pre-written target load balancing strategy through the preset service provision mechanism, the following steps are also included:

[0024] Create a list of target large enterprise service addresses, a list of target small enterprise service addresses, and a list of available service addresses to obtain the corresponding target load balancing strategy;

[0025] The target large enterprise service address list is a list of IP addresses of service providers belonging to the preset large enterprise type; the target small enterprise service address list is a list of IP addresses of service providers belonging to the preset small enterprise type.

[0026] Optionally, determining the corresponding target service call address based on the target enterprise type includes:

[0027] If the target enterprise type is empty or meets the preset enterprise type conditions, then any of the service call addresses in the list of available service addresses will be determined as the target service call address;

[0028] If the target enterprise type is a preset large enterprise type, then the target large enterprise service address list will be used as the target service call address list;

[0029] If the target enterprise type is a preset small enterprise type, then the target small enterprise service address list will be used as the target service call address list;

[0030] The target service call address is determined based on the intersection of the target service call address list and the available service address list;

[0031] The preset enterprise type condition is that the enterprise type is consistent with the preset target type, and the preset target type is an enterprise type other than the preset large enterprise type and the preset small enterprise type.

[0032] Optionally, determining the target service call address based on the intersection of the target service call address list and the available service address list includes:

[0033] If the intersection of the target service call address list and the available service address list is an empty set, then any one of the service call addresses in the available service address list is determined as the target service call address;

[0034] If the intersection of the target service call address list and the available service address list is not an empty set, then any of the service call addresses in the intersection will be determined as the target service call address.

[0035] Secondly, this application provides a service invocation apparatus, comprising:

[0036] The enterprise ID determination module is used to obtain the target method in the enterprise service request using a preset AOP interceptor, and determine the enterprise ID corresponding to the preset enterprise ID annotation based on the parameter list in the target method.

[0037] The target type determination module is used to determine the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and store the target enterprise type in the target context; the target context is the context information passed during the remote procedure call;

[0038] The load balancing module is used to run a pre-written target load balancing strategy through a preset service provisioning mechanism, and to obtain the target enterprise type from the target context using the target load balancing strategy.

[0039] The service address invocation module is used to determine the corresponding target service invocation address based on the target enterprise type, so as to invoke the corresponding enterprise service through the target service invocation address.

[0040] Thirdly, this application provides an electronic device, comprising:

[0041] Memory, used to store computer programs;

[0042] A processor is used to execute the computer program to implement the aforementioned service invocation method.

[0043] Fourthly, this application provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned service invocation method.

[0044] This application utilizes a preset AOP interceptor to obtain the target method in an enterprise service request, and determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method; determines the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and stores the target enterprise type in the target context; runs a pre-written target load balancing strategy through a preset service provision mechanism, and obtains the target enterprise type from the target context using the target load balancing strategy; determines the corresponding target service call address based on the target enterprise type, and calls the corresponding enterprise service through the target service call address. As can be seen, after obtaining the target method using the preset AOP interceptor, this application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method, then determines the target enterprise type using the enterprise number and the preset enterprise service tool, stores the enterprise type in the target context, then obtains the target enterprise type using the pre-written target load balancing strategy, determines the corresponding target service call address based on the target enterprise type, and calls the corresponding enterprise service through the target service call address. In this way, the target enterprise type is determined based on the enterprise number corresponding to the preset enterprise number annotation, and the target service call address is determined by the target load balancing strategy and the target enterprise type. Service calls can be completed without configuring a large number of enterprise services, which greatly reduces the complexity of configuration and maintenance costs, flexibly responds to changes in enterprise type, and makes the code implementation more concise. Attached Figure Description

[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0046] Figure 1 This is a flowchart of a service invocation method disclosed in this application;

[0047] Figure 2 This is a schematic diagram of the structure of a service invocation device disclosed in this application;

[0048] Figure 3 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0050] Currently, routing rules configuration files specify thresholds based on the number of employees in an enterprise to route requests to different service clusters. This requires individual configuration for each service, resulting in high complexity and maintenance costs, and it struggles to handle changes in enterprise type. To address this, this application provides a service invocation method that determines the target enterprise type based on the enterprise number corresponding to a preset enterprise number annotation, and uses the target load balancing strategy and the target enterprise type to determine the target service invocation address. This method eliminates the need to configure numerous enterprise services, significantly reducing configuration complexity and maintenance costs, flexibly adapting to changes in enterprise type, and making the code implementation more concise.

[0051] See Figure 1 As shown, an embodiment of the present invention discloses a service invocation method, including:

[0052] Step S11: Use a preset AOP interceptor to obtain the target method in the enterprise service request, and determine the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method.

[0053] In this embodiment, a preset AOP interceptor is used to obtain the target method in an enterprise service request, and the enterprise number in the target method is marked with a preset enterprise number annotation. The enterprise number corresponding to the preset enterprise number annotation is then determined from the parameter list of the target method. Specifically, obtaining the target method in an enterprise service request using the preset AOP interceptor includes: obtaining the enterprise service request using the preset AOP interceptor; obtaining the target method in the enterprise service request that meets preset request conditions; and performing wrap-around processing on the target method.

[0054] Understandably, before determining the company ID corresponding to the preset company ID annotation based on the parameter list in the target method, the annotation `@CompanyIdKey` can be defined to mark the field representing the company ID; that is, the field that represents the company ID is marked with this annotation. Specifically, the custom annotation `@CompanyIdKey` can be marked in the Controller method, as shown in the code below:

[0055] @RestController

[0056] public class UserController{

[0057] @GetMapping(" / getUserInfo")

[0058] public String getUserInfo(@CompanyIdKey Integer companyId) {

[0059] }

[0060] Furthermore, a pre-defined AOP (Aspect-Oriented Programming) interceptor can be used to check all Spring (an application framework) RESTful (Representational State Transfer) interfaces to see if each parameter or its corresponding POJO (Plain Ordinary JavaObject) contains a field marked with @CompanyIdKey. If so, the value of the field or parameter marked with @CompanyIdKey can be retrieved. Specifically, you can define a `CompanyAspect` class and declare it as a Spring component using the `@Component` annotation so that it can be automatically scanned and instantiated when the application starts; you can define a pointcut using the `@Pointcut` annotation; you can use the `@annotation` annotation to match all methods with annotations such as `@RequestMapping`, `@GetMapping`, and `@PostMapping`, or RPC (Remote Procedure Call) methods whose package path contains `com.yourname.app.facade`; then you can define a method named `setCompanyType` in the class and annotate it with the `@Around` annotation to perform surround processing (i.e., enhance the target method) on the target method that matches the above pointcut, and execute this before and after the target method is executed; in the `setCompanyType` method, you can obtain the parameter list of the target method through the `getArgs()` method of `ProceedingJoinPoint`.

[0061] In this embodiment, after obtaining the parameter list of the target method, the parameter list is traversed to determine the enterprise number. Specifically, determining the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method includes: traversing the parameter list in the target method; if the data type of the parameter in the parameter list is numeric and is marked by the preset enterprise number annotation, then the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number; if the data type of the parameter in the parameter list is non-numeric and is marked by the preset enterprise number annotation, then the annotation value corresponding to the parameter is used as a target expression, and the target attribute value marked by the preset enterprise number annotation is obtained by running the target expression, and the data type corresponding to the target attribute value is converted to an integer type to obtain the enterprise number; if the data type of the parameter in the parameter list is object type and is not marked by the enterprise number annotation, then each attribute in the parameter is traversed, and corresponding recursive operations are performed based on the traversal results to obtain the enterprise number. The relevant code is shown below:

[0062] @GetMapping(" / addUserInfo")

[0063] public void addUserInfo(@CompanyIdKey("user.companyId") UserVO user){

[0064] }

[0065] Furthermore, if the data type corresponding to the parameter in the parameter list is an object type and is not marked by the enterprise number annotation, then the parameters are traversed, and based on the traversal results, it is determined whether the attribute in the parameter is marked by the enterprise number annotation and is a numeric type. If the attribute in the parameter is marked by the enterprise number annotation and is a numeric type, then the target attribute is converted to an integer type to obtain the enterprise number. If the attribute in the parameter is marked by the enterprise number annotation and is not a numeric type, then the attribute value corresponding to the attribute is used as the target expression, and the parameter value corresponding to the parameter is used as the parameter for running the target expression to execute the target expression, obtaining the target attribute value marked by the preset enterprise number annotation, and the data type corresponding to the target attribute value is converted to an integer type to obtain the enterprise number. If the attribute in the parameter is not marked by the preset enterprise number annotation and is an attribute object type, then the attributes of the object type corresponding to the attribute of the object type are further traversed and determined. It is worth mentioning that the non-numeric type can include collection types such as arrays, Collections or Sets, basic types such as Strings and Chars, and custom classes, without specific limitations here.

[0066] It should be further explained that during the traversal of the parameter list, the company ID is extracted by determining which parameters are marked with the `@CompanyIdKey` annotation (i.e., the preset company ID annotation). Specifically, if a parameter in the parameter list is a numeric type and is marked with the preset company ID annotation, the parameter is converted into a Long type company ID; if a parameter in the parameter list is a non-numeric type and is marked with the preset company ID annotation, the annotation value is obtained as a SpEL (Spring Expression Language) expression, the SpEL expression is executed, and the result is converted into a Long type company ID; if a parameter in the parameter list is an object type and is marked with the preset company ID annotation, all attributes in the parameter are traversed, and recursive operations corresponding to the above steps are performed based on whether the attribute is marked with the preset company ID annotation and the data type of the attribute to obtain the company ID.

[0067] Step S12: Determine the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and store the target enterprise type in the target context; the target context is the context information transmitted during the remote procedure call.

[0068] In this embodiment, after obtaining the target enterprise number, the target enterprise type is determined using the enterprise service profile and the enterprise number, and the target enterprise type is stored in the target context. Specifically, determining the corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and storing the target enterprise type in the target context, includes: determining whether the target enterprise type corresponding to the enterprise number exists in the local cache; if the target enterprise type corresponding to the enterprise number exists in the local cache, then retrieving the target enterprise type from the local cache; if the target enterprise type corresponding to the enterprise number does not exist in the local cache, then calling the corresponding enterprise service profile using the enterprise number, retrieving the corresponding target enterprise type from the enterprise service profile, and storing the target enterprise type in the local cache to obtain an updated local cache; when the next enterprise number is obtained, the process jumps to the step of determining whether the target enterprise type corresponding to the enterprise number exists in the local cache.

[0069] Understandably, the target company type is determined based on the company ID, and this company type is included in the context as an attachment for later use. It's worth noting that when implementing the company type determination and caching logic, the target company type can be obtained by calling the company profile service using the company ID. The company profile service can be designed as an RPC service that receives the company ID as a parameter and returns a response containing company type information. To improve performance and avoid frequent calls to the company profile service, a local caching mechanism can be implemented using Guava Cache (i.e., local caching).

[0070] Furthermore, the target enterprise type is saved to the local cache so that the target enterprise type can be determined based on the local cache and the enterprise number. Specifically, an enterprise profile service (CompanyProfileService) can be defined, which can provide a method `getCompanyTypeById` to return the target enterprise type based on the enterprise number. The CompanyProfileService can be injected, and a Guava Cache instance can be created to cache the enterprise type information corresponding to the target enterprise type. When it is necessary to determine the enterprise type, first check whether the enterprise type corresponding to the enterprise number is already cached in the local cache. If the enterprise type corresponding to the enterprise number exists in the local cache, the corresponding target enterprise type is directly retrieved from the cache based on the enterprise number. If the enterprise type corresponding to the enterprise number does not exist in the local cache, the `getCompanyTypeById` method of the CompanyProfileService (i.e., the enterprise profile service) is called to obtain the corresponding enterprise type, and the enterprise type is added to the local cache for use in subsequent requests.

[0071] Furthermore, it can be understood that an aspect can be implemented first to extract the enterprise number from the parameters of the controller layer method and obtain the enterprise type corresponding to the enterprise number. Then, the enterprise type is placed in the target context as an attachment so that the enterprise type information can be easily obtained and used in subsequent RPC calls.

[0072] Step S13: Run the written target load balancing strategy through the preset service provision mechanism, and use the target load balancing strategy to obtain the target enterprise type from the target context.

[0073] In this embodiment, a custom load balancing strategy is defined to obtain a target load balancing strategy, and the target load balancing strategy is enabled through an SPI configuration file to obtain the target enterprise type from the target context through the target load balancing strategy. Specifically, a custom `CompanyLoadBalance` class can be defined, inheriting from `AbstractLoadBalance`, which overrides the abstract method `doSelect`. The custom `CompanyLoadBalance` is configured using SPI. A file `org.apache.dubbo.rpc.cluster.LoadBalance` is created under `META-INF / dubbo`, and the following is written to the file: `company=your.package.name.CompanyLoadBalance`.

[0074] Understandably, before running the target load balancing strategy, lists of IP (Internet Protocol Address) addresses belonging to large enterprises and small enterprises are defined separately, denoted as largeIPList (target large enterprise service address list) and smallIPList (target small enterprise service address list). Specifically, before running the pre-written target load balancing strategy through the preset service provision mechanism, the process further includes: creating a target large enterprise service address list, a target small enterprise service address list, and an available service address list to obtain the corresponding target load balancing strategy; wherein, the target large enterprise service address list is a list of IP addresses belonging to service providers of the preset large enterprise type; the target small enterprise service address list is a list of IP addresses belonging to service providers of the preset small enterprise type; and the available service address list is a list of all currently available service addresses.

[0075] Step S14: Determine the corresponding target service call address based on the target enterprise type, so as to call the corresponding enterprise service through the target service call address.

[0076] In this embodiment, the target enterprise type is determined based on a preset enterprise type condition, and the target service call address is determined based on the determination result, so as to call the corresponding enterprise service based on the target service call address. Specifically, determining the corresponding target service call address based on the target enterprise type includes: if the target enterprise type is empty or meets the preset enterprise type condition, then any service call address in the available service address list is determined as the target service call address; if the target enterprise type is a preset large enterprise type, then the target large enterprise service address list is used as the target service call address list; if the target enterprise type is a preset small enterprise type, then the target small enterprise service address list is used as the target service call address list; the target service call address is determined based on the intersection of the target service call address list and the available service address list; wherein, the preset enterprise type condition is that the enterprise type is consistent with the preset target type, and the preset target type is an enterprise type other than the preset large enterprise type and the preset small enterprise type.

[0077] Understandably, in the `doSelect` method described above, the enterprise type of the current enterprise is obtained from the target context, and an Invoker (i.e., the calling address) is selected and invoked based on the enterprise type. If no corresponding Invoker is specified for the enterprise type, an Invoker is randomly selected for invocation. Specifically, the `doSelect` method has one parameter, `invokers`, which is all currently available Invokers, denoted as `allInvokerList` (i.e., the list of available service addresses); it obtains the enterprise type of the current thread from the target context; if the target enterprise type is empty or unknown, an Invoker is randomly selected from `allInvokerList` and returned; if the target enterprise type is a large enterprise, `largeIPList` is used as the list of target Invokers; if the target enterprise type is a small enterprise, `samllIPList` is used as the list of target Invokers, denoted as `targetInvokerList` (i.e., the list of available target service addresses).

[0078] Furthermore, the target service call address is determined based on the aforementioned list of available target service addresses and the list of available service addresses. Specifically, determining the target service call address based on the intersection of the list of available target service address and the list of available service address includes: if the intersection of the list of available target service address and the list of available service address is an empty set, then any service call address in the list of available service address is determined as the target service call address; if the intersection of the list of available target service address and the list of available service address is not an empty set, then any service call address in the intersection is determined as the target service call address.

[0079] Furthermore, it can be understood that the intersection of targetInvokerList and allInvokerList can be taken, denoted as realInvokerList; if realInvokerList is empty, one is randomly selected from allInvokerList, which indicates that the target enterprise type is neither a large enterprise nor a small enterprise; if realInvokerList is not empty, an Invoker is randomly selected from realInvokerList and returned.

[0080] As can be seen from the above, after obtaining the target method using a preset AOP interceptor, this application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method. Then, it uses the enterprise number and preset enterprise service tools to determine the target enterprise type and stores the enterprise type in the target context. Next, it uses a pre-written target load balancing strategy to obtain the target enterprise type, determines the corresponding target service call address based on the target enterprise type, and calls the corresponding enterprise service through the target service call address. In this way, by determining the target enterprise type based on the enterprise number corresponding to the preset enterprise number annotation and using the target load balancing strategy and the target enterprise type to determine the target service call address, service calls can be completed without configuring a large number of enterprise services, greatly reducing configuration complexity and maintenance costs, flexibly responding to changes in enterprise types, and making the code implementation more concise.

[0081] Accordingly, see Figure 2 As shown, this application also provides a service invocation apparatus, including:

[0082] The enterprise number determination module 11 is used to obtain the target method in the enterprise service request using a preset AOP interceptor, and determine the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method.

[0083] The target type determination module 12 is used to determine the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and store the target enterprise type in the target context; the target context is the context information transmitted during the remote procedure call;

[0084] The load balancing module 13 is used to run a pre-written target load balancing strategy through a preset service provisioning mechanism, and to obtain the target enterprise type from the target context using the target load balancing strategy.

[0085] The service address invocation module 14 is used to determine the corresponding target service invocation address based on the target enterprise type, so as to invoke the corresponding enterprise service through the target service invocation address.

[0086] As can be seen from the above, after obtaining the target method using a preset AOP interceptor, this application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method. Then, it uses the enterprise number and preset enterprise service tools to determine the target enterprise type and stores the enterprise type in the target context. Next, it uses a pre-written target load balancing strategy to obtain the target enterprise type, determines the corresponding target service call address based on the target enterprise type, and calls the corresponding enterprise service through the target service call address. In this way, by determining the target enterprise type based on the enterprise number corresponding to the preset enterprise number annotation and using the target load balancing strategy and the target enterprise type to determine the target service call address, service calls can be completed without configuring a large number of enterprise services, greatly reducing configuration complexity and maintenance costs, flexibly responding to changes in enterprise types, and making the code implementation more concise.

[0087] In some specific embodiments, the enterprise number determination module 11 may specifically include:

[0088] The service request acquisition unit is used to acquire enterprise service requests using a preset AOP interceptor.

[0089] The target method acquisition unit is used to acquire target methods in enterprise service requests that meet preset request conditions, and to perform wrap-around processing on the target methods.

[0090] In some specific embodiments, the enterprise number determination module 11 may specifically include:

[0091] The parameter list traversal unit is used to traverse the parameter list in the target method;

[0092] The first number determination unit is used to convert the parameter value corresponding to the parameter into an integer type if the data type of the parameter in the parameter list is numeric and is marked by a preset enterprise number annotation, so as to obtain the enterprise number.

[0093] The second number determination unit is used to, if the data type corresponding to the parameter in the parameter list is a non-numeric type and is marked by the preset enterprise number annotation, take the annotation value corresponding to the parameter as the target expression, obtain the target attribute value marked by the preset enterprise number annotation by running the target expression, and convert the data type corresponding to the target attribute value into an integer type to obtain the enterprise number;

[0094] The third number determination unit is used to traverse each attribute in the parameter if the data type corresponding to the parameter in the parameter list is an object type and is not marked by the enterprise number annotation, and to perform corresponding recursive operations based on the traversal results to obtain the enterprise number.

[0095] In some specific embodiments, the target type determination module 12 may specifically include:

[0096] The target type determination unit is used to determine whether the target enterprise type corresponding to the enterprise number exists in the local cache;

[0097] The target type acquisition unit is used to acquire the target enterprise type from the local cache if the target enterprise type corresponding to the enterprise number exists in the local cache;

[0098] The target type storage unit is used to call the corresponding enterprise service profile using the enterprise number if the target enterprise type corresponding to the enterprise number does not exist in the local cache, and to obtain the corresponding target enterprise type from the enterprise service profile and store the target enterprise type in the local cache to obtain the updated local cache.

[0099] The next number acquisition unit is used to jump to the step of determining whether the target enterprise type corresponding to the enterprise number exists in the local cache when the next enterprise number is acquired.

[0100] In some specific embodiments, the service invocation device may further include:

[0101] The target strategy determination unit is used to create a list of target large enterprise service addresses, a list of target small enterprise service addresses, and a list of available service addresses to obtain the corresponding target load balancing strategy.

[0102] In some specific embodiments, the service address invocation module 14 may specifically include:

[0103] The second target type determination unit is used to determine any one of the service call addresses in the list of available service addresses as the target service call address if the target enterprise type is empty or meets the preset enterprise type conditions.

[0104] The first list determination unit is used to use the target large enterprise service address list as the target service call address list if the target enterprise type is a preset large enterprise type.

[0105] The second list determination unit is used to use the target small business service address list as the target service call address list if the target enterprise type is a preset small business type.

[0106] The first address determination unit is used to determine the target service call address based on the intersection of the target service call address list and the available service address list.

[0107] In some specific embodiments, the service address invocation module 14 may specifically include:

[0108] The second address determination unit is used to determine any one of the service call addresses in the list of available service addresses as the target service call address if the intersection of the target service call address list and the list of available service addresses is an empty set.

[0109] The third address determination unit is used to determine any one of the service call addresses in the intersection of the target service call address list and the available service address list as the target service call address if the intersection is not an empty set.

[0110] Furthermore, embodiments of this application also disclose an electronic device, Figure 3 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the service invocation method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0111] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0112] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon can include an operating system 221, computer programs 222, etc., and the storage method can be temporary storage or permanent storage.

[0113] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the service invocation methods executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0114] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed service invocation method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0115] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0116] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0117] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0118] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0119] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A service invocation method, characterized in that, include: The target method in the enterprise service request is obtained by using a preset AOP interceptor, and the enterprise number corresponding to the preset enterprise number annotation is determined based on the parameter list in the target method. Based on the enterprise number and the preset enterprise service tools, the corresponding target enterprise type is determined and the target enterprise type is stored in the target context; The target context is the context information passed during the remote procedure call; The pre-written target load balancing strategy is executed through a preset service provision mechanism, and the target enterprise type is obtained from the target context using the target load balancing strategy. Based on the target enterprise type, the corresponding target service call address is determined, so as to call the corresponding enterprise service through the target service call address; The step of determining the corresponding target service call address based on the target enterprise type includes: If the target enterprise type is empty or meets the preset enterprise type conditions, then any of the service call addresses in the list of available service addresses will be determined as the target service call address; If the target enterprise type is a preset large enterprise type, then the target large enterprise service address list will be used as the target service call address list; If the target enterprise type is a preset small enterprise type, then the target small enterprise service address list will be used as the target service call address list; The target service call address is determined based on the intersection of the target service call address list and the available service address list; The preset enterprise type condition is that the enterprise type is consistent with the preset target type, and the preset target type is an enterprise type other than the preset large enterprise type and the preset small enterprise type; the target large enterprise service address list is a list of IP addresses of service providers belonging to the preset large enterprise type; the target small enterprise service address list is a list of IP addresses of service providers belonging to the preset small enterprise type; and the available service address list is a list of all currently available service addresses.

2. The service invocation method according to claim 1, characterized in that, The method for obtaining the target in an enterprise service request using a preset AOP interceptor includes: Use pre-defined AOP interceptors to capture enterprise service requests; Obtain the target method from the enterprise service request that meets the preset request conditions, and perform wrap processing on the target method.

3. The service invocation method according to claim 1, characterized in that, The step of determining the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method includes: The parameter list in the target method is traversed; If the data type of a parameter in the parameter list is numeric and is marked with a preset enterprise number annotation, then the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number; If the data type of the parameter in the parameter list is non-numeric and is marked by the preset enterprise number annotation, then the annotation value corresponding to the parameter is used as the target expression. The target expression is run to obtain the target attribute value marked by the preset enterprise number annotation, and the data type corresponding to the target attribute value is converted to an integer type to obtain the enterprise number. If the data type of the parameter in the parameter list is an object type and is not marked by the enterprise number annotation, then each attribute in the parameter is traversed, and the corresponding recursive operation is performed based on the traversal result to obtain the enterprise number.

4. The service invocation method according to any one of claims 1 to 3, characterized in that, The step of determining the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and storing the target enterprise type in the target context, includes: Determine whether the target enterprise type corresponding to the enterprise number exists in the local cache; If the target enterprise type corresponding to the enterprise number exists in the local cache, then the target enterprise type is retrieved from the local cache; If the target enterprise type corresponding to the enterprise number does not exist in the local cache, the corresponding enterprise service profile is invoked using the enterprise number, and the corresponding target enterprise type is obtained from the enterprise service profile. The target enterprise type is then stored in the local cache to obtain the updated local cache. When the next enterprise number is obtained, the process jumps to the step of determining whether the target enterprise type corresponding to the enterprise number exists in the local cache.

5. The service invocation method according to claim 4, characterized in that, Before running the pre-written target load balancing strategy through the preset service provision mechanism, the following steps are also included: Create a list of target large enterprise service addresses, a list of target small enterprise service addresses, and a list of available service addresses to obtain the corresponding target load balancing strategy.

6. The service invocation method according to claim 1, characterized in that, Determining the target service call address based on the intersection of the target service call address list and the available service address list includes: If the intersection of the target service call address list and the available service address list is an empty set, then any one of the service call addresses in the available service address list is determined as the target service call address; If the intersection of the target service call address list and the available service address list is not an empty set, then any of the service call addresses in the intersection will be determined as the target service call address.

7. A service invocation device, characterized in that, include: The enterprise ID determination module is used to obtain the target method in the enterprise service request using a preset AOP interceptor, and determine the enterprise ID corresponding to the preset enterprise ID annotation based on the parameter list in the target method. The target type determination module is used to determine the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and store the target enterprise type in the target context; The target context is the context information passed during the remote procedure call; The load balancing module is used to run a pre-written target load balancing strategy through a preset service provisioning mechanism, and to obtain the target enterprise type from the target context using the target load balancing strategy. The service address invocation module is used to determine the corresponding target service invocation address based on the target enterprise type, so as to invoke the corresponding enterprise service through the target service invocation address; Specifically, the service address invocation module is used to: determine any one of the service invocation addresses in the available service address list as the target service invocation address if the target enterprise type is empty or meets the preset enterprise type conditions; if the target enterprise type is a preset large enterprise type, use the target large enterprise service address list as the target service invocation address list; if the target enterprise type is a preset small enterprise type, use the target small enterprise service address list as the target service invocation address list; and determine the target service invocation address based on the intersection of the target service invocation address list and the available service address list. The preset enterprise type conditions are that the enterprise type matches the preset target type, and the preset target type is an enterprise type other than the preset large enterprise type and the preset small enterprise type. The target large enterprise service address list is a list of IP addresses of service providers belonging to the preset large enterprise type; the target small enterprise service address list is a list of IP addresses of service providers belonging to the preset small enterprise type; and the available service address list is a list of all currently available service addresses.

8. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the service invocation method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the service invocation method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Load balancing system for remote service calling based on real-time load rate

    CN106453125A

  • Server allocation method and device, electronic equipment and computer readable storage medium

    CN118200321A