Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 illustrates an exemplary system architecture 100 that may be applied to embodiments of the request processing method or apparatus of the present application.
As shown in fig. 1, the system architecture 100 may include a client 101, a forwarding end 102, and a server 103.
Network 104 is used to provide the medium of a transmission link between client 101 and forwarding end 102. The network 104 may include various wired, wireless transmission links. The network 105 is used to provide the medium of a transmission link between the forwarding end 102 and the service end 103. The network 105 may include wired transmission links, such as fiber optic cables.
The server 103 may provide a service, and the client 101 may invoke the service provided by the server 103. The forwarding terminal 102 may receive a call request for a service sent by the client terminal 101, and send the call request to the server terminal 103. The forwarding end 102 may receive a call result generated after the service is called and returned by the server end 103, and send the call result to the client 101.
In the present application, a terminal or a server deployed in the client 101 may invoke a service provided by the server 103. The server cluster deployed at the forwarding end 102 may receive a call request for a service sent by the client 101, and send the call request to the server 103. The services may be provided by a cluster of servers deployed at the server 103.
In the following embodiments of the present application, a service provided by a server may be referred to as a server-provided operation.
Referring to FIG. 2, a flow 200 of one embodiment of a request processing method according to the present application is shown. It should be noted that the request processing method provided in the embodiment of the present application may be executed by the forwarding end 102 in fig. 1, for example, may be executed by a server cluster deployed at the forwarding end 102, and accordingly, the request processing apparatus may be disposed at the forwarding end 102. The method comprises the following steps:
step 201, receiving a first call request sent by a client.
In this embodiment, when the client needs to invoke an operation provided by the server, a first invocation request sent by the client may be received. The first invocation request includes: the operation identification of the operation provided by the server side, callback indicating information indicating whether to call back when the operation provided by the calling server side is successful, and retry indicating information indicating whether to retry when the operation provided by the calling server side is failed.
In this embodiment, the first invocation request sent by the client may include an operation identifier of an operation provided by the server, where the operation identifier may be used to identify an operation of the server that the client needs to invoke.
In this embodiment, the first invocation request sent by the client further includes callback indication information indicating whether a callback is required when the operation provided by the client invocation server is successful. For example, when the client needs to call back the call result generated after the call when the operation provided by the call server is successful, the callback indication information may be indication information indicating that the client calls back the call result when the operation provided by the call server is successful.
In this embodiment, the first invocation request sent by the client further includes retry indication information indicating whether to perform a retry when the operation provided by the invocation server fails. For example, when the client needs to perform a retry when the operation provided by the calling server fails, that is, when the calling request is retransmitted, the retry indication information may be retry indication information indicating that the retry is performed when the operation provided by the calling server fails.
Step 202, sending a second call request containing the operation identifier to the server, and receiving return information returned by the server.
In this embodiment, after receiving the first invocation request sent by the client through step 201, a second invocation request containing the operation identifier may be generated. Then, a second call request may be sent to the server to call an operation corresponding to the operation identifier of the server. After the second operation request is sent to the server, return information returned by the server may be received.
In this embodiment, the return information returned by the server includes: and indicating result indication information indicating success or failure of the operation calling corresponding to the operation identifier.
And 203, determining to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information according to the result indication information.
In this embodiment, it may be determined whether to execute the preset operation corresponding to the callback indication information received in step 201 and determine whether to execute the preset operation corresponding to the retry indication information received in step 201 according to result indication information indicating success or failure of the call corresponding to the indication operation identifier returned by the server in step 202.
In some optional implementation manners of this embodiment, the result indication information indicates that the operation call corresponding to the operation identifier is successful; and according to the result indication information, determining whether to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information comprises: and executing the preset operation corresponding to the callback indication information.
In some optional implementations of this embodiment, the returning information further includes: calling a calling result generated after the operation corresponding to the operation identifier is called, and calling back when the calling back indication information indicates that the operation provided by the calling server is successful; and executing the preset operation corresponding to the callback indication information comprises the following steps: and sending the calling result to the client.
In this embodiment, when the result indication information received in step 202 indicates that the operation corresponding to the operation identifier of the calling server is successfully called, the preset operation corresponding to the callback indication information received in step 201 may be executed.
In this embodiment, when the operation corresponding to the operation identifier of the calling server is successfully called, the return information returned by the server received in step 202 further includes a calling result generated after the operation corresponding to the operation identifier of the calling server. The invocation result may be sent to the client.
In some optional implementation manners of this embodiment, after sending the invocation result to the client, the method further includes: judging whether the client successfully receives the calling result; and when the client does not successfully receive the calling result, the calling result is sent to the client until the client successfully receives the calling result or the sending times corresponding to the calling result are equal to the time threshold.
In this embodiment, after the call result is sent to the client, it may be determined whether the client successfully receives the call result. When the client does not successfully receive the call result, the call result may be sent to the client until the client successfully receives the call result or the number of times of sending corresponding to the call result is equal to the number threshold.
In some optional implementation manners of this embodiment, the result indication information indicates that the operation call corresponding to the operation identifier fails; and according to the result indication information, determining whether to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information comprises: and executing the preset operation corresponding to the retry indication information.
In this embodiment, when the result indication information returned by the server indicates that the operation call corresponding to the operation identifier of the calling server fails through step 202, the preset operation corresponding to the retry indication information received through step 201 may be executed.
In this embodiment, when the retry indication information received in step 201 indicates that a retry is performed when the operation provided by the calling server is failed, a second call request may be sent to the server to call the operation corresponding to the operation identifier on the server until receiving result indication information indicating that the operation call corresponding to the operation identifier returned by the server is successful or the number of times of sending corresponding to the second call request is equal to the threshold number.
In some optional implementations of this embodiment, the method further includes: counting the number of the received first call requests in a preset time period; and when the number is larger than the first number threshold, executing preset current limiting operation to control the number of the second calling requests sent to the server.
In some optional implementations of this embodiment, the method further includes: counting the number of first calling requests received by a server cluster within a preset time period; and when the number is larger than a second number threshold, executing preset server cluster current limiting operation to control the number of second call requests sent by the server cluster to the server.
In the present application, the number of call requests received within a preset time period may be limited. For example, the number of call requests received by a single server may be limited, while the number of call requests received by the entire server cluster on the server side may be limited.
And when the number of the first calling requests received by a single server in a preset time period is smaller than the set JVM single counter number and the total number of the first calling requests received by the server cluster in the preset time period is smaller than the Redis-based server cluster counter number, sending a second calling request to the server side to request the target service. When the total number of the received first call requests in the preset time period reaches the number threshold and the first call requests are received again, the requests fail, and the timing task scanning can be waited to trigger the requests again.
Referring to FIG. 3, a flow 300 of another embodiment of a request processing method according to the present application is shown. It should be noted that the request processing method provided by the embodiment of the present application may be executed by the client 101 in fig. 1, for example, executed by a terminal or a server deployed in the client 101, and accordingly, the request processing apparatus may be disposed in the client 101. The method comprises the following steps:
step 301, receiving a call instruction corresponding to an operation provided by a server.
In this embodiment, before receiving a call instruction corresponding to an operation provided by a server, a call instruction corresponding to an operation provided by a server may be generated first. For example, in the process of using the internet application, a user may click a button corresponding to an operation provided by a server in an interface of the application to generate a call instruction corresponding to the operation provided by the server. At this time, the input call instruction corresponding to the operation provided by the server may be received.
Step 302, generate a call request.
In this embodiment, after receiving a call instruction corresponding to an operation provided by a server through step 301, a call request may be generated. The call request includes: the operation identification of the operation provided by the calling server side is needed to be called, the callback indicating information which indicates whether to call back when the operation provided by the calling server side is successful, and the retry indicating information which indicates whether to retry when the operation provided by the calling server side is failed.
In this embodiment, the configuration may be performed according to the requirements of callback, retry and the like in the process of calling operation. For example, when the client needs to call back the call result generated after the call when the operation provided by the call server is successful, the callback indication information may be indication information indicating that the client calls back the call result when the operation provided by the call server is successful. For another example, when the client needs to retry the operation provided by the calling server when the operation fails, that is, when the calling request is retransmitted, the retry indication information may be retry indication information indicating that the retry is performed when the operation provided by the calling server fails.
Step 303, sending a call request to the forwarding end.
In this embodiment, after the invocation request is generated through step 302, the forwarding end may send the invocation request. Therefore, the forwarding end can send the call request to the server end to call the operation corresponding to the operation identifier, and can determine to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information according to the call success or failure.
Referring to FIG. 4, a flow 400 of yet another embodiment of a request processing method according to the present application is shown. It should be noted that the request processing method provided in the embodiment of the present application may be executed by the server 103 in fig. 1, for example, executed by a server cluster deployed in the server 103, and accordingly, the request processing apparatus may be disposed in the server 103. The method comprises the following steps:
step 401, receiving a call request sent by a forwarding end.
In this embodiment, the invocation request includes: and (5) operation identification.
Step 402, generating result indication information indicating success or failure of the operation call corresponding to the operation identifier.
In this embodiment, after receiving the invocation request sent by the forwarding end in step 401, the operation corresponding to the operation identifier in the invocation request may be invoked. Then, according to the call success or failure, result indication information indicating that the operation call corresponding to the operation identifier is successful or failed may be generated.
And step 403, sending the result indication information to the forwarding end.
In this embodiment, the result indication information indicating that the operation call corresponding to the operation identifier is successful or failed is generated in step 402, and the result indication information may be sent to the forwarding end. Therefore, the forwarding end can determine, according to the result indication information, whether to execute the preset operation corresponding to the callback indication information indicating whether to perform callback when the operation provided by the calling server is successful or whether to execute the preset operation corresponding to the retry indication information indicating whether to perform retry when the operation provided by the calling server is failed.
Referring to fig. 5, an exemplary architecture diagram is shown for a request processing method applicable to the present application.
In fig. 5, a client 501, a forwarding end 502, and a server 503 are shown. The client can run a calling process for calling the target service, the forwarding end can run an asynchronous forwarding service, and the server can provide the target service. The client can call the asynchronous forwarding service, then the asynchronous forwarding service asynchronously calls the target service, and after the calling is successful, the asynchronous forwarding service asynchronously returns a calling result to the client.
In the present application, when the invocation of the target service fails, a task in a specific state may be scanned by a timing task created in advance. For example, a task failing to invoke the target service may be scanned by the timing task and then retried, thereby securing reliability of invoking the target service.
In the application, in the process of calling the target service by the asynchronous forwarding service, the number of calls received in a preset time period can be limited. For example, the number of call requests received by a single server of a server cluster deployed on a server is limited, and meanwhile, the number of call requests received by a whole server cluster deployed on the server is limited.
Referring to FIG. 6, an exemplary schematic diagram of a request processing method according to the present application is shown.
In the present application, a task may be established for a call request, and a task at a specific stage may be scanned by a timing task. In the present application, a task may be in the following stages:
an initialization stage: when the calling party calls the asynchronous forwarding intermediate service, the calling request is sent to the asynchronous forwarding intermediate service, the asynchronous forwarding intermediate service can insert a task record in an initial state into a database, and can perform processing in an execution stage according to configuration information or enter the execution stage after waiting for a task in a timing task scanning initialization state.
An execution stage: and asynchronously calling the target service according to the calling request, and if the calling is successful, setting the state of the task to be successfully executed. Then, according to the configuration information, the callback phase is entered or the current flow is ended, and the state of the task is set as the execution end. If the call fails, retry can be carried out according to the configuration information, namely, the call request is sent again, and when the call is not successfully called after a certain retry number is reached, the state of the task can be set as the execution failure, and the current flow is ended.
A callback phase: and entering a callback phase when the target service called by the asynchronous forwarding intermediate service is successful and needs to be called. The asynchronous forwarding intermediate service can send the calling result to the client according to the set callback address. If the sending is successful, the task state can be set as callback success, and the current flow is ended. If the transmission fails, a retry may be performed based on the configuration information. When the sending is still unsuccessful after reaching a certain retry number, the state of the task can be set as a callback failure state, and the current flow is ended.
In the application, a timing task can be created in advance, and the timing task can scan out a task in an initialization state and execute a success state at fixed time and call back a failed task.
In the present application, a retry mechanism is provided that is directed to meeting different requirements. In the retry mechanism, whether or not a retry is required, the number of retries, and the retry interval can be configured. Because some interactions between the client and the server do not need to guarantee reliability, and only the target service is requested to have a limited flow function, in the application, whether retry is needed can be configured. The retry times after call failure can be configured according to the service requirements, and when the retry times are greater than the retry times, the retry can not be performed any more. The interval of retries can be configured according to traffic demands.
Referring to fig. 7, a schematic structural diagram of an embodiment of a request processing device according to the present application is shown. This device embodiment corresponds to the method embodiment shown in fig. 2.
As shown in fig. 7, the request processing apparatus 700 of the present embodiment includes: request receiving section 701, request transmitting section 702, and determining section 703. The request receiving unit 701 is configured to receive a first invocation request sent by a client, where the first invocation request includes: the method comprises the steps of providing an operation identifier of an operation by a server, callback indicating information indicating whether to call back when the operation provided by a calling server is successful, and retry indicating information indicating whether to retry when the operation provided by the calling server is failed; the request sending unit 702 is configured to send a second invocation request containing the operation identifier to the server, and receive return information returned by the server, where the return information includes: result indication information indicating success or failure of operation calling corresponding to the operation identifier; the determining unit 703 is configured to determine, according to the result indicating information, to execute a preset operation corresponding to the callback indicating information or execute a preset operation corresponding to the retry indicating information.
In some optional implementations of this embodiment, the determining unit 703 includes: a first execution subunit (not shown), configured to, when the result indication information indicates that the operation corresponding to the operation identifier is successfully invoked and the callback indication information indicates that the operation provided by the calling server is successful, send, to the client, a calling result generated after the operation corresponding to the calling operation identifier in the return information; and a second execution subunit (not shown), configured to, when the result indication information indicates that the operation call corresponding to the operation identifier fails and the retry indication information indicates that a retry is performed when the operation provided by the calling server fails, send the second call request to the server until receiving the result indication information indicating that the operation call corresponding to the operation identifier succeeds or the number of times of sending corresponding to the second call request returned by the server is equal to the number threshold.
In some optional implementations of this embodiment, the apparatus 700 further includes: a determining unit (not shown) configured to determine whether the client successfully receives the calling result after sending the calling result to the client; and a retry unit (not shown) configured to, when the client does not successfully receive the call result, send the call result to the client until the client successfully receives the call result or a number of times of sending corresponding to the call result is equal to the number threshold.
In some optional implementations of this embodiment, the apparatus 700 further includes: a first statistical unit (not shown) configured to count the number of first call requests received within a preset time period; a current limiting unit (not shown) configured to perform a preset current limiting operation to control the number of the second call requests sent to the server when the number is greater than a first number threshold; a second counting unit (not shown) configured to count the number of the first call requests received by the server cluster within a preset time period; and the cluster current limiting unit (not shown) is configured to execute a preset server cluster current limiting operation to control the number of the second call requests sent by the server cluster to the server when the number is greater than the second number threshold.
Referring to fig. 8, a schematic structural diagram of another embodiment of a request processing device according to the present application is shown. This device embodiment corresponds to the method embodiment shown in fig. 3.
As shown in fig. 8, the request processing apparatus 800 of the present embodiment includes: an instruction receiving unit 801, a request generating unit 802, and a call request transmitting unit 803. The instruction receiving unit 801 is configured to receive a call instruction corresponding to an operation provided by a server; the request generating unit 802 is configured to generate a call request, where the call request includes: the operation identification of the operation, callback indicating information indicating whether to perform callback when the operation provided by the calling service end is successful, and retry indicating information indicating whether to perform retry when the operation provided by the calling service end is failed; the call request sending unit 803 is configured to send a call request to the forwarding end, so that the forwarding end sends the call request including the operation identifier to the server end to call the operation corresponding to the operation identifier, and determines to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information according to success or failure of the call.
Referring to fig. 9, a schematic structural diagram of yet another embodiment of a request processing device according to the present application is shown. This device embodiment corresponds to the method embodiment shown in fig. 4.
As shown in fig. 9, the request processing apparatus 900 of the present embodiment includes: a call request receiving unit 901, an information generating unit 902, and an information transmitting unit 903. The invocation request receiving unit 901 is configured to receive an invocation request sent by a forwarding end, where the invocation request includes: an operation identifier; the information generating unit 902 is configured to generate result indication information indicating success or failure of the operation call corresponding to the operation identifier; the information sending unit 903 is configured to send the result indication information to the forwarding end, so that the forwarding end determines, according to the result indication information, whether to execute a preset operation corresponding to callback indication information indicating whether to perform callback when the operation provided by the calling server is successful or whether to execute a preset operation corresponding to retry indication information indicating whether to perform retry when the operation provided by the calling server is failed.
FIG. 10 illustrates a block diagram of a computer system suitable for use in implementing a request processing device of an embodiment of the present application.
As shown in fig. 10, the computer system 1000 includes a Central Processing Unit (CPU)1001 that 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 section 1008 into a Random Access Memory (RAM) 1003. In the RAM1003, various programs and data necessary for the operation of the system 1000 are also stored. The CPU1101, ROM 1002, and RAM1003 are connected to each other by a bus 1004. An input/output (I/O) interface 1005 is also connected to bus 1104.
The following components are connected to the I/O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output section 1007 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 1008 including a hard disk and the like; and a communication section 1009 including a network interface card such as a LAN card, a modem, or the like. The communication section 1009 performs communication processing via a network such as the internet. The driver 1010 is also connected to the I/O interface 1005 as necessary. A removable medium 1011 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 1010 as necessary, so that a computer program read out therefrom is mounted into the storage section 1008 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication part 1009 and/or installed from the removable medium 1011.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
As another aspect, the present application also provides a non-volatile computer storage medium, which may be the non-volatile computer storage medium included in the apparatus in the above-described embodiments; or it may be a non-volatile computer storage medium that exists separately and is not incorporated into the terminal. The non-transitory computer storage medium stores one or more programs that, when executed by a device, cause the device to: receiving a first call request sent by a client, wherein the first call request comprises: the method comprises the steps of providing an operation identifier of an operation by a server, callback indicating information indicating whether to call back when the operation provided by a calling server is successful, and retry indicating information indicating whether to retry when the operation provided by the calling server is failed; sending a second calling request containing the operation identifier to the server, and receiving return information returned by the server, wherein the return information comprises: result indication information indicating success or failure of operation calling corresponding to the operation identifier; and according to the result indication information, determining to execute the preset operation corresponding to the callback indication information or execute the preset operation corresponding to the retry indication information.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by a person skilled in the art that the scope of the invention as referred to in the present application is not limited to the embodiments with a specific combination of the above-mentioned features, but also covers other embodiments with any combination of the above-mentioned features or their equivalents without departing from the inventive concept. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.