CN115129490A - Micro-service calling method and device and electronic equipment - Google Patents

Micro-service calling method and device and electronic equipment Download PDF

Info

Publication number
CN115129490A
CN115129490A CN202210772185.2A CN202210772185A CN115129490A CN 115129490 A CN115129490 A CN 115129490A CN 202210772185 A CN202210772185 A CN 202210772185A CN 115129490 A CN115129490 A CN 115129490A
Authority
CN
China
Prior art keywords
calling
service
micro
target
request
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.)
Pending
Application number
CN202210772185.2A
Other languages
Chinese (zh)
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.)
Zhongdian Jinxin Software Co Ltd
Original Assignee
Zhongdian Jinxin Software Co 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 Zhongdian Jinxin Software Co Ltd filed Critical Zhongdian Jinxin Software Co Ltd
Priority to CN202210772185.2A priority Critical patent/CN115129490A/en
Publication of CN115129490A publication Critical patent/CN115129490A/en
Pending legal-status Critical Current

Links

Images

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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • G06F9/548Object oriented; Remote method invocation [RMI]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a micro-service calling method and device and electronic equipment, and relates to the technical field of computers. The method comprises the following steps: and determining a micro-service calling scheme corresponding to the micro-service calling request according to the calling mode identifier in the received micro-service calling request. And when the calling mode identifier indicates that the micro-service calling scheme is a rolling overtime scheme, judging whether to call the first target micro-service according to the current available calling time of the micro-service calling request and the lowest calling time limit of the first target micro-service. And when the first target micro service is not called, stopping the micro service calling process and backing the generated data. According to the method and the system, the calling process is terminated when the calling of the next micro service is judged to be overtime, the generated data is backed off, and then the prompt message that the calling of the client is overtime is returned, so that the problem that the service data is inconsistent with the service data managed by the micro service subsystem side can be effectively avoided.

Description

