Service calling method and device, equipment and storage medium
By using preset AOP interceptors and load balancing strategies in Dubbo, the configuration of enterprise services is simplified, the problems of configuration complexity and maintenance costs in the existing technology are solved, and service calls that flexibly respond to changes in enterprise types are achieved.
Patent Information
- Application Number
- CN202411507827.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-10-25
AI Technical Summary
In the Dubbo routing rule configuration file, requests are routed to different service clusters according to the threshold of the number of enterprise employees, resulting in high configuration complexity and maintenance costs, making it difficult to cope with changes in enterprise types.
The target method in the enterprise service request is obtained through the 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, thereby determining the target enterprise type, and using the target load balancing strategy to determine the target service call address, implement service calls.
It simplifies the configuration of enterprise services, reduces configuration complexity and maintenance costs, and can flexibly respond to changes in enterprise types, making the code implementation more concise.
Smart Images

Figure CN119396493A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a service calling method, device, equipment and storage medium. Background Art
[0002] Currently, in the routing rule configuration file of Dubbo (a service framework), requests are routed to different service clusters based on the threshold of the number of employees in an enterprise. However, each service needs to be configured separately, which is extremely complex and costly to maintain, and it is difficult to cope with changes in enterprise types, such as the addition of new enterprise types.
[0003] As can be seen from the above, how to simplify the configuration of enterprise services during the service call process is an urgent problem to be solved. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a service calling method, apparatus, device and storage medium, which can simplify the configuration of enterprise services during the service calling process. The specific scheme is as follows:
[0005] In a first aspect, the present application provides a service calling method, comprising:
[0006] Obtain a target method in the enterprise service request using a preset AOP interceptor, and determine an enterprise number corresponding to a preset enterprise number annotation based on a parameter list in the target method;
[0007] Determine a corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and store the target enterprise type in a target context; the target context is context information transmitted during a remote procedure call;
[0008] Running the programmed target load balancing strategy through a preset service provision mechanism, and obtaining the target enterprise type from the target context using the target load balancing strategy;
[0009] A corresponding target service calling address is determined based on the target enterprise type, so as to call a corresponding enterprise service through the target service calling address.
[0010] Optionally, the using a preset AOP interceptor to obtain a target method in an enterprise service request includes:
[0011] Use the preset AOP interceptor to obtain enterprise service requests;
[0012] Obtain a target method that meets a preset request condition in an enterprise service request, and perform a surround process 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] Traversing the parameter list in the target method;
[0015] If the data type corresponding to the parameter in the parameter list is a numeric type and is annotated with a preset enterprise number, the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number;
[0016] If the data type corresponding to the parameter in the parameter list is a non-numeric type and is annotated with the preset enterprise number, the annotation value corresponding to the parameter is used as the target expression, the target attribute value annotated with the preset enterprise number 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;
[0017] If the data type corresponding to the parameter in the parameter list is an object type and is not annotated by the enterprise number, each attribute in the parameter is traversed, and a corresponding recursive operation is performed based on the traversal result to obtain the enterprise number.
[0018] Optionally, determining a corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and storing the target enterprise type in a target context includes:
[0019] Determine whether there is a target enterprise type corresponding to the enterprise number in the local cache;
[0020] If the target enterprise type corresponding to the enterprise number exists in the local cache, obtaining the target enterprise type 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 portrait is called using the enterprise number, and the corresponding target enterprise type is obtained from the enterprise service portrait, and the target enterprise type is stored in the local cache to obtain an updated local cache;
[0022] When the next enterprise number is obtained, the process jumps to the step of determining whether there is a target enterprise type corresponding to the enterprise number in the local cache.
[0023] Optionally, before running the programmed target load balancing strategy through the preset service provision mechanism, the method further includes:
[0024] Create a target large enterprise service address list, a target small enterprise service address list, and an available service address list to obtain a corresponding target load balancing strategy;
[0025] The target large enterprise service address list is a list of IP addresses of service providers belonging to a preset large enterprise type; the target small enterprise service address list is a list of IP addresses of service providers belonging to a preset small enterprise type.
[0026] Optionally, determining a corresponding target service calling address based on the target enterprise type includes:
[0027] If the target enterprise type is empty or meets the preset enterprise type condition, any service call address in the available service address list is determined as the target service call address;
[0028] If the target enterprise type is a preset large enterprise type, the target large enterprise service address list is used as the target service calling address list;
[0029] If the target enterprise type is a preset small enterprise type, the target small enterprise service address list is used as the target service calling address list;
[0030] Determine a target service calling address based on an intersection of the target service calling address list and the available service address list;
[0031] Among them, the preset enterprise type condition is that the enterprise type is consistent with the preset target type, and the preset target type is the enterprise type other than the preset large enterprise type and the preset small enterprise type.
[0032] Optionally, determining the target service calling address based on the intersection of the target service calling 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, any service call address 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, any one of the service call addresses in the intersection is determined as the target service call address.
[0035] In a second aspect, the present application provides a service calling device, comprising:
[0036] An enterprise number determination module, used to obtain a target method in an enterprise service request using a preset AOP interceptor, and determine an enterprise number corresponding to a preset enterprise number annotation based on a parameter list in the target method;
[0037] A target type determination module, used to determine the corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and store the target enterprise type in a target context; the target context is context information transmitted during a remote procedure call;
[0038] A load balancing module, used to run the programmed target load balancing strategy through a preset service provision mechanism, and obtain the target enterprise type from the target context using the target load balancing strategy;
[0039] The service address calling module is used to determine the corresponding target service calling address based on the target enterprise type, so as to call the corresponding enterprise service through the target service calling address.
[0040] In a third aspect, the present application provides an electronic device, including:
[0041] Memory, used to store computer programs;
[0042] The processor is used to execute the computer program to implement the aforementioned service calling method.
[0043] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned service calling method when executed by a processor.
[0044] The present application utilizes a preset AOP interceptor to obtain the target method in the 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 the written target load balancing strategy through the 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, so as to call the corresponding enterprise service through the target service call address. As can be seen from the above, after obtaining the target method using the preset AOP interceptor, the present application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method, and then determines the target enterprise type using the enterprise number and the preset enterprise service tool, and stores the enterprise type in the target context, and then obtains the target enterprise type using the 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 using the target load balancing strategy and the target enterprise type. The service call can be completed without configuring a large number of enterprise services, which greatly reduces the configuration complexity and maintenance costs, flexibly responds to changes in enterprise types, and makes the code implementation more concise. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0046] Figure 1 A flow chart of a service calling method disclosed in this application;
[0047] Figure 2 A schematic diagram of the structure of a service calling device disclosed in this application;
[0048] Figure 3 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] At present, in the routing rule configuration file, it is specified that requests are routed to different service clusters according to the threshold of the number of employees in the enterprise. This requires that each service needs to be configured separately, which is extremely complex and has high maintenance costs, and it is difficult to cope with changes in enterprise types. To this end, the present application provides a service calling method, which determines the target enterprise type based on the enterprise number corresponding to the preset enterprise number annotation, and uses the target load balancing strategy and the target enterprise type to determine the target service calling address. The service call 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 types, and makes the code implementation more concise.
[0051] See also Figure 1 As shown, an embodiment of the present invention discloses a service calling method, including:
[0052] Step S11: Use a preset AOP interceptor to obtain a 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 a target method in an enterprise service request, and the enterprise number in the target method is marked by a preset enterprise number annotation, so that the enterprise number corresponding to the preset enterprise number annotation is determined through a parameter list in the target method. Specifically, the use of a preset AOP interceptor to obtain a target method in an enterprise service request includes: using a preset AOP interceptor to obtain an enterprise service request; obtaining a target method in the enterprise service request that meets a preset request condition, and performing surround processing on the target method.
[0054] It is understandable that before determining the company number corresponding to the preset company number annotation based on the parameter list in the target method, the annotation @CompanyIdKey can be defined to mark the field representing the company number, that is, which field is the company number is marked with this annotation. That is, the custom annotation @CompanyIdKey can be marked in the Controller method, and the code is as follows:
[0055] @RestController
[0056] public class UserController {
[0057] @GetMapping(" / getUserInfo")
[0058] public String getUserInfo(@CompanyIdKey Integer companyId) {
[0059] }
[0060] Furthermore, you can use the preset AOP (Aspect Oriented Programming) interceptor for all Spring (an application framework) RESTful (Representational State Transfer) interfaces to find out whether there is a field marked by @CompanyIdKey in each parameter or the POJO (Plain Ordinary JavaObject) corresponding to the parameter. If there is, get the value of the field or parameter marked by @CompanyIdKey. Specifically, you can define a CompanyAspect class and use the @Component annotation to declare it as a Spring component so that it can be automatically scanned and instances created when the program starts; you can use the @Pointcut annotation to define a pointcut that meets the requirements; you can use the @annotation annotation to match all methods annotated with @RequestMapping, @GetMapping, @PostMapping, etc., or RPC (i.e., remote call protocol) methods with com.yourname.app.facade in the package path; you can then define a method named setCompanyType in the class and mark it with the @Around annotation to surround the target method that meets the above pointcut (i.e., enhance the target method), and execute it before and after the target method is executed; in the setCompanyType method, you can use the getArgs() method of ProceedingJoinPoint to get the parameter list of the target method.
[0061] In this embodiment, after obtaining the parameter list of the target method, the parameter list is traversed to determine the enterprise number. Specifically, the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method is determined, including: traversing the parameter list in the target method; if the data type corresponding to the parameter in the parameter list is a numeric type and is marked with a preset enterprise number annotation, the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number; if the data type corresponding to the parameter in the parameter list is a non-numeric type and is marked with the preset enterprise number annotation, the annotation value corresponding to the parameter is used as the target expression, and the target attribute value marked with 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 corresponding to the parameter in the parameter list is an object type and is not marked with the enterprise number annotation, 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] Further, if the data type corresponding to the parameter in the parameter list is an object type and is not annotated with the enterprise number, the parameter is traversed, and based on the traversal result, it is determined whether the attribute in the parameter is annotated with the enterprise number and is a digital type; if the attribute in the parameter is annotated with the enterprise number and is a digital type, the target attribute is converted to an integer type to obtain the enterprise number; if the attribute in the parameter is annotated with the enterprise number and is a non-digital type, 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 the target expression to execute the target expression, obtain the target attribute value annotated with the preset enterprise number, and convert the data type corresponding to the target attribute value to an integer type to obtain the enterprise number. If the attribute in the parameter is not annotated with the preset enterprise number and is the attribute object type, the attribute of the object type corresponding to the attribute of the object type is further traversed and determined. It is worth mentioning that the non-digital type can include collection types such as arrays, Collections or Sets, basic types such as String and Char, and custom classes, which are not specifically limited here.
[0066] It should be further explained that, in the process of traversing the parameter list, the company number is extracted by judging which parameters are annotated with @CompanyIdKey (i.e., the preset company number annotation). Specifically, if the parameters in the parameter list are of numeric type and are annotated with the preset company number, the parameters are converted into a company number of the Long type; if the parameters in the parameter list are of non-numeric type and are annotated with the preset company number, the value of the annotation is obtained as a SpEL (Spring Expression Language, i.e., an expression language) expression, the SpEL expression is run, and the result of the run is converted into a company number of the Long type; if the parameters in the parameter list are of object type and are not annotated with the preset company number, all attributes in the parameters are traversed, and based on whether the attributes are annotated with the preset company number and the data type corresponding to the attributes, the recursive operation corresponding to the above steps is performed to obtain the company number.
[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 a target context; the target context is 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 portrait and the enterprise number, and the target enterprise type is stored in the target context. Specifically, the determination of the corresponding target enterprise type based on the enterprise number and the preset enterprise service tool, and the storage of the target enterprise type in the target context, includes: judging 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, obtaining 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, calling the corresponding enterprise service portrait using the enterprise number, obtaining the corresponding target enterprise type from the enterprise service portrait, and storing the target enterprise type in the local cache to obtain an updated local cache; when the next enterprise number is obtained, jumping to the step of judging whether the target enterprise type corresponding to the enterprise number exists in the local cache.
[0069] It is understandable that the target enterprise type is determined according to the enterprise number, and the enterprise type is placed in the context as an attachment for subsequent use. It is worth mentioning that when implementing the enterprise type determination and caching logic, the enterprise portrait service can be called by the enterprise number to obtain the target enterprise type. The enterprise portrait service can be designed as an RPC service that receives the enterprise number as a parameter and returns a response containing the enterprise type information. In order to improve performance and avoid frequent calls to the enterprise portrait service, Guava Cache (i.e. local cache) can be used to implement a local cache mechanism.
[0070] Furthermore, the target enterprise type is saved in the local cache so that the target enterprise type can be determined based on the local cache and the enterprise number. Specifically, a company profile service CompanyProfileService can be defined, and a method getCompanyTypeById can be provided to return the target enterprise type according to the enterprise number; 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 the enterprise type needs to be determined, first check whether the enterprise type corresponding to the enterprise number has been 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 obtained from the cache according to the enterprise number; if the enterprise type corresponding to the enterprise number does not exist in the local cache, the getCompanyTypeById method of CompanyProfileService (i.e., the enterprise profile service) is called to obtain the corresponding enterprise type, and the enterprise type is placed in the local cache for subsequent requests.
[0071] It can be further understood that a section 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, and then put the enterprise type into 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 programmed target load balancing strategy through a 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 load balancing strategy is customized 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 CompanyLoadBalance class can be customized to inherit AbstractLoadBalance, which overrides the abstract method doSelect; use SPI to configure the customized CompanyLoadBalance, create a file org.apache.dubbo.rpc.cluster.LoadBalance under META-INF / dubbo, and write in the file: company=your.package.name.CompanyLoadBalance.
[0074] It is understandable that before running the target load balancing strategy, the IP (Internet Protocol Address) address lists of service providers belonging to large enterprises and small enterprises are defined respectively, which are recorded as largeIPList (i.e., the target large enterprise service address list) and smallIPList (i.e., the target small enterprise service address list). Specifically, before running the written target load balancing strategy through the preset service provision mechanism, it also 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 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.
[0075] Step S14: determine a corresponding target service calling address based on the target enterprise type, so as to call a corresponding enterprise service through the target service calling address.
[0076] In this embodiment, the target enterprise type is judged based on the preset enterprise type condition, and the target service call address is determined based on the judgment result, so as to call the corresponding enterprise service based on the target service call address. Specifically, the determination of 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, 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, 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, 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] It can be understood that in the above doSelect method, the enterprise type of the current enterprise is obtained from the target context, and an Invoker (i.e., the calling address) is selected for calling according to the enterprise type. If the enterprise type does not specify a corresponding Invoker, an Invoker is randomly selected for calling. Specifically, the doSelect method has a parameter called invokers, which is all currently available Invokers, recorded as allInvokerList (i.e., a list of available service addresses); the enterprise type of the current thread is obtained from the target context; if the target enterprise type is empty or an unknown enterprise type, 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, recorded as targetInvokerList (i.e., a list of target available service addresses).
[0078] Further, the target service call address is determined based on the above-mentioned target available service address list and the available service address list. Specifically, the target service call address is determined based on the intersection of the target service call address list and the available service address list, including: if the intersection of the target service call address list and the available service address list is an empty set, then any 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 is determined as the target service call address.
[0079] It can be further understood that the intersection of targetInvokerList and allInvokerList can be taken, recorded as realInvokerList; if realInvokerList is empty, one is randomly obtained 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 the realInvokerList list and returned.
[0080] As can be seen from the above, after the preset AOP interceptor is used to obtain the target method, the present application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method, and then uses the enterprise number and the preset enterprise service tool to determine the target enterprise type, and stores the enterprise type in the target context, and then uses the 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, 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 using the target load balancing strategy and the target enterprise type. The service call can be completed without configuring a large number of enterprise services, which greatly reduces the complexity of configuration and maintenance costs, and flexibly responds to changes in enterprise types, making the code implementation more concise.
[0081] Accordingly, see Figure 2 As shown, the present application also provides a service calling device, including:
[0082] The enterprise number determination module 11 is used to obtain the target method in the enterprise service request by using the 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] A target type determination module 12 is used to determine a corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and store the target enterprise type in a target context; the target context is context information transmitted during a remote procedure call;
[0084] The load balancing module 13 is used to run the programmed target load balancing strategy through a preset service provision mechanism, and obtain the target enterprise type from the target context using the target load balancing strategy;
[0085] The service address calling module 14 is used to determine a corresponding target service calling address based on the target enterprise type, so as to call a corresponding enterprise service through the target service calling address.
[0086] As can be seen from the above, after the preset AOP interceptor is used to obtain the target method, the present application determines the enterprise number corresponding to the preset enterprise number annotation based on the parameter list in the target method, and then uses the enterprise number and the preset enterprise service tool to determine the target enterprise type, and stores the enterprise type in the target context, and then uses the 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, 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 using the target load balancing strategy and the target enterprise type. The service call can be completed without configuring a large number of enterprise services, which greatly reduces the complexity of configuration and maintenance costs, and flexibly responds to changes in enterprise types, making the code implementation more concise.
[0087] In some specific implementations, the enterprise number determination module 11 may specifically include:
[0088] A 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 a target method that meets a preset request condition in an enterprise service request and perform surround processing on the target method.
[0090] In some specific implementations, the enterprise number determination module 11 may specifically include:
[0091] A parameter list traversal unit, used for traversing the parameter list in the target method;
[0092] A first number determination unit, configured to convert a parameter value corresponding to the parameter into an integer type to obtain an enterprise number if the data type corresponding to the parameter in the parameter list is a digital type and is annotated with a preset enterprise number;
[0093] A second number determination unit is used for, if the data type corresponding to the parameter in the parameter list is a non-numeric type and is annotated with the preset enterprise number, using the annotation value corresponding to the parameter as a target expression, obtaining a target attribute value annotated with the preset enterprise number by running the target expression, and converting 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 annotated with the enterprise number, and perform corresponding recursive operations based on the traversal results to obtain the enterprise number.
[0095] In some specific implementations, the target type determination module 12 may specifically include:
[0096] A target type determination unit, configured to determine whether a target enterprise type corresponding to the enterprise number exists in the local cache;
[0097] a target type acquisition unit, configured 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] A target type storage unit, configured to, if the target enterprise type corresponding to the enterprise number does not exist in the local cache, call the corresponding enterprise service portrait using the enterprise number, obtain the corresponding target enterprise type from the enterprise service portrait, and store the target enterprise type in the local cache to obtain an 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 implementations, the service calling device may further include:
[0101] The target policy determination unit is used to create a target large enterprise service address list, a target small enterprise service address list and an available service address list to obtain a corresponding target load balancing policy.
[0102] In some specific implementations, the service address calling module 14 may specifically include:
[0103] A second target type determination unit, configured to determine any of the service call addresses in the available service address list as a target service call address if the target enterprise type is empty or satisfies a preset enterprise type condition;
[0104] A first list determination unit, configured to use the target large enterprise service address list as a target service calling address list if the target enterprise type is a preset large enterprise type;
[0105] A second list determination unit, configured to use the target small business service address list as the target service calling address list if the target business type is a preset small business type;
[0106] The first address determining unit is configured to determine a target service calling address based on an intersection of the target service calling address list and the available service address list.
[0107] In some specific implementations, the service address calling module 14 may specifically include:
[0108] a second address determining unit, configured to determine any one of the service calling addresses in the available service address list as the target service calling address if the intersection of the target service calling address list and the available service address list is an empty set;
[0109] The third address determining unit is configured to determine any one of the service calling addresses in the intersection as the target service calling address if the intersection of the target service calling address list and the available service address list is not an empty set.
[0110] Furthermore, the present application also discloses an electronic device. Figure 3 This is a structural diagram of an electronic device 20 according to an exemplary embodiment, and the content in the figure cannot be regarded as any limitation on the scope of use 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 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the service calling method disclosed in any of the aforementioned embodiments. In addition, 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 working 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 the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain 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 may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method may be temporary storage or permanent storage.
[0113] The operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the service calling method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0114] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned disclosed service calling method. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.
[0115] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0116] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0117] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0118] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0119] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A service calling method, characterized in that: include: Obtain a target method in the enterprise service request using a preset AOP interceptor, and determine an enterprise number corresponding to a preset enterprise number annotation based on a parameter list in the target method; Determine a corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and store the target enterprise type in a target context; The target context is the context information passed during the remote procedure call; Running the written target load balancing strategy through a preset service provision mechanism, and obtaining the target enterprise type from the target context using the target load balancing strategy; A corresponding target service calling address is determined based on the target enterprise type, so as to call a corresponding enterprise service through the target service calling address.
2. The service calling method according to claim 1, characterized in that: The method of obtaining the target method in the enterprise service request by using the preset AOP interceptor includes: Use the preset AOP interceptor to obtain enterprise service requests; Obtain a target method that meets a preset request condition in an enterprise service request, and perform a surround process on the target method.
3. The service calling method according to claim 1, characterized in that: The 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 corresponding to the parameter in the parameter list is a numeric type and is annotated with a preset enterprise number, the parameter value corresponding to the parameter is converted to an integer type to obtain the enterprise number; If the data type corresponding to the parameter in the parameter list is a non-numeric type and is annotated with the preset enterprise number, the annotation value corresponding to the parameter is used as the target expression, the target attribute value annotated with the preset enterprise number 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 corresponding to the parameter in the parameter list is an object type and is not annotated by the enterprise number, each attribute in the parameter is traversed, and a corresponding recursive operation is performed based on the traversal result to obtain the enterprise number.
4. The service calling method according to any one of claims 1 to 3, characterized in that: The 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 there is a target enterprise type corresponding to the enterprise number in the local cache; If the target enterprise type corresponding to the enterprise number exists in the local cache, obtaining 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, the corresponding enterprise service portrait is called using the enterprise number, and the corresponding target enterprise type is obtained from the enterprise service portrait, and the target enterprise type is stored 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.
5. The service calling method according to claim 4, characterized in that: Before running the written target load balancing strategy through the preset service provision mechanism, the method further includes: Create a target large enterprise service address list, a target small enterprise service address list, and an available service address list to obtain a corresponding target load balancing strategy; Among them, 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.
6. The service calling method according to claim 5, characterized in that: The determining of the corresponding target service calling address based on the target enterprise type includes: If the target enterprise type is empty or meets the preset enterprise type condition, 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, the target large enterprise service address list is used as the target service calling address list; If the target enterprise type is a preset small enterprise type, the target small enterprise service address list is used as the target service calling address list; Determine a target service calling address based on an intersection of the target service calling address list and the available service address list; Among them, the preset enterprise type condition is that the enterprise type is consistent with the preset target type, and the preset target type is the enterprise type other than the preset large enterprise type and the preset small enterprise type.
7. The service calling method according to claim 6, characterized in that: The determining the target service calling address based on the intersection of the target service calling 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, any service call address 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, any one of the service call addresses in the intersection is determined as the target service call address.
8. A service calling device, characterized in that: include: An enterprise number determination module, used to obtain a target method in an enterprise service request using a preset AOP interceptor, and determine an enterprise number corresponding to a preset enterprise number annotation based on a parameter list in the target method; A target type determination module, used to determine a corresponding target enterprise type based on the enterprise number and a preset enterprise service tool, and store the target enterprise type in a target context; The target context is the context information passed during the remote procedure call; A load balancing module, used to run the programmed target load balancing strategy through a preset service provision mechanism, and obtain the target enterprise type from the target context using the target load balancing strategy; The service address calling module is used to determine the corresponding target service calling address based on the target enterprise type, so as to call the corresponding enterprise service through the target service calling address.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the service calling method according to any one of claims 1 to 7.
10. 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 calling method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Load balancing system for remote service calling based on real-time load rate
CN106453125A
Service invocation method, device and system
CN109542641A
Server allocation method and device, electronic equipment and computer readable storage medium
CN118200321A
Request processing method and device and electronic equipment
CN118450009A
Methods, systems and computer program products for integrating carrier services into an enterprise
EP1808804A1