CN109189509B - Interface calling method, interface calling response method and server - Google Patents

Interface calling method, interface calling response method and server Download PDF

Info

Publication number
CN109189509B
CN109189509B CN201811019901.XA CN201811019901A CN109189509B CN 109189509 B CN109189509 B CN 109189509B CN 201811019901 A CN201811019901 A CN 201811019901A CN 109189509 B CN109189509 B CN 109189509B
Authority
CN
China
Prior art keywords
call
target interface
interface
target
waiting queue
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811019901.XA
Other languages
Chinese (zh)
Other versions
CN109189509A (en
Inventor
许进
谈锦勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN201811019901.XA priority Critical patent/CN109189509B/en
Publication of CN109189509A publication Critical patent/CN109189509A/en
Application granted granted Critical
Publication of CN109189509B publication Critical patent/CN109189509B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention is suitable for the technical field of communication, and provides a calling method of an interface, a response method of interface calling and a server, wherein the interface name of the target interface and the server identifier of the target server are obtained through analyzing a calling target interface instruction, a data request is sent to the target server according to the server identifier, after a reply message returned by the target server is received, whether the target interface meets the calling requirement is judged according to waiting queue data corresponding to the target interface contained in the reply message, if the target interface meets the calling requirement, the calling request of the target interface is sent to the target server, so that whether the target interface runs overload is judged before the calling request of the interface is sent, and the safety and the stability of system operation are improved.

Description

Interface calling method, interface calling response method and server
Technical Field
The invention belongs to the technical field of communication, and particularly relates to an interface calling method, an interface calling response method and a server.
Background
Application systems often implement a system architecture based on multiple servers, where interfaces of each server often have a maximum of throughput, and once a certain server's interfaces are requested more than its maximum of throughput, normal operation of the server is affected.
In order to avoid the occurrence of the above situations, the current technology always performs corresponding limitation from the side of the server where the called interface is located, but doing so increases the burden of the server where the called interface is located, and in addition, the server on the side of the calling interface is difficult to acquire the process of the interface call, and the operation which should be executed subsequently cannot be judged, so that the stable operation of the whole system is affected to a certain extent.
Furthermore, each server has the potential to be attacked, and current techniques do not have a good solution to the attack that initiates a large number of requests.
In summary, the current system has the problems of lower safety and poorer stability in the process of interface calling.
Disclosure of Invention
In view of the above, the embodiments of the present invention provide an interface calling method, an interface calling response method, and a server, so as to solve the problem of low security and poor stability in the prior art.
A first aspect of an embodiment of the present invention provides a method for calling an interface, including:
if a call target interface instruction input by a user is received, analyzing an interface name of a target interface contained in the call target interface instruction and a server identification of a target server;
According to the server identification, sending a data request to the target server, wherein the data request comprises a time stamp for describing the generation time of the data request and an interface name of the target interface, so that the target server judges whether to return a reply message according to the time stamp;
if the reply message returned by the target server is received, judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message;
and if the target interface meets the call requirement, generating a call request of the target interface, and sending the call request of the target interface to the target server to finish the call of the target interface.
In the embodiment of the invention, the interface name of the target interface and the server identifier of the target server are obtained through analyzing the call target interface instruction, the data request is sent to the target server according to the server identifier, after the reply message returned by the target server is received, whether the target interface meets the call requirement is judged according to the waiting queue data corresponding to the target interface contained in the reply message, if the target interface meets the call requirement, the call request of the target interface is sent to the target server, so that the judgment of whether the target interface runs overload is firstly carried out before the call request of the interface is sent, and the running stability of the system is improved.
A second aspect of an embodiment of the present invention provides a method for responding to an interface call, including:
If a data request of an external server is received, judging whether to intercept the data request according to an interface name of a target interface contained in the data request;
If the data request is not intercepted, analyzing a time stamp contained in the data request, and if the difference value between the time corresponding to the time stamp and the current time is not larger than a preset time difference threshold value, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache;
if the number of the call requests in the waiting queue is not greater than a preset call number extremum, adding the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packaging the waiting queue data, and generating a reply message;
The reply message is sent to an external server;
when receiving the call requests of the target interface, if the number of the call requests in the waiting queue of the target interface is not 0, adding the latest received call requests into the waiting queue.
A third aspect of the embodiments of the present invention provides a server for calling an interface, including a memory and a processor, where the memory stores a computer program that can run on the processor, and when the processor executes the computer program, the processor implements the following steps:
if a call target interface instruction input by a user is received, analyzing an interface name of a target interface contained in the call target interface instruction and a server identification of a target server;
According to the server identification, sending a data request to the target server, wherein the data request comprises a time stamp for describing the generation time of the data request and an interface name of the target interface, so that the target server judges whether to return a reply message according to the time stamp;
if the reply message returned by the target server is received, judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message;
and if the target interface meets the call requirement, generating a call request of the target interface, and sending the call request of the target interface to the target server to finish the call of the target interface.
A fourth aspect of the embodiment of the present invention provides an interface call response server, including a memory and a processor, where the memory stores a computer program that can run on the processor, and when the processor executes the computer program, the processor implements the following steps:
When a data request of an external server is received, judging whether to intercept the data request according to an interface name of a target interface contained in the data request;
If the data request is not intercepted, analyzing a time stamp contained in the data request, and if the difference value between the time corresponding to the time stamp and the current time is not larger than a preset time difference threshold value, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache;
if the number of the call requests in the waiting queue is not greater than a preset call number extremum, adding the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packaging the waiting queue data, and generating a reply message;
The reply message is sent to an external server;
when receiving the call requests of the target interface, if the number of the call requests in the waiting queue of the target interface is not 0, adding the latest received call requests into the waiting queue.
A fifth aspect of an embodiment of the present invention provides a computer-readable storage medium storing computer-readable instructions which, when executed by a processor, implement the steps of the method of invoking an interface as described in the first aspect.
A sixth aspect of an embodiment of the present invention provides a computer-readable storage medium storing computer-readable instructions which, when executed by a processor, implement the steps of the method of responding to an interface call as described in the second aspect.
In the embodiment of the invention, whether the data request is intercepted or not is judged according to the interface name of the target interface contained in the received data request, if the data request is not intercepted, the timestamp in the data request is analyzed, when the difference value between the time corresponding to the timestamp and the current time meets the requirement, the number of the call requests in the waiting queue corresponding to the target interface is read, if the number meets the requirement, a reply message is sent to an external server, and when the call request of the target interface is received, if the number of the call requests in the waiting queue of the target interface is not 0, the latest received call request is added into the waiting queue so as to avoid malicious attack on the target interface in a mode of a large number of requests, and the running safety of the system is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of an implementation of a method for calling an interface provided by an embodiment of the present invention;
FIG. 2 is a flowchart of a specific implementation of a calling method S103 of an interface according to an embodiment of the present invention;
FIG. 3 is a flow chart of an implementation of a method for responding to an interface call provided by an embodiment of the present invention;
FIG. 4 is a block diagram of a call interface server according to an embodiment of the present invention;
FIG. 5 is a block diagram of an interface call response server provided by an embodiment of the present invention;
FIG. 6 is a schematic diagram of a server of a call interface provided by an embodiment of the present invention;
FIG. 7 is a schematic diagram of a response server for interface calls provided by an embodiment of the present invention;
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, techniques, etc., in order to provide a thorough understanding of the embodiments of the present invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to illustrate the technical scheme of the invention, the following description is made by specific examples.
Fig. 1 shows a flow of implementation of a method for calling an interface provided by an embodiment of the present invention, where the method flow includes steps S101 to S105. The specific implementation principle of each step is as follows.
S101, if a call target interface instruction input by a user is received, analyzing an interface name of a target interface contained in the call target interface instruction and a server identification of a target server.
In the embodiment of the invention, one system comprises a plurality of sub-servers, and one sub-server can call interfaces on other sub-servers so as to use the processing functions of the other sub-servers. For convenience in describing the principles and steps of embodiments of the present invention, we call a sub-server that provides an interface to other sub-servers, referred to as a target server, and call a sub-server that invokes an interface of other sub-servers, referred to as a local server.
Notably, the technical solution is introduced from the local server side, that is, the necessary operation steps of the sub-server of one system are mainly introduced when the interface of another sub-server is called.
In the embodiment of the invention, when a user wants to call the functions of other servers through the server operated by the user, a call target interface instruction is input to the local server operated by the user. It will be appreciated that the interface name of the target interface contained in the target interface instruction is used to lock a particular interface of a target server, and that the server identification of the target server contained in the target interface instruction is used to lock a particular target server.
S102, according to the server identification, sending a data request to the target server, wherein the data request comprises a time stamp for describing the generation time of the data request and an interface name of the target interface, so that the target server judges whether to return a reply message according to the time stamp.
It will be appreciated that the local server, upon receiving the user-entered call target interface command, generates a data request and sends it to the target server.
Notably, the data request includes, in addition to the interface name of the target interface, a timestamp of the generation time of the data request, where the timestamp can help the target interface determine whether the data request has a transmission exception. It will be appreciated that in communication transmissions, transmission anomalies may be caused by a variety of reasons, such as channel congestion, etc., which may result in data requests not being communicated, or being communicated over time. Because the servers involved in the embodiments of the present invention all need to process a large amount of massive data in real time, if a data request arrives in a delayed manner, a local server may not need a target interface to be requested by the data request, or the function of the target interface is outdated or invalid, so that the target server does not need to further analyze the data request and do no subsequent operation of interface call.
In summary, the timestamp of the time of generation of the data request may help the target server determine whether a reply message needs to be returned to agree that the local server continues to invoke the target interface.
It can be understood that in the embodiment of the present invention, only a timestamp of the generation time of the data request needs to be added to the data request, and the call flow of the target interface is continued after the reply message of the target server is received, and before the reply message is not received, the call flow of the interface is naturally in an interrupt transition state.
And S103, if the reply message returned by the target server is received, judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message.
In the embodiment of the invention, when the number of the data requests of any one target server is larger than the maximum concurrency of the interface, the newly received data requests meeting the requirements of the interface are added into the waiting queue data, and in the target server, how to judge whether one data request meets the requirements or not is specifically described in the embodiment of the side of the target server, in the embodiment of the invention, the local server only needs to analyze by utilizing the waiting queue data corresponding to the target interface to judge whether the target interface meets the calling requirements or not.
Notably, the wait queue data includes the number of call requests in the wait queue corresponding to the target interface and the receiving time of each call request.
As an embodiment of the present invention, as shown in fig. 2, S103 includes:
s1031, comparing the number of the call requests in the waiting queue with the first preset number and the second preset number.
In the embodiment of the invention, the first preset number is smaller than the second preset number.
S1032, if the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement.
It will be appreciated that in this case, since there are fewer call requests in the wait queue, receiving a call request again still does not affect normal operation, and the wait time is not too long, so it is determined that the target interface meets the call requirement.
S1033, if the number of the call requests in the waiting queue is larger than the second preset number, judging that the target interface does not meet the call requirement.
It will be appreciated that in this case, since there are too many call requests in the wait queue, the excessive number of call requests in the wait queue in the prior art may cause a series of problems, so in order to avoid the occurrence of processing abnormality of the target server and also in order to avoid the waiting time being too long, it is determined that the target interface does not meet the call requirement.
S1034, if the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of the plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number.
In the embodiment of the present invention, the number of call requests in the waiting queue in S1034 is between the number of call requests in S1032 and S1033, and it is required to determine that the target interface meets the call requirement through a further algorithm.
For example, the unit time period may be 1 minute, and assuming that the current time is 10 points and 10 minutes, according to the receiving time of each call request, counting the number of call requests corresponding to 1 point from 10 points and 10 points, the number … … of call requests corresponding to 1 point and 2 points from 10 points and the number … … of call requests corresponding to 9 points and 10 points, thereby generating the corresponding relationship between each unit time period and the number of call requests.
S1035, fitting a corresponding relation between the unit time period and the number of the call requests in a preset time period through a linear regression model, and calculating a linear regression coefficient of the linear regression equation according to a least square method.
Optionally, the linear regression model includes: y (n) =ax (n) +b, where Y (n) is the number of call requests corresponding to the nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient.
Illustratively, assuming that the preset time period is 10 minutes, the respective unit time periods are sequentially ordered in time order, X (n) of the first unit time period is set to 1, X (n) of the second unit time period is set to 2, X (n) of the third unit time period is set to 3, and so on, X (n) represents the nth unit time period within 10 minutes as an argument.
It is understood that, assuming that the preset time period is divided into 10 unit time periods in total, X (n) of the first unit time period after the current time is 101, X (n) of the second unit time period after the current time is 102, and so on.
It can be appreciated that after the correspondence between the unit time period and the number of call requests in the preset time period is counted, the linear regression coefficient of the linear regression equation may be calculated by the least square method, that is, the slope of the linear regression equation is calculated.
S1036, if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
It can be understood that if the linear regression coefficient, that is, the slope of the linear regression equation, is a non-positive number, it is proved that the number of call requests in the waiting queue is not in an ascending trend in the preset time period, so that on the premise that the number of call requests in the waiting queue is not greater than the second preset number, there is a certain storage space in the waiting queue of the target interface, so that in the embodiment of the present invention, it is determined that the target interface meets the call requirement.
It is worth noting that, an important invention point of the embodiment of the present invention is that, unlike the prior art that only judges the number of call requests at the end of the target server (i.e. the end of the sub-server of the called interface), the number of call requests is prevented from exceeding the bearing range of the target interface, the end of the local server (i.e. the end of calling other sub-server interfaces) of the embodiment of the present invention will inquire and judge whether the target interface in the target server has the capability of processing the new call request, which is helpful to reduce the burden of the target server, and can help the local server to switch the requested target interface in time, ensure the processing efficiency of the data of the user, and ensure the stable operation of the whole system.
S104, if the target interface does not meet the calling requirement, terminating the calling flow of the interface.
Notably, in the embodiment of the present invention, if the target interface does not meet the call requirement, the target interface is proved to be busy, so the call flow to the interface is directly terminated, and no instruction or notification is sent to the target server.
S105, if the target interface meets the call requirement, generating a call request of the target interface, and sending the call request of the target interface to the target server so as to complete the call of the target interface.
Optionally, the generating the call request of the target interface includes: acquiring parameters of an implementation class of the target interface, wherein the parameters of the implementation class are used for determining a specific implementation class in the target interface; packaging the interface name of the target interface and the parameters of the implementation class of the target interface by a writeValuesAsString method to generate a json character string; encrypting the json character string through a preset secret key to generate an encrypted character string; creating a Map set, setting a value of the Map set as the encryption string, setting a Key value of the Map set as the Key, and converting the Map set into a call request.
It can be understood that, in the embodiment of the present invention, by analyzing the instruction of the call target interface, the interface name of the target interface and the server identifier of the target server are obtained, according to the server identifier, a data request is sent to the target server, after receiving the reply message returned by the target server, whether the target interface meets the call requirement is determined according to the waiting queue data corresponding to the target interface included in the reply message, if the target interface meets the call requirement, the call request of the target interface is sent to the target server, so as to determine whether the target interface runs overload before sending the call request of the interface, thereby improving the running stability of the system.
Fig. 3 shows a flow of implementation of the interface call response method provided by the embodiment of the present invention, where the method flow includes steps S301 to S311. The specific implementation principle of each step is as follows.
S301, if a data request of an external server is received, judging whether to intercept the data request according to an interface name of a target interface contained in the data request.
In the embodiment of the invention, a system comprises a plurality of sub-servers, and one sub-server can call interfaces on other sub-servers so as to use the processing functions of the other sub-servers. For convenience in describing the principles and steps of embodiments of the present invention, we call a sub-server that provides an interface to other sub-servers, referred to as a target server, and call a sub-server that calls other sub-server interfaces, referred to as an external server (external server relative to the target server).
Notably, the technical solution is introduced from the side of the target server, that is, the necessary operation steps of the sub-server of a system are mainly introduced when the sub-server is called.
It may be appreciated that in the embodiment of the present invention, a sleep interface list and a failure interface list are stored in the target server, and if the interface name of the target interface exists in the sleep interface list or the failure interface list, the data request is intercepted.
S302, if the data request is intercepted, the data request is not analyzed after the interception, and the flow of the response of the interface call is terminated.
S303, if the data request is not intercepted, analyzing the time stamp contained in the data request.
The data request includes, in addition to the interface name of the target interface, a timestamp of the generation time of the data request, where the timestamp can help the target interface determine whether the data request has a transmission abnormality. It will be appreciated that in communication transmissions, transmission anomalies may be caused by a variety of reasons, such as channel congestion, etc., which may result in data requests not being communicated, or being communicated over time. Because the servers involved in the embodiments of the present invention all need to process a large amount of massive data in real time, if a data request arrives in a delayed manner, an external server may not need a target interface to be requested by the data request, or the function of the target interface is outdated or invalid, so that the target server does not need to further analyze the data request and do no subsequent operation of interface call.
S304, judging whether the difference value between the time corresponding to the time stamp and the current time is larger than a preset time difference threshold value.
S305, if the difference value between the time corresponding to the timestamp and the current time is not greater than a preset time difference threshold, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache.
And S306, if the difference value between the time corresponding to the timestamp and the current time is larger than a preset time difference threshold value, returning a request overtime notification to the external server.
It will be appreciated that the request timeout notification is used to alert the external server to a timeout exception during the communication transmission of the data request.
S307, judging whether the number of call requests in the waiting queue is greater than a preset call number extremum
S308, if the number of the call requests in the waiting queue is greater than a preset call number extreme value, terminating the flow of the interface call response.
And S309, if the number of the call requests in the waiting queue is not greater than a preset call number extremum, adding the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packaging the waiting queue data, and generating a reply message.
And S310, the reply message is sent to an external server.
And S311, when receiving the call request of the target interface, if the number of call requests in the waiting queue of the target interface is not 0, adding the latest received call request into the waiting queue.
It can be understood that, in the embodiment of the present invention, whether to intercept a data request is determined according to an interface name of a target interface included in a received data request, if the data request is not intercepted, a timestamp in the data request is analyzed, when a difference value between a time corresponding to the timestamp and a current time meets a requirement, the number of call requests in a waiting queue corresponding to the target interface is read, if the number meets the requirement, a reply message is sent to an external server, and when the call request of the target interface is received, if the number of call requests in the waiting queue of the target interface is not 0, the latest received call request is added into the waiting queue to avoid malicious attack on the target interface by a large number of requests, so as to improve the security of system operation.
It will be appreciated that, by the embodiments described in fig. 1 and 3, an interface call interactive system may be formed, where the system includes a target server and an external server, where the target server is a server that provides an interface, and the external server is a server that calls an interface;
When receiving a call target interface instruction input by a user, the external server analyzes an interface name of a target interface contained in the call target interface instruction and a server identification of the target server;
The external server sends a data request to the target server according to the server identifier, wherein the data request comprises a time stamp of the moment of generating the data request and an interface name of the target interface;
when the target server receives a data request of an external server, judging whether to intercept the data request according to an interface suffix name of a target interface contained in the data request;
If the target server does not intercept the data request, analyzing a time stamp contained in the data request, and if the difference value between the time corresponding to the time stamp and the current time is not greater than a preset time difference threshold value, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache;
If the number of the call requests in the waiting queue is not greater than a preset call number extremum, the target server adds the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packages the waiting queue data, generates a reply message, and sends the reply message to an external server;
If the external server receives the reply message returned by the target server, judging whether the target interface meets the calling requirement or not according to the reply message;
if the target interface meets the call requirement, the external server generates a call request of the target interface and sends the call request of the target interface to the target server;
When the target server receives the call requests of the target interface, if the number of the call requests in the waiting queue of the target interface is not 0, the latest received call requests are added into the waiting queue so as to complete the call of the target interface.
It can be understood that, by analyzing the instruction of the calling target interface, the interface name of the target interface and the server identifier of the target server are obtained, according to the server identifier, a data request is sent to the target server, after receiving the reply message returned by the target server, whether the target interface meets the calling requirement is judged according to the waiting queue data corresponding to the target interface contained in the reply message, if the target interface meets the calling requirement, the calling request of the target interface is sent to the target server, so as to judge whether the target interface runs overload before sending the interface calling request, thereby improving the running stability of the system.
Corresponding to the calling method of the interface described in the above embodiment, fig. 4 shows a block diagram of the structure of the server for calling the interface provided in the embodiment of the present invention, and for convenience of explanation, only the portion related to the embodiment of the present invention is shown.
Referring to fig. 4, the server includes:
The parsing module 401 is configured to parse an interface name of a target interface and a server identifier of a target server included in a call target interface instruction if the call target interface instruction input by a user is received;
A sending module 402, configured to send a data request to the target server according to the server identifier, where the data request includes a timestamp for describing a generation time of the data request and an interface name of the target interface, so that the target server determines whether to return a reply message according to the timestamp;
a judging module 403, configured to judge whether the target interface meets a call requirement according to the waiting queue data corresponding to the target interface included in the reply message if the reply message returned by the target server is received;
And the calling module 404 is configured to generate a call request of the target interface if the target interface meets a call requirement, and send the call request of the target interface to the target server to complete the call of the target interface.
Optionally, the waiting queue data includes the number of call requests in the waiting queue corresponding to the target interface and the receiving time of each call request;
Judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message, wherein the judging comprises the steps of;
If the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement;
If the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of a plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number;
By a linear regression model: fitting a corresponding relation between a unit time period and the number of call requests in a preset time period by Y (n) =ax (n) +b, and calculating a linear regression coefficient of the linear regression equation according to a least square method, wherein Y (n) is the number of call requests corresponding to an nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient;
And if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
Optionally, the generating the call request of the target interface includes:
acquiring parameters of an implementation class of the target interface, wherein the parameters of the implementation class are used for determining a specific implementation class in the target interface;
Packaging the interface name of the target interface and the parameters of the implementation class of the target interface by a writeValuesAsString method to generate a json character string;
Encrypting the json character string through a preset secret key to generate an encrypted character string;
Creating a Map set, setting a value of the Map set as the encryption string, setting a Key value of the Map set as the Key, and converting the Map set into a call request.
It may be understood that, in the embodiment of the present invention, by analyzing the instruction of the call target interface, the interface name of the target interface and the server identifier of the target server are obtained, according to the server identifier, a data request is sent to the target server, after receiving the reply message returned by the target server, whether the target interface meets the call requirement is determined according to the waiting queue data corresponding to the target interface included in the reply message, if the target interface meets the call requirement, a call request of the target interface is sent to the target server, so as to determine whether the target interface runs overload before sending the call request of the interface, thereby improving the stability of system running.
Corresponding to the method for responding to the interface call described in the above embodiment, fig. 5 shows a block diagram of a response server for responding to the interface call provided in the embodiment of the present invention, and for convenience of explanation, only a portion related to the embodiment of the present invention is shown.
Referring to fig. 5, the response server of the interface call includes:
a receiving module 501, configured to determine whether to intercept a data request of an external server according to an interface name of a target interface included in the data request if the data request is received;
a reading module 502, configured to, if the data request is not intercepted, analyze a timestamp included in the data request, and if a difference value between a time corresponding to the timestamp and a current time is not greater than a preset time difference threshold, read a number of call requests in a wait queue corresponding to the target interface stored in a Java virtual machine cache;
a generating module 503, configured to add, if the number of call requests in the wait queue is not greater than a preset call number extremum, the number of call requests in the wait queue and a receiving time of each call request into wait queue data, and package the wait queue data to generate a reply message;
a sending module 504, configured to send the reply message to an external server;
And the adding module 505 is configured to add, when receiving a call request of the target interface, a latest received call request to a wait queue of the target interface if the number of call requests in the wait queue is not 0.
Optionally, the response server of the interface call further includes:
And the notification module is used for returning a request overtime notification to the external server if the difference value between the time corresponding to the timestamp and the current time is larger than a preset time difference threshold value, wherein the request overtime notification is used for reminding the external server of overtime abnormality in the communication transmission process of the data request.
Fig. 6 is a schematic diagram of a server of a call interface according to an embodiment of the present invention. As shown in fig. 6, the terminal device 6 of this embodiment includes: a processor 60, a memory 61 and a computer program 62, such as an interface caller, stored in the memory 61 and executable on the processor 60. The processor 60, when executing the computer program 62, implements the steps of the above-described calling method embodiments of the respective interfaces, such as steps 101 to 105 shown in fig. 1. Or the processor 60, when executing the computer program 62, performs the functions of the modules/units of the apparatus embodiments described above, e.g. the functions of the units 401 to 404 shown in fig. 4.
Illustratively, the computer program 62 may be partitioned into one or more modules/units that are stored in the memory 61 and executed by the processor 60 to complete the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions for describing the execution of the computer program 62 in the terminal device 6.
The terminal device 6 may be a computing device such as a desktop computer, a notebook computer, a palm computer, a cloud server, etc. The terminal device may include, but is not limited to, a processor 60, a memory 61. It will be appreciated by those skilled in the art that fig. 6 is merely an example of the terminal device 6 and does not constitute a limitation of the terminal device 6, and may include more or less components than illustrated, or may combine certain components, or different components, e.g., the terminal device may further include an input-output device, a network access device, a bus, etc.
The Processor 60 may be a central processing unit (Central Processing Unit, CPU), other general purpose Processor, digital signal Processor (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), off-the-shelf Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 61 may be an internal storage unit of the terminal device 6, such as a hard disk or a memory of the terminal device 6. The memory 61 may also be an external storage device of the terminal device 6, such as a plug-in hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD) or the like, which are provided on the terminal device 6. Further, the memory 61 may also include both an internal storage unit and an external storage device of the terminal device 6. The memory 61 is used for storing the computer program and other programs and data required by the terminal device. The memory 61 may also be used for temporarily storing data that has been output or is to be output.
FIG. 7 is a schematic diagram of a response server for interface calls according to an embodiment of the present invention. As shown in fig. 7, the terminal device 7 of this embodiment includes: a processor 70, a memory 71 and a computer program 72, e.g. an interface calling program, stored in said memory 71 and executable on said processor 70. The processor 70, when executing the computer program 72, implements the steps of the above-described calling method embodiments of the respective interfaces, such as steps 301 to 311 shown in fig. 3. Or the processor 70, when executing the computer program 72, performs the functions of the modules/units of the apparatus embodiments described above, e.g., the functions of the units 501 to 505 shown in fig. 5.
By way of example, the computer program 72 may be partitioned into one or more modules/units that are stored in the memory 71 and executed by the processor 70 to complete the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions for describing the execution of the computer program 72 in the terminal device 7.
The terminal device 7 may be a computing device such as a desktop computer, a notebook computer, a palm computer, a cloud server, etc. The terminal device may include, but is not limited to, a processor 70, a memory 71. It will be appreciated by those skilled in the art that fig. 7 is merely an example of the terminal device 7 and does not constitute a limitation of the terminal device 7, and may include more or less components than illustrated, or may combine certain components, or different components, e.g., the terminal device may further include an input-output device, a network access device, a bus, etc.
The Processor 70 may be a central processing unit (Central Processing Unit, CPU), or may be another general purpose Processor, a digital signal Processor (DIGITAL SIGNAL Processor, DSP), an Application SPECIFIC INTEGRATED Circuit (ASIC), an off-the-shelf Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 71 may be an internal storage unit of the terminal device 7, such as a hard disk or a memory of the terminal device 7. The memory 71 may be an external storage device of the terminal device 7, such as a plug-in hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD) or the like, which are provided on the terminal device 7. Further, the memory 71 may also include both an internal storage unit and an external storage device of the terminal device 7. The memory 71 is used for storing the computer program as well as other programs and data required by the terminal device. The memory 71 may also be used for temporarily storing data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. In addition, the specific names of the functional units and modules are only for distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
The integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present invention may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention, and are intended to be included in the scope of the present invention.

