Service request processing method, electronic equipment terminal and storage medium
By adding an interface address switching filtering mechanism to the Feign framework, the problem of business process interruption caused by the absence of interface addresses during remote calls by electronic device terminals is solved, improving user experience and development efficiency.
Patent Information
- Application Number
- CN202210173512.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-24
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2042-02-24
AI Technical Summary
When electronic device terminals complete remote calls based on the Feign framework, the remote interface fails to provide normal services or return corresponding data, causing business process interruption, reducing user experience and prolonging the project development cycle.
Before calling the interface remotely, change the execution order of Feign and add filtering to determine whether the interface address needs to be switched. If it does not belong to the target interface address, use the preset interface address to send the business request to ensure smooth data transmission.
It improves the user experience, avoids interruption of the execution process due to the non-existence of the remote calling interface address, and reduces the project development cycle.
Smart Images

Figure CN114650276B
Abstract
Description
[Technical field]
[0001] The embodiments of the present application relate to the field of intelligent terminal technology, and in particular to a service request processing method, an electronic device terminal, and a storage medium. [Background technology]
[0002] With the continuous development of device terminal technology, people can use electronic device terminals to process various business data. However, in the process of completing remote calls based on the Feign framework, there is a situation where the remote interface fails to provide normal services or return corresponding data. At this time, the electronic device terminal cannot receive feedback data, resulting in the inability to continue the remaining business processes, thereby reducing the user experience and lengthening the project cycle during project development. [Summary of the invention]
[0003] The embodiments of the present application provide a service request processing method, an electronic device terminal and a storage medium, so as to realize the improvement of user experience by changing the execution order of feign and adding filtering before remotely calling the interface to determine whether the interface address needs to be switched.
[0004] In the first aspect, an embodiment of the present application provides a service request processing method, which is applied to an electronic device terminal, and the method includes: obtaining a service request to be sent based on feign; determining a corresponding service request address according to the service request, and judging whether the service request address belongs to a target interface address; if the service request address does not belong to the target interface address, sending the service request according to a preset interface address.
[0005] In the above-mentioned business request processing method, by obtaining the business request to be sent based on feign, it is determined whether the business request address corresponding to the business request belongs to the target interface address. If the business request address does not belong to the target interface address, the business request is sent according to the preset interface address. Compared with the prior art, the present application changes the execution order of feign, adds filtering before the remote call interface to determine whether the interface address needs to be replaced, and returns the return information to the request source according to the return result after the feign request is completed, thereby ensuring that the electronic device terminal will not interrupt the execution process due to the non-existence of the remote call interface address, thereby improving user experience and avoiding the extension of the project cycle during project development.
[0006] In one implementation manner, the method further includes: if the service request address belongs to the target interface address, sending the service request according to the service request address.
[0007] In one embodiment, if the service request address does not belong to the target interface address, the process of sending the service request according to the preset interface address includes: obtaining the preset interface address from the cache; if the preset interface address is not empty, sending the service request according to the preset interface address; if the preset interface address is empty and has a configured preset address, writing the configured preset address to the cache as the preset interface address; if the preset interface address is empty and does not have a configured preset address, writing the service request address to the cache as the preset interface address.
[0008] In one implementation manner, the method further includes: receiving a preset interface address update instruction; and updating the preset interface address according to the preset interface address update instruction.
[0009] In one implementation manner, the preset interface address is a virtual service interface address.
[0010] In one implementation manner, before obtaining the feign-based business request to be sent, it also includes: obtaining the http-based business request to be sent; converting the http-based business request to be sent into the feign-based business request to be sent.
[0011] In the second aspect, an embodiment of the present application provides an electronic device terminal, which includes: a service request acquisition module, used to obtain a service request to be sent based on feign; a request address judgment module, used to determine the corresponding service request address according to the service request, and judge whether the service request address belongs to the target interface address; a preset interface address sending module, used to send the service request according to the preset interface address if the service request address does not belong to the target interface address.
[0012] In one implementation manner, the terminal further includes: a service request address sending module, configured to send the service request according to the service request address if the service request address belongs to the target interface address.
[0013] In one embodiment, the preset interface address sending module includes: a preset address acquisition submodule, used to obtain the preset interface address from the cache; a preset interface address sending first submodule, used to send the service request according to the preset interface address if the preset interface address is not empty; a preset interface address sending second submodule, used to write the configured preset address into the cache as the preset interface address if the preset interface address is empty and has a configured preset address; a preset interface address sending third submodule, used to write the service request address into the cache as the preset interface address if the preset interface address is empty and does not have a configured preset address.
[0014] In one implementation manner, the terminal further includes: an update instruction receiving module, configured to receive a preset interface address update instruction; and a preset interface update module, configured to update the preset interface address according to the preset interface address update instruction.
[0015] In one implementation manner, the terminal further includes: a second service request acquisition module, used to acquire the service request to be sent based on http; and a service request conversion module, used to convert the service request to be sent based on http into the service request to be sent based on feign.
[0016] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the above-mentioned business request processing method.
[0017] It should be understood that the second to third aspects of the embodiments of the present application are consistent with the technical solutions of the first aspect of the embodiments of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here.
Brief Description of the Drawings
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A flowchart of a method for processing a business request provided by an embodiment of the present application;
[0020] Figure 2 A flowchart of a method for processing a business request provided by an embodiment of the present application;
[0021] Figure 3A flowchart of a method for processing a business request provided by an embodiment of the present application;
[0022] Figure 4 A flowchart of a method for processing a business request provided by an embodiment of the present application;
[0023] Figure 5 A flowchart of a method for processing a business request provided by an embodiment of the present application;
[0024] Figure 6 A schematic diagram of the structure of an electronic device terminal provided by an embodiment of the present application;
[0025] Figure 7 A schematic diagram of the structure of an electronic device terminal provided by an embodiment of the present application;
[0026] Figure 8 A schematic diagram of the structure of an electronic device terminal provided by an embodiment of the present application;
[0027] Fig. 9 A schematic diagram of the structure of an electronic device terminal provided by one embodiment of the present application. [Specific implementation method]
[0028] In order to better understand the technical solution of this specification, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0029] It should be clear that the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0030] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit this specification. The singular forms "a", "a", "an" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0031] The service request processing method provided in the embodiment of the present application can be executed by an electronic device terminal, which can be a terminal device such as a smart phone, a tablet computer, a PC, a laptop, etc. In an optional embodiment, a service program for executing the service request processing method can be installed on the electronic device terminal.
[0032] The technical problems actually to be solved by the technical solutions provided in the embodiments of the present application are:
[0033] In the process of completing remote calls based on the Feign framework, there is a situation where the remote interface fails to provide normal services or return corresponding data. At this time, the electronic device terminal cannot receive feedback data, resulting in the inability to continue the remaining business processes, thereby reducing the user experience and lengthening the project cycle during project development.
[0034] Figure 1 A flow chart of a service request processing method provided by the present application is shown in the figure. The service request processing method may include the following steps:
[0035] Step S101, obtaining a feign-based service request to be sent.
[0036] Under the Feign framework, after the technicians in this field send a business request, they will template the business request through JAVA annotations. JAVA annotations, such as @FeignClient, are equivalent to a markup language, which allows electronic device terminals to dynamically operate members with this tag at runtime. When the actual call is made, the relevant parameters of the incoming business request are applied to the business request according to the parameters, and then converted into an HTTP request. Through Feign and JAVA's dynamic proxy mechanism, Java developers can complete HTTP calls to remote services without encapsulating HTTP request messages through the HTTP framework. When obtaining the target object from the Feign environment, the attributes in the target object will search for the id attribute value or class attribute value of the tag in the entire Feign environment according to the name. If there is the same, then the object is obtained to achieve the association.
[0037] Optionally, under the Feign framework, the Feign request interceptor can be used to obtain business requests. For example, the RequestInterceptor component is used to obtain business requests. The specific code can be: RequestInterceptormockFeignRequestInterceptor(){return new MockFeign-RequestInterceptor();}.
[0038] It should be noted that a business request is a request for calling a business interface. In the Feign environment, a business interface can be an interface service composed of multiple components. A business interface call request consists of two parts: a header and a body. The header is the request header, and the body is the request body. The request header contains parameters such as content-type. Feign request interceptor is a type of Spring interceptor. In the Feign environment, it can automatically obtain and judge business requests.
[0039] Step S102: determine the corresponding service request address according to the service request, and judge whether the service request address belongs to the target interface address.
[0040] Optionally, when the business request is identified as a feign object, the business request address contained in the business request, that is, the destination interface address, is obtained based on the Feign request interceptor. In actual operation, the getInstance method can be used to return the specific FeignClient object to be executed, so that each time a remote interface request is executed, the interface judgment operation will be executed first, thereby executing the corresponding address switching process according to the specific situation of the interface address.
[0041] Optionally, the target interface address is an interface address capable of normal data transmission, and relevant information of the target interface address is preset by the electronic device terminal.
[0042] Step S103: If the service request address does not belong to the target interface address, send the service request according to the preset interface address.
[0043] Optionally, when it is determined that the service request address does not belong to the target interface address, the interface switching process can be performed in a mock manner, for example, the LoadBalanceFeignClient class is used, which is a judgment class for executing mock requests, and the mock configuration information can be loaded in this class. Therefore, each call will be filtered according to the request address and the mock configuration information, and then the specific interface request address will be calculated, and then the remote interface call will be made.
[0044] Optionally, step S103 may specifically include the following steps:
[0045] Step S1031, obtaining a preset interface address from the cache.
[0046] Step S1032: If the preset interface address is not empty, send a service request according to the preset interface address.
[0047] Step S1033: if the preset interface address is empty and there is a configured preset address, the configured preset address is written into the cache as the preset interface address.
[0048] Optionally, determining whether the preset interface address is empty may directly determine whether the cache includes information of the preset interface address.
[0049] Optionally, the configured preset address may be a preset address written in a configuration file, and the configuration file may be a storage space such as a database.
[0050] Step S1034: if the preset interface address is empty and there is no configured preset address, the service request address is written into the cache as the preset interface address.
[0051] Optionally, when neither the preset interface address nor the preset address is set, in order to ensure continued execution of the process, the service request sending process is directly performed according to the service request address included in the service request.
[0052] In one embodiment, Figure 2 As shown, the above method may also include:
[0053] Step S104: If the service request address belongs to the target interface address, send the service request according to the service request address.
[0054] In one implementation manner, a second configuration file representing address conversion may also be included, wherein the second configuration file includes an original address to be converted and a new address after conversion. When the service request address belongs to the original address to be converted in the second configuration file, a conversion operation is performed, converting the service request address into a new address, and performing a service request sending operation according to the new address.
[0055] In one embodiment, the preset interface address may be a virtual service interface address, such as a mock address, or may be other service interface addresses other than the service request address, for example, the original service request address is service interface address A, and the preset interface address is service interface address B, wherein service interface addresses A and B are both actual service interface addresses; optionally, service interface address A may be, for example, bank A interface address, and service interface address B may be, for example, bank B interface address.
[0056] In the above-mentioned business request processing method, by obtaining the business request to be sent based on feign, it is determined whether the business request address corresponding to the business request belongs to the target interface address. If the business request address does not belong to the target interface address, the business request is sent according to the preset interface address. Compared with the prior art, the present application changes the execution order of feign, adds filtering before the remote call interface to determine whether the interface address needs to be replaced, and returns the return information to the request source according to the return result after the feign request is completed, thereby ensuring that the electronic device terminal will not interrupt the execution process due to the non-existence of the remote call interface address, thereby improving user experience and avoiding the extension of the project cycle during project development.
[0057] Figure 3 A flow chart of a service request processing method provided in an embodiment of the present application is shown in the figure. Based on the above method, the service request processing method may further include the following steps:
[0058] Step S105: receiving a preset interface address update instruction.
[0059] Step S106, updating the preset interface address according to the preset interface address update instruction.
[0060] Optionally, a distributed coordination center may be used to control the updating of the preset interface address, modify the data of the preset interface address in the remote control terminal and issue a corresponding modification instruction, and the electronic device terminal automatically updates the preset interface address configuration in the cache in response to the modification instruction.
[0061] In the above service request processing method, the preset interface address is updated by executing the preset interface address update instruction, so as to realize flexible setting of the preset interface address and reduce the updating operation process of the technicians.
[0062] Figure 4 A flow chart of a service request processing method provided in an embodiment of the present application is shown in the figure. Before step S101, the service request processing method may further include the following steps:
[0063] Step S107, obtaining the service request to be sent based on HTTP.
[0064] Step S108: convert the http-based service request to be sent into a feign-based service request to be sent.
[0065] In the above-mentioned business request processing method, the business request sending environment based on http can be converted into a business request sending environment based on feign, so that the interface switching scheme in other non-feign environments can be implemented, and the switching scheme of the business request address based on the http environment can be implemented, which ensures that the electronic device terminal in the http environment will not cause the execution process to be interrupted due to the non-existence of the remote call interface address, thereby improving the user experience and avoiding the extension of the project cycle during the project development process.
[0066] Figure 5 A flow chart of a service request processing method provided in an embodiment of the present application is shown in the figure. The service request processing method may include the following steps:
[0067] Step S201, obtaining the service request host.
[0068] Step S202, determine whether the service request host is empty; when the service request host is empty, it is determined that the service request is not the target object of this solution, and the service request host is directly returned.
[0069] Step S203: when the service request host is not empty, it is determined whether the service request host is in a white list, wherein the white list is a pre-set interface address that can perform normal data transmission.
[0070] Step S204: when the service request host is in the whitelist, the service request host is returned to the main thread.
[0071] Step S205: when the service request host is not in the whitelist, the mock address is obtained from the cache.
[0072] Step S206, determining whether the mock address in the cache is empty, and when the mock address in the cache is not empty, returning the mock address in the cache.
[0073] Step S207: When the mock address in the cache is empty, it is determined whether there is a configuration file of the mock address.
[0074] Step S208: When there is a configuration file of the mock address, the mock address is written into the cache according to the configuration file, and the mock address in the cache is returned.
[0075] Step S209: When there is no configuration file of the mock address, the original service request host is written into the cache, and the original service request host in the cache is returned.
[0076] Step S210, determining whether the addresses returned in steps S202 to S209 are valid.
[0077] Optionally, the step of determining whether the address is valid may be:
[0078] Step S2101, sending a response request to the address;
[0079] Step S2102: after receiving the response instruction of the address feedback, it is determined that the service request address is effective.
[0080] Step S211, when it is determined that the returned address is valid, the returned address is returned, and the service request is sent according to the returned address.
[0081] Step S212, when it is determined that the returned address is not valid, the second configuration file representing the address conversion is searched, and when the address belongs to the original address to be converted in the second configuration file, the conversion operation is performed, converting from the address to a new address, returning the converted new address, and executing the sending of the service request according to the converted new address.
[0082] Figure 6A schematic diagram of the structure of an electronic device terminal provided in an embodiment of the present application, as shown in the figure, the electronic device terminal 30 may include:
[0083] The service request acquisition module 301 is used to acquire the service request to be sent based on feign;
[0084] A request address determination module 302 is used to determine the corresponding service request address according to the service request, and determine whether the service request address belongs to the target interface address;
[0085] The preset interface address sending module 303 is used to send the service request according to the preset interface address if the service request address does not belong to the target interface address.
[0086] In one implementation manner, the preset interface address sending module 303 includes:
[0087] A preset address acquisition submodule is used to obtain a preset interface address from a cache;
[0088] The preset interface address sends the first submodule, which is used to send the service request according to the preset interface address if the preset interface address is not empty;
[0089] The preset interface address sending second submodule is used for writing the configured preset address into the cache as the preset interface address if the preset interface address is empty and there is a configured preset address;
[0090] The third submodule for sending the preset interface address is used to write the service request address into the cache as the preset interface address if the preset interface address is empty and there is no configured preset address.
[0091] Figure 7 A schematic diagram of the structure of an electronic device terminal provided in an embodiment of the present application, as shown in the figure, the electronic device terminal 30 may also include:
[0092] The service request address sending module 304 is used to send the service request according to the service request address if the service request address belongs to the target interface address.
[0093] Figure 8 A schematic diagram of the structure of an electronic device terminal provided in an embodiment of the present application, as shown in the figure, the electronic device terminal 30 may also include:
[0094] An update instruction receiving module 305 is used to receive a preset interface address update instruction;
[0095] The preset interface updating module 306 is used to update the preset interface address according to the preset interface address updating instruction.
[0096] Fig. 9A schematic diagram of the structure of an electronic device terminal provided in an embodiment of the present application, as shown in the figure, the electronic device terminal 30 may also include:
[0097] A second service request acquisition module 307, used to acquire a service request to be sent based on HTTP;
[0098] The business request conversion module 308 is used to convert the business request to be sent based on http into the business request to be sent based on feign.
[0099] The embodiment of the present application also provides a computer-readable storage medium on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the above-mentioned service request processing method are implemented. The readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0100] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0101] In the description of the embodiments of the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0102] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of this specification includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of this specification belong.
[0103] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0104] It should be noted that the terminals involved in the embodiments of the present application may include but are not limited to personal computers (PCs), personal digital assistants (PDAs), wireless handheld devices, tablet computers, mobile phones, MP3 players, MP4 players, etc.
[0105] In the several embodiments provided in this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0106] In addition, each functional unit in each embodiment of this specification may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0107] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the method described in each embodiment of this specification. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes.
[0108] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
Claims
1. A method for processing a business request, It is characterized in that Applied to an electronic device terminal, the method comprises: Get the business request to be sent based on feign; Determine a corresponding service request address according to the service request, and judge whether the service request address belongs to the target interface address; If the service request address does not belong to the target interface address, the service request is sent according to the preset interface address; wherein, if the service request address does not belong to the target interface address, the process of sending the service request according to the preset interface address includes: obtaining the preset interface address from the cache; if the preset interface address is not empty, sending the service request according to the preset interface address; if the preset interface address is empty and has a configured preset address, writing the configured preset address into the cache as the preset interface address; if the preset interface address is empty and does not have a configured preset address, writing the service request address into the cache as the preset interface address; Receive a preset interface address update instruction; The preset interface address is updated according to the preset interface address update instruction.
2. The method according to claim 1, It is characterized in that The method further comprises: If the service request address belongs to the target interface address, the service request is sent according to the service request address.
3. The method according to claim 1, It is characterized in that The preset interface address is a virtual service interface address.
4. The method according to claim 1, It is characterized in that Before obtaining the feign-based service request to be sent, it also includes: Get the business request to be sent based on http; The http-based business request to be sent is converted into the feign-based business request to be sent.
5. An electronic equipment terminal, It is characterized in that The terminal comprises: The business request acquisition module is used to obtain the business requests to be sent based on feign; A request address determination module, used to determine the corresponding service request address according to the service request, and determine whether the service request address belongs to the target interface address; A preset interface address sending module, used for sending the service request according to the preset interface address if the service request address does not belong to the target interface address, wherein the preset interface address sending module is specifically used for: obtaining the preset interface address from the cache; if the preset interface address is not empty, sending the service request according to the preset interface address; if the preset interface address is empty and has a configured preset address, writing the configured preset address into the cache as the preset interface address; if the preset interface address is empty and has no configured preset address, writing the service request address into the cache as the preset interface address; An update instruction receiving module, used for receiving a preset interface address update instruction; The preset interface updating module is used to update the preset interface address according to the preset interface address updating instruction.
6. The terminal according to claim 5, It is characterized in that The terminal further includes: The service request address sending module is used to send the service request according to the service request address if the service request address belongs to the target interface address.
7. The terminal according to claim 5, It is characterized in that The preset interface address sending module includes: A preset address acquisition submodule is used to obtain a preset interface address from a cache; A first submodule for sending the preset interface address is used to send the service request according to the preset interface address if the preset interface address is not empty; The preset interface address sending second submodule is used for, if the preset interface address is empty and there is a configured preset address, writing the configured preset address into the cache as the preset interface address; The third submodule for sending the preset interface address is used to write the service request address into the cache as the preset interface address if the preset interface address is empty and there is no configured preset address.
8. A computer-readable storage medium having computer instructions stored thereon, It is characterized in that When the instruction is executed by a processor, the steps of any method described in claims 1 to 4 are implemented.
