Service calling method and device
Process multiple service call requests through a set of interfaces in RPC technology, use method parameters and object parameters to determine the executor and input parameters, scan the path to obtain the request type, and deserialize the object parameters, which solves the problem of interface correspondence in the existing technology. It solves the problem of high development and maintenance costs, achieves stability and security, and simplifies the development process.
Patent Information
- Application Number
- CN202410758931.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-10
AI Technical Summary
In existing RPC technology, the calling interface and the response interface correspond one-to-one, resulting in each remote service having separate business logic, which increases development and maintenance costs. It also needs to be deployed separately during updates, consuming manpower and material resources, and the update efficiency is low.
Process multiple service call requests through a set of interfaces, use method parameters and object parameters to determine the method executor and method input parameters, scan the path to quickly obtain the request type, deserialize the object parameters, generate the request class name according to the encoding rules, and simplify the number of interfaces , reduce development and maintenance costs.
It realizes processing of multiple service invocation requests through a set of interfaces, reduces development and maintenance costs, ensures the stability and security of the service invocation process, simplifies the development and maintenance process, and improves the conversion efficiency and flexibility of request class names. , avoiding the problem of too many interfaces.
Smart Images

Figure CN118626290A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for service invocation. Background Art
[0002] It is very common to use RPC (Remote Procedure Call) technology to call remote services. For example, multiple microservices call each other through RPC technology. The service call end and the service execution end using RPC technology need to define corresponding interfaces. Each call interface on the service call end corresponds to a response interface on the service execution end. As the number of remote services continues to increase, more and more interfaces are defined. Different call interfaces are used to send different service call requests, and different response interfaces are used to execute different business logic.
[0003] In the process of implementing the present invention, the inventors found that the prior art has at least the following problems:
[0004] Since the calling interface corresponds one-to-one with the response interface, each remote service has separate business logic, which increases development and maintenance costs. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and apparatus for service invocation, which can process multiple service invocation requests through a set of interfaces, thereby reducing development costs and maintenance costs.
[0006] To achieve the above object, according to a first aspect of an embodiment of the present invention, a service invocation method is provided, comprising:
[0007] In response to receiving the service call request, obtaining method parameters and object parameters corresponding to the service call request;
[0008] Get the method executor according to the method parameters;
[0009] Get the method entry object according to the object parameter, and use the method entry object as the method input parameter of the method executor;
[0010] Executes the method executor in response to the service call request.
[0011] Optionally, obtain the method executor according to the method parameters, including:
[0012] Convert method parameters to request class names;
[0013] Determine whether the request class name meets the conversion conditions;
[0014] If the request class name meets the conversion conditions, the request class name is converted into an executor name, and the method executor is obtained according to the executor name.
[0015] Optionally, determine whether the request class name meets the conversion conditions, including:
[0016] Scan the class packages under the preset scanning path to obtain the request type set;
[0017] When the request class name belongs to the request type set, it is determined that the request class name meets the conversion condition.
[0018] Optionally, the method entry object is obtained according to the object parameter, including:
[0019] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0020] Deserialize the object parameter into the parent class object of the request object;
[0021] The request object is assigned a value using the parent class object, and the assigned request object is used as the method entry object.
[0022] Optionally, the method entry object is obtained according to the object parameter, including:
[0023] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0024] The object parameters are deserialized using the request object to obtain the method entry object.
[0025] Optionally, convert method arguments to request class names, including:
[0026] Convert method parameters into target strings according to pre-set encoding rules;
[0027] Concatenate the target string with the preset request string to get the request class name.
[0028] Optionally, the service call request is initiated by the service call end and received by the service execution end; the method of the embodiment of the present invention further includes:
[0029] In response to the service execution end being restarted, the processing logic of the service call request is updated.
[0030] According to a second aspect of an embodiment of the present invention, a device for service invocation is provided, including:
[0031] The parsing module is used to obtain method parameters and object parameters corresponding to the service call request in response to receiving the service call request;
[0032] A first acquisition module, used for acquiring a method executor according to method parameters;
[0033] The second acquisition module is used to acquire the method entry object according to the object parameter, and use the method entry object as the method input parameter of the method executor;
[0034] The execution module is used to execute the method executor in response to the service call request.
[0035] Optionally, obtain the method executor according to the method parameters, including:
[0036] Convert method parameters to request class names;
[0037] Determine whether the request class name meets the conversion conditions;
[0038] If the request class name meets the conversion conditions, the request class name is converted into an executor name, and the corresponding method executor is obtained according to the executor name.
[0039] Optionally, determine whether the request class name meets the conversion conditions, including:
[0040] Scan the class packages under the preset scanning path to obtain the request type set;
[0041] When the request class name belongs to the request type set, it is determined that the request class name meets the conversion condition.
[0042] Optionally, the method entry object is obtained according to the object parameter, including:
[0043] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0044] Deserialize the object parameter into the parent class object of the request object;
[0045] The request object is assigned a value using the parent class object, and the assigned request object is used as the method entry object.
[0046] Optionally, the method entry object is obtained according to the object parameter, including:
[0047] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0048] Use the request object to deserialize the object parameters to obtain the method entry object.
[0049] Optionally, convert method arguments to request class names, including:
[0050] Convert method parameters into target strings according to pre-set encoding rules;
[0051] Concatenate the target string with the preset request string to get the request class name.
[0052] Optionally, the service call request is initiated by the service call end and received by the service execution end; the device of the embodiment of the present invention further includes:
[0053] The update module is used to update the processing logic of the service call request in response to the restart of the service execution end.
[0054] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, including:
[0055] one or more processors;
[0056] a storage device for storing one or more programs,
[0057] When one or more programs are executed by one or more processors, the one or more processors implement the method of any of the above embodiments.
[0058] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method of any of the above embodiments is implemented.
[0059] According to a fifth aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and the computer program implements the method of any of the above embodiments when executed by a processor.
[0060] An embodiment of the above invention has the following advantages or beneficial effects: determining the method executor and method input parameters of the service call request according to the method parameters and the object parameters, multiple service call ends send service call requests to the service execution end through a call interface, and the service execution end receives the service call request sent by the service call end through a response interface, and can process multiple service call requests through a set of interfaces, thereby reducing development costs and maintenance costs; obtaining the corresponding method executor when the request class name meets the conversion conditions, and being able to determine whether the service call request is within the request range, filtering out the service call requests that cannot be processed, and ensuring the stability and security of the service call process; determining the corresponding request type set according to the scanning path, and being able to quickly obtain the request type, and improving the efficiency of determining the request class name; converting the object parameter into the method entry object by deserialization, and being able to ensure the integrity of the method entry object, and converting the object parameter into other types of objects; obtaining the request class name according to the encoding rules and splicing rules, and being able to improve the conversion efficiency and flexibility of the request class name, and avoiding duplication of the request class name; after restarting the service execution end, updating the corresponding processing logic, and being able to avoid modifying the service call end, simplifying the development process and maintenance process, and reducing the development cost and maintenance cost.
[0061] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0063] Figure 1 is a schematic diagram of the main process of the service calling method according to an embodiment of the present invention;
[0064] Figure 2 is a schematic diagram of request type scanning of a service invocation method according to a reference embodiment of the present invention;
[0065] Figure 3 is a schematic diagram of a service call according to a method for service call in a reference embodiment of the present invention;
[0066] Figure 4 It is a schematic diagram of the overall process of a service calling method according to a reference embodiment of the present invention;
[0067] Figure 5 It is a schematic diagram of the main process of a service calling method according to a reference embodiment of the present invention;
[0068] Figure 6 is a schematic diagram of the main process of a service calling method according to another reference embodiment of the present invention;
[0069] Figure 7 is a schematic diagram of the main process of a method for service invocation according to yet another reference embodiment of the present invention;
[0070] Figure 8 is a schematic diagram of main modules of a device for service invocation according to an embodiment of the present invention;
[0071] Fig. 9 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0072] Fig.10 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0073] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0074] It should be noted that in the technical solution of the present invention, the collection, use, storage, sharing and transfer of user personal information involved are in compliance with the provisions of relevant laws and regulations, and it is necessary to inform the user and obtain the user's consent or authorization. When applicable, the user's personal information is de-identified and / or anonymized and / or encrypted.
[0075] It is very common to use RPC (Remote Procedure Call) technology to call remote services. For example, multiple microservices call each other through RPC technology. The service call end and the service execution end using RPC technology need to define corresponding interfaces. Each call interface on the service call end corresponds to a response interface on the service execution end. As the number of remote services continues to increase, more and more interfaces are defined. Different call interfaces are used to send different service call requests, and different response interfaces are used to execute different business logic.
[0076] Since the calling interface corresponds one-to-one with the response interface, each remote service has a separate business logic, which increases development and maintenance costs. After the update, it also needs to be deployed separately on the service calling end and the service execution end, which consumes manpower and material resources and has low update efficiency.
[0077] In view of this, according to a first aspect of an embodiment of the present invention, a service calling method is provided.
[0078] Figure 1 FIG. 1 is a schematic diagram of the main process of the service invocation method according to an embodiment of the present invention. Figure 1 As shown, the service calling method according to the embodiment of the present invention mainly includes the following steps S101 to S104.
[0079] Step S101, in response to receiving a service call request, obtaining method parameters and object parameters corresponding to the service call request.
[0080] The execution subject of the embodiment of the present invention parses the received service call request to obtain method parameters and object parameters. Method parameters are parameters used to determine the execution method of the service call request, and object parameters are parameters used to determine the input parameters required for the execution method. Specifically, method parameters are strings or collections containing strings, and the data type of object parameters is a data type that can represent all data. For example, the data type of object parameters is java.lang.Object in the Java language or a structured string JSONString, etc., wherein the object parameter of the Object data type is converted into objects of different data types through dynamic binding, and the object parameter as a structured string is converted into objects of different data types through an open source class package or a custom method.
[0081] The execution subject of the embodiment of the present invention provides a variety of services, such as document query service, logistics distribution service, inventory update service, etc. One interface is used to receive different service call requests, each service call request carries method parameters and object parameters, and different service call requests are distinguished and different service processing logics are determined through the method parameters and object parameters.
[0082] Exemplarily, the interface " / RpcRequest" is used to receive the service call request " / RpcRequest?methodPara=A1&dataParam=A2", and the received service call request is parsed to obtain the method parameter of the service call request as A1 and the object parameter as A2. In another exemplary embodiment, the parameter carried by the service call request is the request object request, and the method parameter is obtained by the method request.getParameter("method"), and the object parameter is obtained by the method request.getParameter("data").
[0083] Only one interface is set up, and different service call requests are distinguished by method parameters and object parameters. This can significantly reduce the number of interfaces, avoid setting up too many interfaces, reduce development costs and operation and maintenance costs, and facilitate the management of service call requests.
[0084] Step S102, obtaining a method executor according to method parameters.
[0085] The method executor is a specific method for processing a service call request. Multiple method executors are pre-set, and different method executors process different service call requests. After obtaining the method parameters, the method parameters are parsed to determine the corresponding method executor. For example, the obtained method parameters include a first method parameter and a second method parameter. The class package path where the method executor is located is determined according to the first method parameter. The corresponding method execution object is generated according to the class package path. The second method parameter is used as the method name, and the method executor corresponding to the second method parameter is searched in the multiple methods included in the method execution object. For another example, according to the pre-set mapping rules, the class package path and method name corresponding to the method parameter are searched, the corresponding method execution object is generated according to the mapped class package path, and the method executor included in the method execution object is determined according to the mapped method name.
[0086] Exemplarily, the method parameters include a first method parameter "B1.B2.B3" and a second method parameter "B4", wherein the first method parameter indicates that the class package path where the method executor is located is class package B1, class package B2 under class package B1, and class package B3 under class package B2, and the method getBean("B1.B2.B3") is used to generate a method execution object; the second method parameter is concatenated with the preset string "Service" to obtain the executor name "B4Service", and according to the preset judgment statement, the method executor corresponding to the executor name "B4Service" is searched. If not found, a prompt message is returned to prompt the initiator of the service call request "The called service does not exist, please resend the service call request."
[0087] The method executor can be quickly determined through method parameters, and different method parameters can be flexibly associated with corresponding method executors, so as to improve the response efficiency of service calls.
[0088] According to a reference embodiment of the present invention, when obtaining a method executor according to a method parameter, the method parameter is converted into a request class name, which is the name of the class in which the method executor is located. For example, the method parameter is directly used as the request class name, or the request class name corresponding to the method parameter is determined according to a pre-set mapping rule. It is judged whether the request class name meets the conversion conditions, for example, whether the request class name exists in a pre-set configuration file. If the configuration file includes the request class name, it is determined that the request class name meets the conversion conditions, or the request class name is compared with a pre-set general class name to determine whether the request class name meets the naming rules of the general class name. If the request class name meets the naming rules, it is determined that the request class name meets the conversion conditions.
[0089] If the request class name meets the conversion conditions, the request class name is converted into an executor name, for example, the executor name corresponding to the request class name is searched in a preset mapping relationship, or characters are added or subtracted based on the request class name to obtain the executor name. The corresponding method execution object is generated according to the request class name, and the method executor corresponding to the method execution object is obtained according to the executor name.
[0090] Exemplarily, the method parameters C1.C2.C5 are directly used as the request class name, and the preset general class name is "C*.C*.C*", which means that each class package of the request class name starts with the letter C. The request class name is determined to comply with the naming rules of the general class name through comparison, and the request class name is determined to comply with the conversion conditions. The preset mapping relationship "{'C1.C2.C3':'D1'; 'C1.C2.C4':'D2'; 'C1.C2.C5':'D3'}" is obtained to determine that the method executor corresponding to the request class name is D4, and the corresponding method execution object is generated by the request class name, and the method execution object is used to call the method executor to execute the corresponding processing logic.
[0091] By judging whether the request class name meets the conversion conditions, most of the service call requests that cannot be processed can be filtered out as early as possible, saving system resources and improving the response efficiency of service calls.
[0092] According to a reference embodiment of the present invention, when judging whether the request class name meets the conversion conditions, the pre-set scan path is scanned to determine all the class packages included in the scan path, and the fully qualified name of each class package is used as the request type. The request type represents the request type of the service call request that the execution subject of the embodiment of the present invention can handle, and a request type set is obtained. The request type set includes all request types under the scan path. The request type set is traversed to determine whether the request type set includes the same request type as the request class name. When there is a request type with the same request class name, it means that the execution subject of the embodiment of the present invention can handle the corresponding service call request, so it is determined that the request class name meets the conversion conditions. The scan path is modifiable, and the class packages under the scan path can be added, deleted or modified. When adding, deleting or modifying the scan class packages, there is no need to modify the interface that accepts the service call request.
[0093] Figure 2 Schematic diagram of request type scanning of a service call method according to a reference embodiment of the present invention. Exemplarily, before receiving a service call request, the developer first configures a base class or interface of the request type, and multiple specific request types that inherit the base class or implement the interface, and places the multiple request types under the same path or multiple sub-paths of the same path; Figure 2 As shown, when judging whether the request class name meets the conversion conditions, obtain the preset scan path; scan the class package name under each scan path to obtain multiple request types; judge whether the request type is a base class or an interface, if the request type is a base class or an interface, ignore the request type; if the request type is not a base class or an interface, add the request type to the request type set, and when the request class name is the same as the request type in the request type set, judge that the request class name meets the conversion conditions.
[0094] By scanning the path, the request type is quickly and accurately obtained, and the request type is used to judge the request class name, so as to effectively identify the service call requests that can be processed, improve the processing efficiency of service call requests, avoid further processing of services outside the request type, and save system resources.
[0095] According to a reference embodiment of the present invention, when converting method parameters into request class names, the method parameters are converted into target strings according to preset encoding rules. For example, the method parameters are mapped according to their specific contents, and the business field corresponding to the service call request is determined according to the first digit of the method parameters. Specifically, the number "1" represents the logistics field, the number "2" represents the online shopping field, the number "3" represents the financial field, and so on. Method parameters in different business fields are converted into different target strings. For another example, characters in odd or even positions in the method parameters are obtained to form a target string. For another example, the method parameters are reversed to obtain the corresponding target string.
[0096] After obtaining the target string, the target string is concatenated with the preset request string to obtain the request class name. For example, the preset request string is used as a prefix of the target string and added to the beginning of the target string, or the preset request string is used as a suffix of the target string and added to the end of the target string.
[0097] Exemplarily, the received method parameter is "asdfgh", and the preset encoding rule is "reverse the method parameter", then the method parameter "asdfgh" is reversed into the target string "hgfdsa"; the preset request string "Request" is obtained, the request string is used as the suffix of the target string and concatenated to the end of the target string to obtain the request class name "hgfdsaRequest".
[0098] By setting encoding rules and request strings, different request class names can be flexibly generated to avoid using the same request class name for multiple method parameters, thereby improving the efficiency and flexibility of obtaining the request class name.
[0099] Step S103, obtaining the method entry object according to the object parameters, and using the method entry object as the method input parameter of the method executor.
[0100] The method entry object is the method input parameter required when executing the method executor. The data type of the method entry object can be a string, a number, a reference object, or a combination of the above data types. After obtaining the object parameter, convert the object parameter to the method entry object. For example, the object parameter is an object with a data type of java.lang.Object, and the data type of the method input parameter required by the method executor is "TypeE". After determining the object parameter E1, use the statement "TypeE E2 = (TypeE) E1;" to force the object parameter E1 to be converted to the method entry object E2 with a data type of "TypeE". For another example, the object parameter is a JSONString string, and an open source class package (for example, JSONObject, Gson, etc.) is used to convert the object parameter to a method entry object.
[0101] By converting object parameters into method entry objects, the method input parameters of the method executor can be quickly obtained, which is convenient for improving the response efficiency of service calls.
[0102] According to a reference embodiment of the present invention, when obtaining a method entry object according to an object parameter, if the object parameter is a JSONString string, first determine whether the request class name meets the conversion conditions. If the request class name meets the conversion conditions, determine the corresponding fully qualified class name according to the request class name, and initialize the request object according to the fully qualified class name. Deserialize the object parameter into the parent class object of the request object; the request object includes all the properties of the parent class object, so the parent class object is used to assign values to the properties of the request object, and the assigned request object is used as the method entry object.
[0103] For example, the JSONString string is first deserialized into the parent class object obj of the Object class, and then the corresponding request object req is generated according to the request class name, and then the attribute values in the parent class object obj are assigned to the request object req. Through deserialization, the attribute values in the JSONString string are accurately converted to the parent class object of the request object, and then the method entry object is obtained, so that the method entry object has all the attributes of the JSONString string, which is convenient for the subsequent accurate execution of the method executor.
[0104] According to a reference embodiment of the present invention, when obtaining a method entry object based on an object parameter, when the object parameter is a JSONString string, first determine whether the request class name meets the conversion conditions; when the request class name meets the conversion conditions, obtain the corresponding request object based on the request class name; use the request object to deserialize the object parameter to obtain a method entry object, wherein the method entry object has a serial number corresponding to the JSONString string, so that the JSONString string is just deserialized into the data type of the method entry object.
[0105] Exemplarily, the request class name is "F1.F2.F3", the method "getBean("F1.F2.F3")" is used to obtain the request object req1, the method "getClass()" is used to obtain the data type of the request object req1, and the data type is "F3", and the method "F3 req2 = (F3) new ObjectInputStream(new fileInputStream(JSONString)).readObject()" is used to deserialize the object parameter (ie, JSONString string) into a method entry object.
[0106] Through deserialization, the attribute values in the JSONString string are accurately converted to the method entry object, so that the method entry object has all the attributes of the JSONString string, which facilitates the subsequent accurate execution of the method executor.
[0107] Step S104, executing the method executor to respond to the service call request.
[0108] When the method executor and the method entry object required by the method executor are determined, the method entry object is used as the method input parameter of the method executor, and the business logic of the method executor is executed to call the corresponding service, and the return result of the method executor is returned to the initiator of the service call request as the response result of the service call request.
[0109] Exemplarily, after the method executor completes execution, the response result of the method executor is packaged to obtain "{'code':'200'; 'state':'success'; 'result':'returnValue'}", wherein "'code':'200'" indicates that the status code is normal, "'state':'success'" indicates that the service call request is successful, and "'result':'returnValue'" indicates that the return result of the service call request is "returnValue"; the above-packaged response result is returned to the initiator of the service call request, so that the initiator of the service call request can quickly and accurately understand the response result of the service call request.
[0110] According to a reference embodiment of the present invention, a service call request is initiated by a service calling end and received by a service execution end. The execution subject of the embodiment of the present invention runs on the service execution end. One service execution end can receive service call requests sent by multiple service calling ends. The service calling end and the service execution end are two terminals that need to communicate with each other through RPC technology. The service calling end and the service execution end have a set of interfaces. The service calling end calls different services provided by the service execution end by sending service call requests with different method parameters and object parameters to the service execution end.
[0111] The method also includes: the R&D personnel modify the service execution end, for example, adding or deleting the data type of the request type, method executor, method entry object, or modifying the data type of the existing request type, method executor, method entry object; after the R&D personnel modify the service execution end, the service execution end is redeployed, and the execution subject of the embodiment of the present invention responds to the restart of the service execution end, scans the pre-set initialization path, and registers the various modified request types and method executors, so that when a service call request is received, the updated processing logic is used to respond to the service call request.
[0112] Figure 3 FIG. 1 is a schematic diagram of a service call according to a method for service call of a reference embodiment of the present invention. Figure 3 As shown, the service calling end sends a service calling request to the service executing end through a calling interface, and each service calling request carries method parameters and object parameters; the service executing end receives the service calling request sent by the service calling end through a response interface, determines the corresponding method executor according to the method parameters carried in the service calling request, determines the corresponding method entry object according to the object parameters carried in the service calling request, and then uses the method entry parameters as the method input parameters of the object's method executor, executes the method executor, and returns the generated response result to the service calling end.
[0113] Setting only one set of interfaces on the service call end and the service execution end can significantly reduce the number of interfaces, lowering development costs and operation and maintenance costs. When updating the interface, only the business logic of the service execution end is updated, without the need to update and deploy the service call end. This can simplify the deployment process and further reduce development costs and operation and maintenance costs.
[0114] Figure 4 FIG. 1 is a schematic diagram of the overall process of a service invocation method according to a reference embodiment of the present invention. Figure 4 As shown, when responding to a service call request, the service call request is parsed to obtain the method parameters and object parameters corresponding to the service call request; the method parameters are converted into a request class name, and it is determined whether the request class name meets the conversion conditions. If the request class name does not meet the conversion conditions, a prompt message is generated, indicating that the service cannot be called and a response result cannot be returned; if the request class name meets the conversion conditions, the request class name is converted into an executor name, and the corresponding method executor is obtained according to the executor name; the object parameters are deserialized using the request object, and if an exception is captured, it is determined that the deserialization fails, and a prompt message is generated, indicating that the service cannot be called and a response result cannot be returned; if no exception is captured, it is determined that the deserialization is successful, and a method entry object is obtained, and the method executor with the method entry object as the method input parameter is executed, and the response result is returned to the initiator of the service call request.
[0115] Figure 5 FIG. 1 is a schematic diagram of the main process of a service invocation method according to a reference embodiment of the present invention. Figure 5 As shown, the service calling method may include:
[0116] Step S501, in response to receiving a service call request, obtaining method parameters and object parameters corresponding to the service call request;
[0117] Step S502, converting the method parameters into a request class name;
[0118] Step S503, determine whether the request class name meets the conversion conditions, if yes, jump to step S504, otherwise, jump to step S508;
[0119] Step S504, convert the request class name into an executor name, and obtain the corresponding method executor according to the executor name;
[0120] Step S505, obtaining the corresponding request object according to the request class name that meets the conversion condition, and deserializing the object parameter into the parent class object of the request object;
[0121] Step S506, using the parent class object to assign a value to the request object, and using the assigned request object as the method entry object;
[0122] Step S507, executing the method executor to respond to the service call request;
[0123] Step S508: Return a prompt message, indicating that the service call request cannot be processed.
[0124] The specific implementation content of the service calling method of the above-mentioned reference embodiment of the present invention has been described in detail in the above service calling method, so the repeated content will not be described again here.
[0125] Figure 6 FIG. 1 is a schematic diagram of the main process of a method for service invocation according to another reference embodiment of the present invention. Figure 6 As shown, the service calling method may include:
[0126] Step S601, in response to receiving a service call request, obtaining method parameters and object parameters corresponding to the service call request;
[0127] Step S602, converting the method parameters into a request class name;
[0128] Step S603, according to the preset scanning path, scanning the class packages under the scanning path to obtain the request type set;
[0129] Step S604, determine whether the request class name belongs to the request type set, if yes, jump to step S605, otherwise, jump to step S609;
[0130] Step S605, convert the request class name into an executor name, and obtain the corresponding method executor according to the executor name;
[0131] Step S606, obtaining a corresponding request object according to the request class name that meets the conversion condition;
[0132] Step S607, deserialize the object parameters using the request object to obtain the method entry object;
[0133] Step S608, executing the method executor to respond to the service call request;
[0134] Step S609: Return a prompt message, indicating that the service call request cannot be processed.
[0135] The specific implementation content of the service calling method of another reference embodiment of the present invention has been described in detail in the above service calling method, so the repeated content will not be described here.
[0136] Figure 7 FIG. 1 is a schematic diagram of the main process of a method for service invocation according to another reference embodiment of the present invention. Figure 7 As shown, the service calling method may include:
[0137] Step S701, receiving a service call request sent by a service call end at a service execution end, and obtaining corresponding method parameters and object parameters;
[0138] Step S702, converting the method parameter into a target string according to a preset encoding rule;
[0139] Step S703, concatenate the target string with the preset request string to obtain a request class name;
[0140] Step S704, scanning the class packages under the preset scanning path to obtain a request type set;
[0141] Step S705, determine whether the request class name belongs to the request type set, if yes, jump to step S706, otherwise, jump to step S711;
[0142] Step S706, convert the request class name into an executor name, and obtain the corresponding method executor according to the executor name;
[0143] Step S707, obtaining the corresponding request object according to the request class name that meets the conversion condition;
[0144] Step S708, deserialize the object parameters using the request object to obtain the method entry object;
[0145] Step S709, executing the method executor to respond to the service call request;
[0146] Step S710, in response to the service execution end restarting, updating the processing logic of the service call request;
[0147] Step S711, returning a prompt message, indicating that the service call request cannot be processed.
[0148] The specific implementation content of the service calling method of another reference embodiment of the present invention has been described in detail in the above service calling method, so the repeated content will not be described here.
[0149] According to a second aspect of an embodiment of the present invention, a device for service invocation is provided.
[0150] Figure 8 is a schematic diagram of the main modules of the device for service invocation according to an embodiment of the present invention, such as Figure 8 As shown, the service calling device 800 mainly includes:
[0151] The parsing module 801 is used to obtain method parameters and object parameters corresponding to the service call request in response to receiving the service call request;
[0152] A first acquisition module 802, used to acquire a method executor according to method parameters;
[0153] The second acquisition module 803 is used to acquire the method entry object according to the object parameter, and use the method entry object as the method input parameter of the method executor;
[0154] The execution module 804 is used to execute the method executor to respond to the service call request.
[0155] According to a reference embodiment of the present invention, obtaining a method executor according to a method parameter includes:
[0156] Convert method parameters to request class names;
[0157] Determine whether the request class name meets the conversion conditions;
[0158] If the request class name meets the conversion conditions, the request class name is converted into an executor name, and the corresponding method executor is obtained according to the executor name.
[0159] According to another reference embodiment of the present invention, determining whether the request class name meets the conversion condition includes:
[0160] Scan the class packages under the preset scanning path to obtain the request type set;
[0161] When the request class name belongs to the request type set, it is determined that the request class name meets the conversion condition.
[0162] According to another reference embodiment of the present invention, obtaining a method entry object according to an object parameter includes:
[0163] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0164] Deserialize the object parameter into the parent class object of the request object;
[0165] Use the parent class object to assign a value to the request object, and use the assigned request object as the method entry object.
[0166] According to another reference embodiment of the present invention, obtaining a method entry object according to an object parameter includes:
[0167] Get the corresponding request object according to the request class name that meets the conversion conditions;
[0168] Use the request object to deserialize the object parameters to obtain the method entry object.
[0169] According to another reference embodiment of the present invention, converting a method parameter into a request class name includes:
[0170] Convert method parameters into target strings according to pre-set encoding rules;
[0171] Concatenate the target string with the preset request string to get the request class name.
[0172] According to a reference embodiment of the present invention, the service call request is initiated by the service call end and received by the service execution end; the service call device 800 also includes:
[0173] The update module is used to update the processing logic of the service call request in response to the restart of the service execution end.
[0174] It should be noted that the specific implementation content of the service calling device in the embodiment of the present invention has been described in detail in the above service calling method, so the repeated content will not be described again here.
[0175] According to the technical solution of the embodiment of the present invention, the method executor and method input parameters of the service call request are determined according to the method parameters and the object parameters, and multiple service call requests can be processed through a set of interfaces, thereby reducing development costs and maintenance costs; when the request class name meets the conversion conditions, the corresponding method executor is obtained, and it can be determined that the service call request is within the request range, and the service call requests that cannot be processed are filtered out, thereby ensuring the stability and security of the service call process; the corresponding request type set is determined according to the scanning path, and the request type can be quickly obtained, thereby improving the efficiency of determining the request class name; the object parameters are converted into the method entry object by deserialization, and the integrity of the method entry object can be guaranteed, and the object parameters can be converted into other types of objects; the request class name is obtained according to the encoding rules and splicing rules, and the conversion efficiency and flexibility of the request class name can be improved, and the duplication of the request class name can be avoided; after restarting the service execution end, the corresponding processing logic is updated, and the modification of the service call end can be avoided, the development process and maintenance process are simplified, and the development cost and maintenance cost are reduced.
[0176] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for service calling, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement the method provided by the first aspect of the embodiment of the present invention.
[0177] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0178] According to a fifth aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0179] Fig. 9 An exemplary system architecture 900 is shown to which the method for service invocation or the apparatus for service invocation according to an embodiment of the present invention can be applied.
[0180] like Fig. 9 As shown, system architecture 900 may include terminal devices 901, 902, 903, network 904 and server 905. Network 904 is used to provide a medium for communication links between terminal devices 901, 902, 903 and server 905. Network 904 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0181] The user can use the terminal devices 901, 902, 903 to interact with the server 905 through the network 904 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 901, 902, 903, such as: service call applications, service execution applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0182] The terminal devices 901 , 902 , and 903 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0183] The server 905 may be a server that provides various services, such as a background management server (only an example) that provides support for the service call request sent by the upstream terminal devices 901, 902, and 903. In response to receiving the service call request, the background management server may obtain the method parameters and object parameters corresponding to the service call request; obtain the method executor according to the method parameters; obtain the method entry object according to the object parameters, and use the method entry object as the method input parameter of the method executor; execute the method executor to respond to the service call request; and feedback the service call situation (only an example) to the terminal device.
[0184] It should be noted that the service calling method provided in the embodiment of the present invention is generally executed by the server 905, and accordingly, the service calling device is generally set in the server 905. The service calling method provided in the embodiment of the present invention can also be executed by the terminal devices 901, 902, and 903, and accordingly, the service calling device can be set in the terminal devices 901, 902, and 903.
[0185] It should be understood that Fig. 9 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0186] Reference below Fig.10 , which shows a schematic diagram of the structure of a computer system 1000 of a terminal device suitable for implementing an embodiment of the present invention. Fig.10 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0187] like Fig.10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage part 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the system 1000 are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0188] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0189] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1009, and / or installed from the removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the above-mentioned functions defined in the system of the embodiment of the present invention are executed.
[0190] It should be noted that the computer-readable medium shown in the embodiment of the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In an embodiment of the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0191] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0192] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a parsing module, a first acquisition module, a second acquisition module, and an execution module, wherein the names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the parsing module may also be described as a "module for acquiring method parameters and object parameters".
[0193] As another aspect, an embodiment of the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: in response to receiving a service call request, obtain method parameters and object parameters corresponding to the service call request; obtain a method executor according to the method parameters; obtain a method entry object according to the object parameters, and use the method entry object as a method input parameter of the method executor; execute the method executor to respond to the service call request.
[0194] According to the technical solution of the embodiment of the present invention, the method executor and method input parameters of the service call request are determined according to the method parameters and the object parameters, and multiple service call requests can be processed through a set of interfaces, thereby reducing development costs and maintenance costs; when the request class name meets the conversion conditions, the corresponding method executor is obtained, and it can be determined that the service call request is within the request range, and the service call requests that cannot be processed are filtered out, thereby ensuring the stability and security of the service call process; the corresponding request type set is determined according to the scanning path, and the request type can be quickly obtained, thereby improving the efficiency of determining the request class name; the object parameters are converted into the method entry object by deserialization, and the integrity of the method entry object can be guaranteed, and the object parameters can be converted into other types of objects; the request class name is obtained according to the encoding rules and splicing rules, and the conversion efficiency and flexibility of the request class name can be improved, and the duplication of the request class name can be avoided; after restarting the service execution end, the corresponding processing logic is updated, and the modification of the service call end can be avoided, the development process and maintenance process are simplified, and the development cost and maintenance cost are reduced.
[0195] The above specific implementations do not constitute a limitation on the protection scope of the embodiments of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the embodiments of the present invention should be included in the protection scope of the embodiments of the present invention.
Claims
1. A method for service invocation, characterized in that: include: In response to receiving the service call request, obtaining method parameters and object parameters corresponding to the service call request; Obtaining a method executor according to the method parameters; Acquire a method entry object according to the object parameter, and use the method entry object as a method input parameter of the method executor; The method executor is executed to respond to the service call request.
2. The method according to claim 1, characterized in that Acquiring a method executor according to the method parameters includes: Convert the method parameter to a request class name; Determine whether the request class name meets the conversion conditions; When the request class name meets the conversion condition, the request class name is converted into an executor name, and the method executor is obtained according to the executor name.
3. The method according to claim 2, characterized in that Determining whether the request class name meets the conversion condition includes: Scan the class packages under the preset scanning path to obtain the request type set; In the case that the request class name belongs to the request type set, it is determined that the request class name meets the conversion condition.
4. The method according to claim 2, characterized in that: Obtaining a method entry object according to the object parameter includes: Obtaining a corresponding request object according to the request class name that meets the conversion condition; Deserialize the object parameter into the parent class object of the request object; The parent class object is used to assign a value to the request object, and the assigned request object is used as the method entry object.
5. The method according to claim 2, characterized in that: Obtaining a method entry object according to the object parameter includes: Obtaining a corresponding request object according to the request class name that meets the conversion condition; The object parameters are deserialized using the request object to obtain the method entry object.
6. The method according to claim 2, characterized in that Convert the method parameters to a request class name, including: According to the preset encoding rules, the method parameters are converted into a target string; The target string is concatenated with a preset request string to obtain the request class name.
7. The method according to claim 1, characterized in that The service call request is initiated by the service call end and received by the service execution end; the method also includes: In response to the service execution end being restarted, the processing logic of the service call request is updated.
8. A device for service invocation, characterized in that: include: The parsing module is used to obtain method parameters and object parameters corresponding to the service call request in response to receiving the service call request; A first acquisition module, used for acquiring a method executor according to the method parameters; A second acquisition module is used to acquire a method entry object according to the object parameter, and use the method entry object as a method input parameter of the method executor; An execution module is used to execute the method executor to respond to the service call request.
9. An electronic device, characterized in that: include: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 7.