Claims (8)

1. A method for calling an interface, comprising:
if a call target interface instruction input by a user is received, analyzing an interface name of a target interface contained in the call target interface instruction and a server identification of a target server;
According to the server identification, sending a data request to the target server, wherein the data request comprises a time stamp for describing the generation time of the data request and an interface name of the target interface, so that the target server judges whether to return a reply message according to the time stamp;
if the reply message returned by the target server is received, judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message;
If the target interface does not meet the calling requirement, terminating the calling flow of the interface;
If the target interface meets the call requirement, generating a call request of the target interface, and sending the call request of the target interface to the target server to complete the call of the target interface;
the waiting queue data comprise the number of calling requests in the waiting queue corresponding to the target interface and the receiving time of each calling request;
Judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message, wherein the judging comprises the steps of;
If the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement;
If the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of a plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number;
By a linear regression model: fitting a corresponding relation between a unit time period and the number of call requests in a preset time period by Y (n) =ax (n) +b, and calculating a linear regression coefficient of the linear regression model according to a least square method, wherein Y (n) is the number of call requests corresponding to an nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient;
And if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
2. The method for calling the interface according to claim 1, wherein generating the call request of the target interface includes:
acquiring parameters of an implementation class of the target interface, wherein the parameters of the implementation class are used for determining a specific implementation class in the target interface;
Packaging the interface name of the target interface and the parameters of the implementation class of the target interface by a writeValuesAsString method to generate a json character string;
Encrypting the json character string through a preset secret key to generate an encrypted character string;
Creating a Map set, setting a value of the Map set as the encryption string, setting a Key value of the Map set as the Key, and converting the Map set into a call request.
3. A method of responding to an interface call, comprising:
If a data request of an external server is received, judging whether to intercept the data request according to an interface name of a target interface contained in the data request;
If the data request is not intercepted, analyzing a time stamp contained in the data request, and if the difference value between the time corresponding to the time stamp and the current time is not larger than a preset time difference threshold value, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache;
if the number of the call requests in the waiting queue is greater than a preset call number extreme value, terminating the flow of the response called by the interface;
if the number of the call requests in the waiting queue is not greater than a preset call number extremum, adding the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packaging the waiting queue data, and generating a reply message;
The reply message is sent to an external server;
When receiving the call requests of the target interface, if the number of the call requests in the waiting queue of the target interface is not 0, adding the latest received call requests into the waiting queue;
The waiting queue data comprise the number of calling requests in the waiting queue corresponding to the target interface and the receiving time of each calling request; the external server is further configured to:
If the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement;
If the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of a plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number;
By a linear regression model: fitting a corresponding relation between a unit time period and the number of call requests in a preset time period by Y (n) =ax (n) +b, and calculating a linear regression coefficient of the linear regression model according to a least square method, wherein Y (n) is the number of call requests corresponding to an nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient;
And if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
4. The method of responding to an interface call of claim 3, further comprising:
And if the difference value between the time corresponding to the timestamp and the current time is larger than a preset time difference threshold, returning a request overtime notification to the external server, wherein the request overtime notification is used for reminding the external server of overtime abnormality in the communication transmission process of the data request.
5. A server for calling an interface, comprising a memory and a processor, said memory storing a computer program executable on said processor, characterized in that said processor, when executing said computer program, implements the steps of:
if a target interface calling instruction input by a user is received, analyzing an interface name of a target interface contained in the target interface calling instruction and a server identification of a target server;
According to the server identification, sending a data request to the target server, wherein the data request comprises a time stamp for describing the generation time of the data request and an interface name of the target interface, so that the target server judges whether to return a reply message according to the time stamp;
if the reply message returned by the target server is received, judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message;
If the target interface does not meet the calling requirement, terminating the calling flow of the interface; if the target interface meets the call requirement, generating a call request of the target interface, and sending the call request of the target interface to the target server to complete the call of the target interface;
the waiting queue data comprise the number of calling requests in the waiting queue corresponding to the target interface and the receiving time of each calling request;
Judging whether the target interface meets the calling requirement according to the waiting queue data corresponding to the target interface contained in the reply message, wherein the judging comprises the steps of;
If the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement;
If the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of a plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number;
by a linear regression model: fitting a corresponding relation between a unit time period and the number of call requests in a preset time period by Y (n) =ax (n) +b, and calculating a linear regression coefficient of the linear regression model according to a least square method, wherein Y (n) is the number of call requests corresponding to an nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient;
And if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
6. An interface call response server comprising a memory and a processor, said memory storing a computer program executable on said processor, characterized in that said processor, when executing said computer program, performs the steps of:
When a data request of an external server is received, judging whether to intercept the data request according to an interface name of a target interface contained in the data request;
If the data request is not intercepted, analyzing a time stamp contained in the data request, and if the difference value between the time corresponding to the time stamp and the current time is not larger than a preset time difference threshold value, reading the number of call requests in a waiting queue corresponding to the target interface stored in a Java virtual machine cache;
if the number of the call requests in the waiting queue is greater than a preset call number extreme value, terminating the flow of the response called by the interface;
if the number of the call requests in the waiting queue is not greater than a preset call number extremum, adding the number of the call requests in the waiting queue and the receiving time of each call request into waiting queue data, packaging the waiting queue data, and generating a reply message;
The reply message is sent to an external server;
When receiving the call requests of the target interface, if the number of the call requests in the waiting queue of the target interface is not 0, adding the latest received call requests into the waiting queue;
The waiting queue data comprise the number of calling requests in the waiting queue corresponding to the target interface and the receiving time of each calling request; the external server is further configured to:
If the number of the call requests in the waiting queue is not greater than the first preset number, judging that the target interface meets the call requirement;
If the number of the call requests in the waiting queue is larger than the first preset number and not larger than the second preset number, calculating the number of the call requests corresponding to each of a plurality of unit time periods according to the receiving time of each call request, and generating a corresponding relation between the unit time periods and the number of the call requests, wherein the first preset number is smaller than the second preset number;
By a linear regression model: fitting a corresponding relation between a unit time period and the number of call requests in a preset time period by Y (n) =ax (n) +b, and calculating a linear regression coefficient of the linear regression model according to a least square method, wherein Y (n) is the number of call requests corresponding to an nth unit time period in the preset time period, X (n) is the nth unit time period in the preset time period, a is the linear regression coefficient, and b is an error coefficient;
And if the linear regression coefficient is a non-positive number, judging that the target interface meets the calling requirement.
7. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor realizes the steps of the method according to claim 1 or 2.
8. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor realizes the steps of the method according to claim 3 or 4.
CN201811019901.XA 2018-09-03 2018-09-03 Interface calling method, interface calling response method and server Active CN109189509B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811019901.XA CN109189509B (en) 2018-09-03 2018-09-03 Interface calling method, interface calling response method and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811019901.XA CN109189509B (en) 2018-09-03 2018-09-03 Interface calling method, interface calling response method and server