Micro-service calling method and device and electronic equipment
Technical Field
The application relates to the technical field of computers, in particular to a micro-service calling method and device and electronic equipment.
Background
After the centralized system is split into distributed systems, all the micro-service subsystems under the distributed systems are mutually independent, and service interaction is carried out in a remote calling mode.
When each micro-service subsystem is remotely called, the called micro-service may be actually in the processing process, but the calling party determines that the calling is overtime after waiting for a preset time, and at this time, the calling party gives feedback that the client requests the overtime. In fact, the called micro-service may succeed or fail in processing after a certain period of time. Finally, the problem that the service data at the client side is inconsistent with the service data managed at the micro-service subsystem side is caused.
Disclosure of Invention
The embodiment of the application aims to solve the problem that service data of a client side and service data managed by a micro-service subsystem side are inconsistent in a micro-service calling process.
In a first aspect, the present application provides a method for invoking a micro-service, including:
receiving a micro-service calling request, wherein the micro-service calling request comprises a request identifier and a calling mode identifier;
when the calling mode identifier indicates that the micro-service calling scheme is a rolling overtime scheme, aiming at a first target micro-service to be called currently, determining the lowest calling time limit of the first target micro-service based on the request identifier; the method comprises the following steps that a plurality of target micro services need to be called in a micro service calling request processing process;
judging whether to call the first target micro service or not according to the current available calling time of the micro service calling request and the lowest calling time limit of the first target micro service;
and under the condition that the first target micro service is determined not to be called, stopping the micro service calling process and backing the data generated for the micro service calling request under each target micro service which is successfully called.
In an optional embodiment of the first aspect, the determining whether to invoke the first target microservice according to a currently available invocation time of the microservice invocation request and a minimum invocation time limit of the first target microservice includes:
determining a total calling time limit of the micro-service calling request based on the request identifier;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit, and calling the first target micro-service if the current available calling time is greater than the minimum calling time limit of the first target micro-service.
In an optional embodiment of the first aspect, when the micro-service invocation scheme is a rolling timeout scheme, the method further comprises:
determining the calling sequence and calling information of each target microservice based on the request identifier; the calling information comprises a port number and an internet protocol address;
and sequentially calling each target micro service based on the calling information and the calling sequence of each target micro service.
In an optional embodiment of the first aspect, obtaining the current available invocation time of the micro-service invocation request based on the total invocation time limit comprises:
determining the total actual calling time corresponding to all the target micro-services which are called;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit and the total actual calling time.
In an optional embodiment of the first aspect, obtaining a current available invocation time of the micro-service invocation request based on the total invocation time limit and the total actual invocation time includes:
and subtracting the total actual calling time from the total calling time limit to obtain the current available calling time.
In an optional embodiment of the first aspect, the micro service invocation scheme further includes a retry scheme, and when the micro service invocation scheme is the retry scheme, the method further includes:
and determining the highest calling time limit and the threshold of the retry times of each target micro service based on the request identifier, and calling each target micro service based on the highest calling time limit and the threshold of the retry times of each target micro service.
In an optional embodiment of the first aspect, invoking the respective target microservice according to a highest invocation time limit of each target microservice comprises:
for each target micro service, recording the actual calling time of the target micro service;
when the actual calling time is longer than the highest calling time limit of the target micro service, obtaining the retry times of the target micro service, and detecting the retry times of the target micro service based on a retry time threshold;
if the retry times are smaller than the retry time threshold, the target micro service is called again, and the retry times of the target micro service are updated;
and if the retry times are larger than or equal to the retry time threshold, stopping calling the target micro service.
In an optional embodiment of the first aspect, the method further comprises:
determining the total calling time limit of the micro-service calling request based on the request identifier, counting the total calling time length from calling the first target micro-service, and stopping the calling process if the total calling time length is larger than the total calling time limit;
and sending calling overtime prompt information to the client corresponding to the micro-service calling request.
In a second aspect, an apparatus for invoking micro-services is provided, the apparatus comprising:
the calling request receiving module is used for receiving a micro-service calling request, and the micro-service calling request comprises a request identifier and a calling mode identifier;
the calling scheme determining module is used for determining the lowest calling time limit of the first target micro service based on the request identifier aiming at the first target micro service to be called currently when the calling mode identifier indicates that the micro service calling scheme is a rolling overtime scheme; the method comprises the following steps that a plurality of target micro services need to be called in a micro service calling request processing process;
the micro-service calling module is used for judging whether to call the first target micro-service or not according to the current available calling time of the micro-service calling request and the lowest calling time limit of the first target micro-service; and under the condition that the first target micro service is determined not to be called, stopping the micro service calling process and backing back the data generated for the micro service calling request under each target micro service which is successfully called.
In a third aspect, an electronic device is provided, which includes:
the micro-service calling method comprises a memory, a processor and a program which is stored on the memory and can run on the processor, wherein the micro-service calling method of any embodiment is realized when the processor executes the program.
According to the micro-service calling method, the micro-service calling request is received, and the micro-service calling scheme corresponding to the micro-service calling request is determined according to the request identifier and the calling mode identifier in the micro-service calling request. And when the calling mode identifier indicates that the micro-service calling scheme is a rolling overtime scheme, aiming at a first target micro-service to be called currently, determining the minimum calling time limit of the first target micro-service based on the request identifier, and judging whether to call the first target micro-service or not according to the current available calling time of the micro-service calling request and the minimum calling time limit of the first target micro-service. And under the condition that the first target micro service is determined not to be called, stopping the micro service calling process and backing back the data generated for the micro service calling request under each target micro service which is successfully called. According to the micro-service calling method, on one hand, the lowest calling time limit of each target micro-service is set, and the lowest calling time limit is used for judging when the micro-service is called, so that a distributed core system is prevented from carrying out meaningless calling, the waste of computing resources is reduced, and the micro-service calling efficiency is improved; in a second aspect, according to the method for calling the micro service provided by the application, the set micro service calling mechanism directly terminates the calling process when it is determined that the calling of the next micro service is overtime, backs up data corresponding to the calling request generated in the called micro service, and then returns a prompt message indicating that the calling of the client is overtime, so that the problem that the service data is inconsistent with the service data managed by the micro service subsystem side can be effectively avoided.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments of the present application will be briefly described below.
Fig. 1 is a schematic flowchart of a method for invoking a micro service according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of a method for invoking a micro service according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a micro service invocation device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device for micro service invocation according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the embodiments set forth below in connection with the drawings are exemplary descriptions for explaining technical solutions of the embodiments of the present application, and do not limit the technical solutions of the embodiments of the present application.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should be further understood that the terms "comprises" and/or "comprising," when used in this specification in connection with embodiments of the present application, specify the presence of stated features, information, data, steps, operations, elements, and/or components, but do not preclude the presence or addition of other features, information, data, steps, operations, elements, components, and/or groups thereof, as embodied in the art. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein indicates at least one of the items defined by the term, e.g., "a and/or B" may be implemented as "a", or as "B", or as "a and B".
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
The method, the device, the electronic equipment, the computer readable storage medium and the computer program product for calling the micro-service aim to solve the technical problems that the micro-service calling efficiency is not high enough and a large amount of computing resources are wasted in the prior art.
The technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application will be described below through descriptions of several exemplary embodiments. It should be noted that the following embodiments may be referred to, referred to or combined with each other, and the description of the same terms, similar features, similar implementation steps and the like in different embodiments is not repeated.
The embodiment of the present application provides a method for invoking micro services, which may be applied to a distributed system, where the distributed system includes a distributed core system and at least one micro service subsystem, and the micro service subsystem is provided with at least one micro service, as shown in fig. 1, the method may include:
step S101, receiving a micro-service calling request, wherein the micro-service calling request comprises a request identifier and a calling mode identifier.
In the embodiment of the present application, the target microservices corresponding to each request identifier and the call sequence between the target microservices may be preconfigured in the distributed core system. Meanwhile, the corresponding relation between the calling mode identification and the calling scheme can be configured in advance.
Determining target micro services to be called and a calling sequence among the target micro services according to a request identifier in a received micro service calling request; and determining the micro-service calling scheme specified by the micro-service calling request according to the calling mode identifier.
In some embodiments, the distributed core system may also be directly configured with a correspondence between the request identifier and the micro-service invocation scheme, that is, a corresponding micro-service invocation scheme is preset for each request, and the invocation scheme specified by the micro-service invocation request may be directly determined according to the request identifier. The method for specifically determining the calling scheme is not limited in this application.
In this embodiment of the application, the distributed core system may determine, based on the request identifier, a total invocation time limit corresponding to the micro service invocation request, and determine, based on the invocation mode identifier, a micro service invocation scheme corresponding to the micro service invocation request, where the micro service invocation scheme includes a rolling timeout scheme or a retry scheme.
In this embodiment of the present application, the distributed core system may be preconfigured with a total invocation time limit corresponding to each request identifier. For the microservice calling request, the total calling time limit corresponding to the microservice calling request may refer to the overall highest calling time limit from the time when the first microservice corresponding to the microservice calling request is processed to the time when the last microservice is processed and the processing result is received.
Specifically, different micro service invocation schemes may correspond to different invocation mode identifiers, and the distributed core system may determine the corresponding invocation scheme according to the invocation mode identifier in the received micro service invocation request.
For example, the calling mode identifier may include a first identifier and a second identifier, the first identifier may be used to characterize the micro-service call request using a rolling timeout scheme, and the second identifier may be used to characterize the micro-service call request using a retry scheme.
The specific flow steps of the scroll timeout scheme and the retry scheme will be described in detail later.
Step S102, when the calling mode identification indicates that the micro-service calling scheme is the rolling overtime scheme, aiming at a first target micro-service to be called currently, determining the lowest calling time limit of the first target micro-service based on the request identification.
And calling a plurality of target micro services in the micro service calling request processing process.
The first target microservice may be a target microservice to be called currently in target microservices corresponding to microservice requests, the "first" is used for representing that the first target microservice is the target microservice to be called currently, and when the current first target microservice is called completely, a next target microservice in a calling sequence may be used as a new first target microservice.
In this embodiment of the application, the distributed core system may further pre-configure a minimum invocation time limit corresponding to each micro service. The distributed core system can determine a target microservice corresponding to the microservice calling request based on the request identifier and then determine a minimum calling time limit for each target microservice.
Specifically, for a first target micro service to be currently called, the minimum calling time limit of the first target micro service may be determined based on the request identifier.
For each micro service, the minimum call time limit may refer to a minimum call time limit required for calling the micro service, and is a preset theoretical value. In an actual application scenario, the actual call time of the microservice may be greater than or equal to the minimum call time limit, depending on the complexity of the data to be processed.
In this embodiment of the present application, when the micro-service invocation scheme is a rolling timeout scheme, the method may further include the following steps:
(1) determining the calling sequence and calling information of each target microservice based on the request identifier; the invocation information includes a port number and an internet protocol address.
Specifically, target microservices corresponding to the request identifiers and call sequences of the target microservices to the request identifiers may be preconfigured in the distributed core system. It will be appreciated that different request identifications may correspond to the same target microservice or to different target microservices. When different request identifiers correspond to the same target microservices, the target microservices may have different calling orders for different request identifiers.
For example, assume that request identification a corresponds to target microservice 1, target microservice 2, and target microservice 3; the request identification b may likewise correspond to target microservice 1, target microservice 2 and target microservice 3.
However, the call sequence corresponding to the request identifier a may be "target microservice 1, target microservice 2, and target microservice 3", and the call sequence corresponding to the request identifier b may be "target microservice 2, target microservice 1, and target microservice 3".
In the embodiment of the present application, each target microservice may have corresponding invocation information, which includes, but is not limited to, a port number and an internet protocol address.
(2) And sequentially calling each target micro service based on the calling information and the calling sequence of each target micro service.
Step S103, judging whether to call the first target micro service according to the current available calling time of the micro service calling request and the minimum calling time limit of the first target micro service; and under the condition that the first target micro service is determined not to be called, stopping a micro service calling process and backing data generated for the micro service calling request under each target micro service which is successfully called.
Each target micro service that has been successfully called may refer to a target micro service that has completed being called before a first target micro service to be currently called. The target micro service which finishes the calling generates corresponding calling data, and if the micro service calling flow is stopped, the generated data can be backed, namely, the data is returned to the client side which sends the micro service calling request.
In this embodiment of the present application, determining whether to invoke the first target microservice according to the current available invocation time of the microservice invocation request and the minimum invocation time limit of the first target microservice may include:
determining a total calling time limit of the micro-service calling request based on the request identifier;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit, and calling the first target micro-service if the current available calling time is greater than the minimum calling time limit of the first target micro-service.
The total calling time limit may be a time threshold for calling the target micro service corresponding to all the micro service calling requests. The current available invocation time of the microservice invocation request may be the available invocation time corresponding to the first target microservice currently to be invoked. The current callable time corresponding to the first target microservice may be obtained based on the total call time limit. The current available invocation time of each target microservice may be used to characterize the remaining time available for use of that target microservice in the total invocation time limit.
It can be understood that, as the target micro services summarized by the micro service invocation requests are invoked in sequence, the current available invocation time corresponding to the micro service invocation requests is dynamically changed.
Before the first target micro service is called, whether the available remaining time of the first target micro service in the total calling time limit is larger than the lowest calling time limit of the target micro service can be judged by comparing the current available calling time of the first target micro service with the lowest calling time limit.
If the current available calling time is larger than the lowest calling time limit, calling a first target micro service; and if the available calling time is less than or equal to the lowest calling time limit, stopping calling the flow.
In this embodiment of the present application, the calling condition of the first target microservice may also be set to be that the current available calling time is greater than or equal to the minimum calling time limit, which is not limited in this application.
In this embodiment of the present application, obtaining the current available call time of the microservice call request based on the total call time limit may include: determining the total actual calling time corresponding to all the target micro-services which are called; and acquiring the current available calling time of the micro-service calling request based on the total calling time limit and the total actual calling time.
Specifically, the total actual calling time may be subtracted from the total calling time limit to obtain the current available calling time.
In an actual application scenario, when the first target microservice in the calling sequence corresponding to the microservice calling request is called, since there is no target microservice which has been called before the target microservice, the total actual calling time is 0, and the current available calling time of the first target microservice is the total calling time limit.
For other target microservices except the first target microservice in the calling sequence, the total actual calling time corresponding to all target microservices which are already called before the current target microservice in the calling sequence can be determined, and the total calling time is subtracted by the actual calling time to obtain the current available calling time of the current target microservice.
In the embodiment of the present application, the current available call time corresponding to each target microservice is dynamically changed, and may be determined according to the total actual call time and the total call time limit spent by the microservice that has completed the call before the target microservice.
In one example, one microservice invocation request corresponds to two target microservices, A and B, with a total invocation time limit of 200 s.
Assuming that a takes 100s to complete the call, the total call time limit may be subtracted by the time taken for a to complete the call, and the current available call time for B is calculated to be 100 s. If the corresponding lowest calling time limit of B is 50s, B can be continuously called; if the minimum calling time limit of B is 120s and is larger than the available calling time 100s, then B is not called any more, and the execution of the micro-service calling request is finished.
According to the micro-service calling method, the micro-service calling request is received, and the micro-service calling scheme corresponding to the micro-service calling request is determined according to the request identifier and the calling mode identifier in the micro-service calling request. And when the calling mode identifier indicates that the micro-service calling scheme is a rolling overtime scheme, determining the minimum calling time limit of the first target micro-service based on the request identifier aiming at the first target micro-service to be called currently, and judging whether to call the first target micro-service according to the current available calling time of the micro-service calling request and the minimum calling time limit of the first target micro-service. And under the condition that the first target micro service is determined not to be called, stopping the micro service calling process and backing back the data generated for the micro service calling request under each target micro service which is successfully called.
According to the micro-service calling method, on one hand, the lowest calling time limit of each target micro-service is set, and the lowest calling time limit is used for judging when the micro-service is called, so that a distributed core system is prevented from carrying out meaningless calling, the waste of computing resources is reduced, and the micro-service calling efficiency is improved; in a second aspect, according to the method for calling the micro service provided by the application, the set micro service calling mechanism directly terminates the calling process when it is determined that the calling of the next micro service is overtime, backs up data corresponding to the calling request generated in the called micro service, and then returns a prompt message indicating that the calling of the client is overtime, so that the problem that the service data is inconsistent with the service data managed by the micro service subsystem side can be effectively avoided.
The embodiment of the present application provides a possible implementation manner, and when the micro-service invocation scheme is a retry scheme, the method further includes:
a maximum call limit and retry number threshold for each target microservice may be determined based on the request identification, and each target microservice may be invoked based on the maximum call limit and retry number threshold for each target microservice.
The maximum calling time limit of the target micro service may be preset, and is used to represent the maximum available time for calling the target micro service, and may be a fixed value.
In the embodiment of the application, the request sender can select the micro-service calling scheme according to actual requirements, and the distributed core system can call the micro-service according to the calling scheme specified by the request sender, so that the application scene is expanded, and the diversified application requirements of each request sender are further met.
In this embodiment of the present application, invoking each target microservice according to the highest invocation time limit of each target microservice may include the following steps:
(1) for each target microservice, the actual invocation time of the target microservice is recorded.
Specifically, for each target microservice, a preset timer may be used to record the actual call time taken by the target microservice from the start of the call to the target microservice.
It will be appreciated that the actual call time is dynamically changed during the call to the target microservice, starting from the time the call is started, until the call is completed or until the actual call time is greater than the maximum call time limit for the target microservice.
(2) When the actual calling time is longer than the highest calling time limit of the target micro service, obtaining the retry times of the target micro service, and detecting the retry times of the target micro service based on a retry time threshold;
if the retry times are smaller than the retry time threshold value, the distributed core system recalls the target micro service and updates the retry times of the target micro service;
and if the retry number is greater than or equal to the threshold number, stopping calling the target micro service.
In the embodiment of the application, before retry, whether the retry number of the target micro service is smaller than the threshold number of times or not can be detected, and whether the total calling time limit corresponding to the micro service calling request is used up or not can be verified. If the total calling time limit is used up, the calling process can be directly stopped.
The embodiment of the present application provides a possible implementation manner, and the method for invoking micro-services provided by the present application may further include:
counting the total calling time length from calling the first target micro service, and stopping the calling process if the total calling time length is larger than the total calling time limit; and sending calling overtime prompt information to the client corresponding to the micro-service calling request by the distributed core system.
The method for calling the micro-service, as shown in fig. 2, may include the following steps:
step S201, a distributed core system receives a micro-service calling request, wherein the micro-service calling request comprises a request identifier and a calling mode identifier;
step S202, the distributed core system determines the total calling time limit corresponding to the micro-service calling request based on the request identifier, and determines the micro-service calling scheme corresponding to the micro-service calling request based on the calling mode identifier, wherein the micro-service calling scheme comprises a rolling overtime scheme or a retry scheme;
step S203, judging whether the micro-service calling scheme is a rolling overtime scheme, if so, entering step S204, otherwise, entering step S206;
step S204, the distributed core system determines the lowest calling time limit of each target micro service based on the request identifier;
step S205, for each target micro service, acquiring the current available calling time corresponding to the target micro service based on the total calling time limit, if the current available calling time is larger than the lowest calling time limit of the target micro service, calling the target micro service, otherwise, stopping the calling process; specifically, the total actual calling time corresponding to all the target microservices which have been called can be determined, and the total actual calling time is subtracted from the total calling time limit to obtain the current available calling time corresponding to the target microservices.
Step S206, the distributed core system determines the highest calling time limit and the threshold value of the retry times of each target micro service based on the request identification;
step S207, calling each target micro service based on the highest calling time limit and retry time threshold of each target micro service; specifically, for each target micro service, recording the actual calling time of the target micro service; when the actual calling time is longer than the highest calling time limit of the target micro service, obtaining the retry times of the target micro service, and detecting the retry times of the target micro service based on a retry time threshold; if the retry times are smaller than the retry time threshold value, the distributed core system recalls the target micro service and updates the retry times of the target micro service; and if the retry number is greater than or equal to the retry number threshold value, stopping calling the target micro service.
As an example, in an actual application scenario, the method for invoking the micro service provided by the present application may include the following steps:
the first step is as follows: the distributed core system receives a micro-service call request, and the micro-service call request can comprise a request identifier and a call mode identifier. The calling mode identifier may include a first identifier and a second identifier, the first identifier may be used to characterize the micro-service call request using a rolling timeout scheme, and the second identifier may be used to characterize the micro-service call request using a retry scheme.
The total calling time limit corresponding to each request identifier, and the calling information and calling sequence of the corresponding target microservice can be configured in advance. The distributed core system may determine a total invocation time limit and corresponding invocation information and invocation order for each target microservice based on the request identification.
In addition, the calling information and the calling sequence of the target micro service to be called can also be directly given by the micro service calling request, and the application is not limited.
And secondly, acquiring the lowest calling time limit or the highest calling time limit of the first target micro service corresponding to the micro service calling request according to the determined micro service calling scheme.
Specifically, if a rolling timeout scheme is used, the lowest call time limit is obtained, and if a retry scheme is used, the highest call time limit is obtained. At the same time, the total call duration of the micro-service call request from the first target micro-service may be recorded by the first timer.
Third, the first target microservice in the calling sequence is executed, and the actual calling time of the target microservice can be recorded by using a second timer. According to different calling schemes, the calling steps are as follows:
(1) if the calling scheme is a rolling overtime scheme, before the first target micro-service is called, whether the available execution time of the target micro-service is larger than the lowest calling time limit of the target micro-service is judged. Since the target microservice is the first invoked microservice, the current available invocation time of the target microservice is the total execution time limit of the microservice invocation request, so that whether the total invocation time limit is greater than the minimum invocation time limit of the microservice can be compared, if so, the first target microservice is invoked, and if not, the invocation flow is stopped.
(2) If the calling scheme is a timeout retry scheme, directly calling the first target micro-service until a calling result is received, or the actual calling time of the first target micro-service recorded by the second timer reaches the highest calling time limit of the micro-service. When the actual calling time of the first target micro service reaches the highest calling time limit of the target micro service, judging whether the retry number of the target micro service reaches a threshold number or not so as to determine whether to continuously retry or not. If the retry times are larger than the threshold value of times, stopping calling, returning prompt information to the initiating end of the request, and prompting that overtime occurs and calling is not finished.
In any of the above calling schemes, if the total calling time recorded by the first timer reaches the total calling time limit of the micro-service calling request, the calling process is stopped.
And fourthly, after the first target micro service is executed, the actual calling time of the first target micro service recorded by the second timer is counted into the total actual calling time.
The second target microservice in the preset calling sequence is called, and the actual calling time of the second microservice can be recorded by a second timer (or a new timer) after being cleared.
According to different calling schemes, the calling steps are as follows:
(1) if the calling scheme is a rolling overtime scheme, before calling a second target micro-service, judging whether the available execution time of the target micro-service is greater than the lowest calling time limit of the target micro-service. The current available invocation time of the target microservice is the total execution time limit of the microservice invocation request minus the total actual invocation time (the current total actual invocation time is the actual invocation time of the first target microservice). The current available call time may be compared to determine whether the current available call time is greater than the minimum call time limit of the microservice, and if so, a second target microservice may be called, and if not, the call flow may be stopped.
(2) And if the calling scheme is a timeout retry scheme, directly calling the second target micro service until a calling result is received, or the actual calling time of the second target micro service recorded by the second timer reaches the highest calling time limit of the micro service. When the actual calling time of the second target micro service reaches the highest calling time limit of the target micro service, judging whether the retry number of the target micro service reaches a threshold number or not so as to determine whether to continuously retry. If the retry times are larger than the threshold value of times, stopping calling, returning prompt information to the initiating end of the request, and prompting that overtime occurs and calling is not finished.
Similarly, no matter which calling scheme is used, if the total calling time recorded by the first timer reaches the total calling time limit of the micro-service calling request, the calling process is stopped.
And the like, wherein at any moment, the total calling time recorded by the first timer reaches the total calling time limit of the micro-service calling request, and the calling process is stopped.
An embodiment of the present application provides a micro service invoking device, and as shown in fig. 3, the micro service invoking device 30 may include: a call request receiving module 301, a call scenario determination module 302, and a micro-service calling module 303, wherein,
a calling request receiving module 301, configured to receive a micro-service calling request, where the micro-service calling request includes a request identifier and a calling mode identifier;
a calling scheme determining module 302, configured to determine, for a first target microservice to be currently called, a lowest calling time limit of the first target microservice based on the request identifier when the calling mode identifier indicates that the microservice calling scheme is the rolling timeout scheme; wherein, a plurality of target micro services need to be called in the micro service calling request processing process;
the micro-service calling module 303 is configured to determine whether to call the first target micro-service according to the current available call time of the micro-service call request and the minimum call time limit of the first target micro-service; and under the condition that the first target micro service is determined not to be called, stopping a micro service calling process and backing data generated for the micro service calling request under each target micro service which is successfully called.
The micro-service calling device receives the micro-service calling request, and determines the micro-service calling scheme corresponding to the micro-service calling request according to the request identifier and the calling mode identifier in the micro-service calling request. And when the calling mode identifier indicates that the micro-service calling scheme is a rolling overtime scheme, determining the minimum calling time limit of the first target micro-service based on the request identifier aiming at the first target micro-service to be called currently, and judging whether to call the first target micro-service according to the current available calling time of the micro-service calling request and the minimum calling time limit of the first target micro-service. And under the condition that the first target micro service is determined not to be called, stopping the micro service calling process and backing back the data generated for the micro service calling request under each target micro service which is successfully called. According to the micro-service calling method, on one hand, the lowest calling time limit of each target micro-service is set, and the lowest calling time limit is used for judging when the micro-service is called, so that a distributed core system is prevented from carrying out meaningless calling, the waste of computing resources is reduced, and the micro-service calling efficiency is improved; in a second aspect, according to the method for calling the micro service provided by the application, the set micro service calling mechanism directly terminates the calling process when it is determined that the calling of the next micro service is overtime, backs up data corresponding to the calling request generated in the called micro service, and then returns a prompt message indicating that the calling of the client is overtime, so that the problem that the service data is inconsistent with the service data managed by the micro service subsystem side can be effectively avoided.
In this embodiment of the present application, determining whether to invoke the first target microservice according to the currently available invocation time of the microservice invocation request and the minimum invocation time limit of the first target microservice includes:
determining a total calling time limit of the micro-service calling request based on the request identifier;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit, and calling the first target micro-service if the current available calling time is greater than the minimum calling time limit of the first target micro-service.
In this embodiment of the present application, when the micro-service invocation scheme is a rolling timeout scheme, the method further includes:
determining the calling sequence and calling information of each target microservice based on the request identifier; the calling information comprises a port number and an internet protocol address;
and sequentially calling each target micro service based on the calling information and the calling sequence of each target micro service.
In this embodiment of the present application, obtaining the current available invocation time of the micro-service invocation request based on the total invocation time limit includes:
determining the total actual calling time corresponding to all the target micro-services which are called;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit and the total actual calling time.
In the embodiment of the present application, obtaining the current available call time of the micro-service call request based on the total call time limit and the total actual call time includes:
and subtracting the total actual calling time from the total calling time limit to obtain the current available calling time.
In an embodiment of the present application, the micro service invocation scheme further includes a retry scheme, and when the micro service invocation scheme is the retry scheme, the method further includes:
and determining the highest calling time limit and the threshold of the retry times of each target micro service based on the request identifier, and calling each target micro service based on the highest calling time limit and the threshold of the retry times of each target micro service.
In the embodiment of the present application, invoking each target microservice according to the highest invocation time limit of each target microservice comprises:
for each target micro service, recording the actual calling time of the target micro service;
when the actual calling time is longer than the highest calling time limit of the target micro service, obtaining the retry times of the target micro service, and detecting the retry times of the target micro service based on a retry time threshold;
if the retry times are smaller than the retry time threshold, the target micro service is called again, and the retry times of the target micro service are updated;
and if the retry number is greater than or equal to the retry number threshold value, stopping calling the target micro service.
In an embodiment of the present application, the method further comprises:
determining the total calling time limit of the micro-service calling request based on the request identifier, counting the total calling time from the beginning of calling the first target micro-service, and stopping the calling process if the total calling time is greater than the total calling time limit;
and sending calling overtime prompt information to the client corresponding to the micro-service calling request.
The apparatus of the embodiment of the present application may execute the method provided by the embodiment of the present application, and the implementation principle is similar, the actions executed by the modules in the apparatus of the embodiments of the present application correspond to the steps in the method of the embodiments of the present application, and for the detailed functional description of the modules of the apparatus, reference may be specifically made to the description in the corresponding method shown in the foregoing, and details are not repeated here.
The embodiment of the present application provides an electronic device (computer apparatus/device/system), including a memory, a processor and a computer program stored on the memory, where the processor executes the computer program to implement the steps of the micro service invoking method, and compared with the related art, the method can implement: on one hand, the lowest calling time limit of each target micro-service is set, and the lowest calling time limit is used for judgment during calling, so that a distributed core system is prevented from carrying out meaningless calling, the waste of computing resources is reduced, and the efficiency of calling the micro-service is improved; in a second aspect, according to the method for calling the micro-service provided by the application, the set micro-service calling mechanism directly terminates the calling process when it is determined that the calling of the next micro-service is overtime, backs up data corresponding to the calling request generated in the called micro-service, and then returns a prompt message indicating that the calling of the client is overtime, so that the problem that the service data is inconsistent with the service data managed by the micro-service subsystem side can be effectively avoided.
In an alternative embodiment, an electronic device is provided, as shown in fig. 4, the electronic device 4000 shown in fig. 4 comprising: a processor 4001 and a memory 4003. Processor 4001 is coupled to memory 4003, such as via bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, and the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data. It should be noted that the transceiver 4004 is not limited to one in practical applications, and the structure of the electronic device 4000 is not limited to the embodiment of the present application.
The Processor 4001 may be a CPU (Central Processing Unit), a general-purpose Processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 4001 may also be a combination that performs a computational function, including, for example, a combination of one or more microprocessors, a combination of a DSP and a microprocessor, or the like.
Bus 4002 may include a path that carries information between the aforementioned components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 4002 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 4, but this does not indicate only one bus or one type of bus.
The Memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), a magnetic Disc storage medium, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and that can be Read by a computer, without limitation.
The memory 4003 is used for storing computer programs for executing the embodiments of the present application, and is controlled by the processor 4001 to execute. The processor 4001 is used to execute computer programs stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.
Among them, electronic devices include but are not limited to: mobile terminals such as mobile phones, notebook computers, PADs, etc., and fixed terminals such as digital TVs, desktop computers, etc.
Embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, and when being executed by a processor, the computer program may implement the steps and corresponding contents of the foregoing method embodiments.
Embodiments of the present application further provide a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps and corresponding contents of the foregoing method embodiments can be implemented.
The terms "first," "second," "third," "fourth," "1," "2," and the like in the description and in the claims of the present application and in the above-described drawings (if any) are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in other sequences than described or illustrated herein.
It should be understood that, although each operation step is indicated by an arrow in the flowchart of the embodiment of the present application, the implementation order of the steps is not limited to the order indicated by the arrow. In some implementation scenarios of the embodiments of the present application, the implementation steps in the flowcharts may be performed in other sequences as desired, unless explicitly stated otherwise herein. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on an actual implementation scenario. Some or all of these sub-steps or stages may be performed at the same time, or each of these sub-steps or stages may be performed at different times. In a scenario where execution times are different, an execution sequence of the sub-steps or the phases may be flexibly configured according to requirements, which is not limited in the embodiment of the present application.
The foregoing is only an optional implementation manner of a part of implementation scenarios in this application, and it should be noted that, for those skilled in the art, other similar implementation means based on the technical idea of this application are also within the protection scope of the embodiments of this application without departing from the technical idea of this application.

Claims (10)

1. A method for invoking a microservice, the method comprising:
receiving a micro-service calling request, wherein the micro-service calling request comprises a request identifier and a calling mode identifier;
when the calling mode identification indicates that the micro-service calling scheme is a rolling overtime scheme, aiming at a first target micro-service to be called currently, determining the lowest calling time limit of the first target micro-service based on the request identification; wherein, a plurality of target micro services need to be called in the micro service calling request processing process;
judging whether to call the first target micro service according to the current available calling time of the micro service calling request and the lowest calling time limit of the first target micro service;
and under the condition that the first target micro service is determined not to be called, stopping a micro service calling process and backing data generated for the micro service calling request under each target micro service which is successfully called.
2. The method of claim 1, wherein the determining whether to invoke the first target microservice according to the current available invocation time of the microservice invocation request and the minimum invocation time limit of the first target microservice comprises:
determining a total calling time limit of the micro-service calling request based on the request identification;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit, and calling the first target micro-service if the current available calling time is greater than the lowest calling time limit of the first target micro-service.
3. The microservice calling method of claim 1, wherein when the microservice calling scheme is the rolling timeout scheme, the method further comprises:
determining the calling sequence and calling information of each target microservice based on the request identification; the calling information comprises a port number and an internet protocol address;
and sequentially calling each target micro service based on the calling information and the calling sequence of each target micro service.
4. The micro-service invocation method according to claim 2, wherein said obtaining the current available invocation time of said micro-service invocation request based on said total invocation time limit comprises:
determining the total actual calling time corresponding to all the target micro-services which are called;
and acquiring the current available calling time of the micro-service calling request based on the total calling time limit and the total actual calling time.
5. The method of claim 4, wherein the obtaining the current available call time of the micro-service call request based on the total call time limit and the total actual call time comprises:
and subtracting the total actual calling time from the total calling time limit to obtain the current available calling time.
6. The micro-service invocation method according to claim 1, wherein said micro-service invocation scheme further comprises a retry scheme, and when said micro-service invocation scheme is the retry scheme, said method further comprises:
and determining the highest calling time limit and the threshold of the retry times of each target micro service based on the request identifier, and calling each target micro service based on the highest calling time limit and the threshold of the retry times of each target micro service.
7. The method for calling the microservice according to claim 6, wherein the calling the target microservices according to the highest calling time limit of each target microservice comprises:
for each target micro service, recording the actual calling time of the target micro service;
when the actual calling time is larger than the highest calling time limit of the target micro service, obtaining the retry times of the target micro service, and detecting the retry times of the target micro service based on the retry times threshold;
if the retry times are smaller than the retry times threshold value, the target micro service is called again, and the retry times of the target micro service are updated;
and if the retry times are greater than or equal to the retry time threshold, stopping calling the target micro service.
8. The microservice invocation method according to any of claims 1-7, wherein the method further comprises:
determining a total calling time limit of the micro-service calling request based on the request identifier, counting the total calling time length from calling a first target micro-service, and stopping a calling process if the total calling time length is larger than the total calling time limit;
and sending calling overtime prompt information to a client corresponding to the micro-service calling request.
9. A microservice invocation device, comprising:
the calling request receiving module is used for receiving a micro-service calling request, and the micro-service calling request comprises a request identifier and a calling mode identifier;
a calling scheme determining module, configured to determine, for a first target microservice to be currently called, a lowest calling time limit of the first target microservice based on the request identifier when the calling mode identifier indicates that the microservice calling scheme is a rolling timeout scheme; wherein, a plurality of target micro services need to be called in the micro service calling request processing process;
the micro-service calling module is used for judging whether to call the first target micro-service or not according to the current available calling time of the micro-service calling request and the lowest calling time limit of the first target micro-service; and under the condition that the first target micro service is determined not to be called, stopping a micro service calling process and backing data generated for the micro service calling request under each target micro service which is successfully called.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to implement the steps of the method of any of claims 1-8.
CN202210772185.2A 2022-06-30 2022-06-30 Micro-service calling method and device and electronic equipment Pending CN115129490A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210772185.2A CN115129490A (en) 2022-06-30 2022-06-30 Micro-service calling method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210772185.2A CN115129490A (en) 2022-06-30 2022-06-30 Micro-service calling method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN115129490A true CN115129490A (en) 2022-09-30

Family

ID=83381081

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210772185.2A Pending CN115129490A (en) 2022-06-30 2022-06-30 Micro-service calling method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN115129490A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109684105A (en) * 2018-12-18 2019-04-26 中国平安人寿保险股份有限公司 Method, equipment and the storage medium that request is controlled under micro services framework
US20200045117A1 (en) * 2018-08-02 2020-02-06 International Business Machines Corporation Dynamic backoff and retry attempts based on incoming request
CN113783822A (en) * 2020-06-03 2021-12-10 北京沃东天骏信息技术有限公司 Service timeout management method and device
CN114253673A (en) * 2021-12-17 2022-03-29 中电金信软件有限公司 Transaction processing method and transaction processing device of distributed system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200045117A1 (en) * 2018-08-02 2020-02-06 International Business Machines Corporation Dynamic backoff and retry attempts based on incoming request
CN109684105A (en) * 2018-12-18 2019-04-26 中国平安人寿保险股份有限公司 Method, equipment and the storage medium that request is controlled under micro services framework
CN113783822A (en) * 2020-06-03 2021-12-10 北京沃东天骏信息技术有限公司 Service timeout management method and device
CN114253673A (en) * 2021-12-17 2022-03-29 中电金信软件有限公司 Transaction processing method and transaction processing device of distributed system

Similar Documents

Publication Publication Date Title
CN111459659A (en) Data processing method, device, scheduling server and medium
EP3489825A1 (en) Method, apparatus and computer readable storage medium for processing service
CN111163130B (en) Network service system and data transmission method thereof
CN111737022A (en) Interface calling method, system, equipment and medium based on micro-service
CN107645476B (en) Request processing method and device
CN108429703B (en) DHCP client-side online method and device
CN108647102B (en) Service request processing method and device of heterogeneous system and electronic equipment
CN112818336A (en) Data access method, data access device and computer readable storage medium
CN111913815A (en) Call request processing method and device, electronic equipment and readable storage medium
CN115129490A (en) Micro-service calling method and device and electronic equipment
CN108830724B (en) Resource data packet processing method and terminal equipment
CN111078382A (en) Command timeout processing method and device
CN111262794B (en) Gateway flow control method and device
CN110008010B (en) System calling method, device, equipment and readable storage medium
CN113986995A (en) Request distribution method and device, storage medium and electronic equipment
CN111061576B (en) Method and system for creating entity object
CN110351334B (en) Service request processing method and device and payment service request processing method and device
CN111309744A (en) Object processing method and device, electronic equipment and computer readable storage medium
CN112799791A (en) Method and device for calling distributed lock, electronic equipment and storage medium
CN112612625A (en) Service calling method and device
CN112231090A (en) Application process management method and device and terminal equipment
CN112532699B (en) Data port updating method and device, electronic equipment and readable storage medium
CN112511603B (en) Data port updating method and device, electronic equipment and readable storage medium
CN116010126B (en) Service aggregation method, device and system
CN108563523B (en) Information callback method, 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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20220930