Publications (2)

Publication Number Publication Date
CN109189509A CN109189509A (en) 2019-01-11
CN109189509B true CN109189509B (en) 2024-04-26

Family

ID=64917871

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811019901.XA Active CN109189509B (en) 2018-09-03 2018-09-03 Interface calling method, interface calling response method and server

Country Status (1)

Country Link
CN (1) CN109189509B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109857575A (en) * 2019-01-18 2019-06-07 深圳壹账通智能科技有限公司 Interface call method, device, electronic equipment and storage medium
CN109872146A (en) * 2019-02-17 2019-06-11 北京意锐新创科技有限公司 Third party's interface call method and system based on two dimension code reading device
CN110187987B (en) * 2019-06-05 2022-02-25 北京百度网讯科技有限公司 Method and apparatus for processing requests
CN112306701B (en) * 2019-07-25 2024-05-03 中移动信息技术有限公司 Service fusing method, device, equipment and storage medium
CN111552577B (en) * 2020-03-24 2023-11-03 福建天泉教育科技有限公司 Method for preventing invalid request from occurring and storage medium
CN111953772B (en) * 2020-08-11 2022-11-22 北京达佳互联信息技术有限公司 Request processing method, device, server and storage medium
CN113204395A (en) * 2021-05-21 2021-08-03 珠海金山网络游戏科技有限公司 Service processing method and device

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104580409A (en) * 2014-12-24 2015-04-29 广州酷狗计算机科技有限公司 Service request processing method, server and terminal
CN105262826A (en) * 2015-10-29 2016-01-20 福建天晴数码有限公司 Method and system for adjusting interface processing amount
CN108279983A (en) * 2016-12-30 2018-07-13 北京国双科技有限公司 A kind of processing method and processing device that interface returns the result
CN108282405A (en) * 2017-12-27 2018-07-13 努比亚技术有限公司 Application programming interfaces buffer memory management method, application server and storage medium
CN108365961A (en) * 2018-01-02 2018-08-03 深圳壹账通智能科技有限公司 The response method and server that interface call method and terminal device, interface call

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150128103A1 (en) * 2013-11-07 2015-05-07 Runscope, Inc. System and method for automating application programming interface integration
US9973584B2 (en) * 2015-10-30 2018-05-15 Hyland Software, Inc. Methods and apparatuses for location-based data access

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104580409A (en) * 2014-12-24 2015-04-29 广州酷狗计算机科技有限公司 Service request processing method, server and terminal
CN105262826A (en) * 2015-10-29 2016-01-20 福建天晴数码有限公司 Method and system for adjusting interface processing amount
CN108279983A (en) * 2016-12-30 2018-07-13 北京国双科技有限公司 A kind of processing method and processing device that interface returns the result
CN108282405A (en) * 2017-12-27 2018-07-13 努比亚技术有限公司 Application programming interfaces buffer memory management method, application server and storage medium
CN108365961A (en) * 2018-01-02 2018-08-03 深圳壹账通智能科技有限公司 The response method and server that interface call method and terminal device, interface call

Also Published As

Publication number Publication date
CN109189509A (en) 2019-01-11

Similar Documents

Publication Publication Date Title
CN109189509B (en) Interface calling method, interface calling response method and server
CN110545260B (en) Cloud management platform construction method based on mimicry structure
EP3234776B1 (en) Data stream processing language for analyzing instrumented software
US20190082026A1 (en) Interface invocation method and apparatus for hybrid cloud
CN109951546B (en) Transaction request processing method, device, equipment and medium based on intelligent contract
US11656902B2 (en) Distributed container image construction scheduling system and method
CN112751847A (en) Interface call request processing method and device, electronic equipment and storage medium
CN112631800A (en) Kafka-oriented data transmission method and system, computer equipment and storage medium
CN112506683A (en) Data processing method, related device, equipment and storage medium
CN115408715A (en) Heterogeneous data processing system, method and equipment based on block chain and IPFS
CN114567650A (en) Data processing method and Internet of things platform system
CN114221995A (en) Service calling method and device and electronic equipment
CN114268667B (en) Data forwarding method, device, computer equipment and storage medium
CN114185743A (en) Data processing method and device, computer equipment and storage medium
CN113259429B (en) Session maintenance management and control method, device, computer equipment and medium
CN113132400B (en) Business processing method, device, computer system and storage medium
CN115694699A (en) Time delay parameter acquisition method and device, electronic equipment and storage medium
CN111935210B (en) Data service method, device, server and storage medium
CN111597041B (en) Calling method and device of distributed system, terminal equipment and server
CN114048059A (en) Method and device for adjusting timeout time of interface, computer equipment and storage medium
CN114338051A (en) Method, device, equipment and medium for acquiring random number by block chain
CN115174665B (en) Login state determining method, device, equipment and storage medium
CN113032168B (en) Data transmission rate dynamic adjustment method and device, electronic equipment and storage medium
CN110876852A (en) Network game data processing method and system of micro-service
CN117539439B (en) Lightweight real-time application development method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant