CN113641518A - Service calling method, device and storage medium - Google Patents

Service calling method, device and storage medium Download PDF

Info

Publication number
CN113641518A
CN113641518A CN202110937264.XA CN202110937264A CN113641518A CN 113641518 A CN113641518 A CN 113641518A CN 202110937264 A CN202110937264 A CN 202110937264A CN 113641518 A CN113641518 A CN 113641518A
Authority
CN
China
Prior art keywords
request
calling
interface
call
remote
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
CN202110937264.XA
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.)
Jingdong Technology Holding Co Ltd
Original Assignee
Jingdong Technology Holding 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 Jingdong Technology Holding Co Ltd filed Critical Jingdong Technology Holding Co Ltd
Priority to CN202110937264.XA priority Critical patent/CN113641518A/en
Publication of CN113641518A publication Critical patent/CN113641518A/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
    • 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/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • 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/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45579I/O management, e.g. providing access to device drivers or storage
    • 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/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45587Isolation or security of virtual machine instances

Abstract

The present disclosure relates to a service calling method, device and storage medium, the method comprising: calling a remote calling frame from a micro service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved.

Description

Service calling method, device and storage medium
Technical Field
The present disclosure relates to the field of communications, and in particular, to a service invocation method, device and storage medium.
Background
A microservice (or microservice architecture) is a cloud-native architecture approach that includes multiple applications, where a single application is made up of many loosely-coupled and independently-deployable smaller components or services. In the micro-service architecture, the services are fine-grained, the protocol is light-weight, and meanwhile, the micro-service has the advantages of easiness in development and maintenance, high starting speed of a single micro-service, easiness in deployment of local modification and the like, so that the micro-service is widely applied. At present, micro services are mutually called, that is, when one service calls another service, the user is required to complete identity authentication in a mode of putting a token in a request parameter every time so as to call another service.
In the course of implementing the disclosed concept, the inventors found that there are at least the following technical problems in the related art: when another service is called by one service, the user is required to put the token in the request parameter each time, and the like.
Disclosure of Invention
In order to solve the technical problem or at least partially solve the technical problem, embodiments of the present disclosure provide a service invocation method, device and storage medium, so as to solve at least the problems in the prior art that a user is required to place a token in a request parameter each time another service is invoked through one service.
The purpose of the present disclosure is realized by the following technical scheme:
in a first aspect, an embodiment of the present disclosure provides a service invocation method, including: calling a remote calling frame from a micro service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token.
In an exemplary embodiment, the invoking a remote invocation framework from a micro service center to create a remote invocation interface class corresponding to the remote invocation framework includes: receiving a class creating instruction sent by the target object through the remote calling frame, and defining a class statement, a constructor, a variable and a method corresponding to the remote calling interface class according to the class creating instruction; and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class to create the remote call interface class.
In an exemplary embodiment, the implementing the request interception interface in the remote invocation interface class includes: receiving an interface implementation instruction, and performing template conversion operation on the interface implementation instruction in an interface annotation mode through the remote call frame; and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
In an exemplary embodiment, before the implementing the request interception interface in the remote invocation interface class, the method further includes: receiving an interface creating instruction through the remote calling frame, and defining an interface statement, a constant and a method corresponding to the request intercepting interface according to the interface creating instruction; and packaging the interface statement, the constant and the method corresponding to the request interception interface to create the request interception interface.
In one exemplary embodiment, the writing the call token into a call request by a request function includes: calling a service isolation component to configure a program request object corresponding to the remote call framework; and writing the call token into the call request through the request function and the program request object.
In an exemplary embodiment, before the invoking the request container by the hijack object algorithm to obtain the access request sent by the target object and determine the invocation token carried in the access request, the method further includes: under the condition of logging in a gateway service, sending an authentication request to a token authentication service so that the token authentication service generates the calling token according to the authentication request; sending the access request through the target object, where the access request includes the invocation token, if the token authentication service returns the invocation token.
In an exemplary embodiment, after the request container is called by the hijack object algorithm to obtain the access request sent by the target object and the call token carried in the access request is determined, the method further includes: writing the call token into a request parameter through a built-in function; and calling the target service according to the request interception interface and the request parameter carrying the calling token.
In an exemplary embodiment, the invoking a target service according to the request interception interface and the invocation request carrying the invocation token includes: calling the target service in an asynchronous calling mode under the condition that the target service is busy; and calling the target service in a synchronous calling mode under the condition that the target service is idle.
In a second aspect, an embodiment of the present disclosure provides a service invocation apparatus, including: the first calling module is used for calling a remote calling frame from a micro service center so as to create a remote calling interface class corresponding to the remote calling frame; the realization module is used for realizing a request interception interface in the remote calling interface class; the second calling module is used for calling the request container through a hijack object algorithm to acquire an access request sent by a target object and determine a calling token carried in the access request; and the third calling module is used for writing the calling token into a calling request through a request function and calling a target service according to the request intercepting interface and the calling request carrying the calling token.
In a third aspect, embodiments of the present disclosure provide an electronic device. The electronic equipment comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus; a memory for storing a computer program; and a processor for implementing the service calling method or the image processing method when executing the program stored in the memory.
In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium. The computer-readable storage medium has stored thereon a computer program that, when executed by a processor, implements the service invocation method or the image processing method as described above.
Compared with the prior art, the technical scheme provided by the embodiment of the disclosure at least has part or all of the following advantages: calling a remote calling frame from a micro service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved, so that the service calling efficiency is improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.
In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the related art will be briefly described below, and it is obvious for those skilled in the art to obtain other drawings without inventive exercise.
Fig. 1 schematically shows a hardware structure block diagram of a computer terminal of a service invocation method according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a method of service invocation of an embodiment of the present disclosure;
FIG. 3 is a flow diagram that schematically illustrates a method for service invocation in accordance with an embodiment of the present disclosure;
fig. 4 is a block diagram schematically illustrating a structure of a service invocation apparatus according to an embodiment of the present disclosure;
fig. 5 schematically shows a block diagram of an electronic device provided in an embodiment of the present disclosure.
Detailed Description
The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments. It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided by the embodiments of the present disclosure may be executed in a computer terminal or a similar computing device. Taking an example of the service invocation method running on a computer terminal as an example, fig. 1 schematically illustrates a hardware structure block diagram of a computer terminal of the service invocation method according to the embodiment of the disclosure. As shown in fig. 1, a computer terminal may include one or more processors 102 (only one is shown in fig. 1), wherein the processors 102 may include but are not limited to a processing device such as a Microprocessor (MPU) or a Programmable Logic Device (PLD) and a memory 104 for storing data, and optionally, the computer terminal may further include a transmission device 106 for communication function and an input/output device 108, it is understood by those skilled in the art that the structure shown in fig. 1 is merely illustrative and not a limitation to the structure of the computer terminal, for example, the computer terminal may further include more or less components than those shown in fig. 1, or have equivalent functions or different configurations than those shown in fig. 1.
The memory 104 may be used to store computer programs, for example, software programs and modules of application software, such as computer programs corresponding to the service calling method in the embodiments of the present disclosure, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the above-mentioned method. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to a computer terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
In an embodiment of the present disclosure, a service invocation method is provided, and fig. 2 schematically illustrates a flowchart of a service invocation method in an embodiment of the present disclosure, where as shown in fig. 2, the flowchart includes the following steps:
step S202, a remote calling frame is called from a micro-service center to create a remote calling interface class corresponding to the remote calling frame;
step S204, realizing a request interception interface in the remote call interface class;
step S206, calling the request container through the hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request;
and step S208, writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token.
It should be noted that the remote invocation interface Class is a Class corresponding to the remote invocation interface, where the Class (Class) is a basis for implementing information encapsulation by Object-Oriented Programming (OOP). A class is a user-defined type of reference data, also called a class type. Each class contains a description of the data and a set of functions that operate on the data or pass messages. Instances of classes are referred to as objects.
According to the method, a remote calling frame is called from a micro-service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved, so that the service calling efficiency is improved.
In step S202, a remote invocation framework is invoked from the micro service center to create a remote invocation interface class corresponding to the remote invocation framework, including: receiving a class creating instruction sent by the target object through the remote calling frame, and defining a class statement, a constructor, a variable and a method corresponding to the remote calling interface class according to the class creating instruction; and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class to create the remote call interface class.
The remote calling framework can be a Feign framework, the Feign framework is a lightweight framework called by Http requests, and the Http requests can be called by a Java interface annotation mode. The Feign makes the request templated by processing the annotation, and when the request is actually called, the parameter is transmitted and applied to the request according to the parameter, so that the request is converted into a real request, and the http calling flow is encapsulated. If the Feign framework is not used, if http is needed for calling service, a request header and a request body are configured, then a request can be initiated, and after a response body is obtained, operations such as analysis and the like are needed, so that the operation is very complicated. According to the embodiment of the disclosure, the efficiency and the speed of calling the target service are improved by calling the remote calling framework from the micro-service center. The target object can be a user or a client, a computer terminal and the like used by the user.
Optionally, the remote invocation interface class may be replaced by a remote invocation interface class library, where the remote invocation interface class library includes a plurality of remote invocation interface classes.
Optionally, receiving a class creation instruction sent by the target object through the remote call framework, and defining a class statement, a constructor, a variable and a method corresponding to each remote call interface class in the remote call interface class library according to the class creation instruction; and encapsulating class statements, constructors, variables and methods corresponding to each remote call interface class in the remote call interface class library to create the remote call interface class library.
In step S204, implementing a request interception interface in the remote invocation interface class, including: receiving an interface implementation instruction, and performing template conversion operation on the interface implementation instruction in an interface annotation mode through the remote call frame; and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
Through the remote call framework, the template conversion operation of the interface implementation instruction in an interface annotation mode comprises the following steps: annotating the interface implementation instruction, analyzing the annotated interface implementation instruction, and realizing the templating of the interface implementation instruction in the analyzing operation process. The interface implementation instruction may be sent by the target object, or may be sent by the remote call framework after the remote call interface class corresponding to the remote call framework is created.
Optionally, implementing a request interception interface in the remote call interface class, or implementing a request interception interface in the remote call interface class library, includes: receiving an interface implementation instruction, and performing template conversion operation on the interface implementation instruction in an interface annotation mode through the remote call frame; and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
In the embodiment of the present disclosure, a fault tolerance mechanism is added to the remote call framework, wherein the fault tolerance mechanism may implement the request interception interface again when the request interception interface in the remote call interface class fails to be implemented.
Before step S204 is executed, that is, before the request intercepting interface in the remote invocation interface class is implemented, the method further includes: receiving an interface creating instruction through the remote calling frame, and defining an interface statement, a constant and a method corresponding to the request intercepting interface according to the interface creating instruction; and packaging the interface statement, the constant and the method corresponding to the request interception interface to create the request interception interface.
In practical operation, the request interception interface may be created in the process of creating the remote invocation interface class: according to the class creating instruction, defining class statements, constructors, variables and methods corresponding to the remote call interface class, and defining interface statements, constants and methods corresponding to the request interception interface; and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class, and encapsulating interface statements, constants and methods corresponding to the request interception interface. Through the technical means, the request interception interface is also created in the process of creating the remote call interface class.
The interface creating instruction may be sent by the target object, or may be sent by the remote call framework after the remote call interface class corresponding to the remote call framework is created.
In step S208, writing the call token into the call request through the request function includes: calling a service isolation component to configure a program request object corresponding to the remote call framework; and writing the call token into the call request through the request function and the program request object.
In actual operation, the problem that the program request object is empty occurs when the call token is written into the call request through the request function, so that a service isolation component needs to be called, the program request object corresponding to the remote call framework is configured, and the call token is written into the call request through the request function and the program request object. The service isolation component may be hystrix in Feign, and the program request object may be HttpServletRequest in Feign.
Invoking a service isolation component comprising: using a command mode to pack all calls to external services (or dependency relationships) in a HystrixCommand or HystrixObservivableCommand object, and putting the object in a separate thread for execution; each dependency maintains a thread pool (or semaphore), which is exhausted and requests are denied (rather than queued); recording success, failure, timeout and thread rejection of the request; when the percentage of service errors exceeds a threshold value, the fuse switch is automatically opened, and all requests for the service are stopped within a period of time; performing degradation logic when the request fails, is rejected, overtime or is fused; the modification of the index and configuration is monitored in near real time.
Before step S206 is executed, that is, before the request container is called by the hijack object algorithm to obtain the access request sent by the target object and determine the call token carried in the access request, the method further includes: under the condition of logging in a gateway service, sending an authentication request to a token authentication service so that the token authentication service generates the calling token according to the authentication request; sending the access request through the target object, where the access request includes the invocation token, if the token authentication service returns the invocation token.
The hijack object algorithm may be an application algorithm, wherein the application algorithm functions to merge methods and properties of methods and objects and to point this of methods and objects to the merged object. The embodiment of the disclosure obtains the access request sent by the target object by calling the request container by using the application algorithm.
Optionally, the request container is called by a hijack object algorithm to obtain an access request sent by a target object, and before determining a call token carried in the access request, an authentication request is directly sent to a token authentication service without logging in a gateway service, so that the token authentication service generates the call token according to the authentication request. The token authentication service generates the invocation token in a JWT manner. JWT, or Json web token, is a JSON-based open standard ((RFC 7519) designed to be compact and secure and particularly suitable for single sign-on (SSO) scenarios on distributed sites, implemented for transferring assertions between web application environments.
The token authentication service generates the call token according to the authentication request, actually according to the identification information such as the user ID number in the authentication request, the account number of the application to which the user belongs, and the like.
After step S206 is executed, that is, after the request container is called by the hijack object algorithm to obtain the access request sent by the target object, and the call token carried in the access request is determined, the method further includes: writing the call token into a request parameter through a built-in function; and calling the target service according to the request interception interface and the request parameter carrying the calling token.
In the embodiment of the present disclosure, the writing of the call token into the request parameter through the built-in function or the writing of the call token into the call request through the request function is to transmit the call token in a manner, that is, to transmit the call token through the request parameter or transmit the call token through the call request. The transfer of the invocation token by requesting the parameters is an explicit way of transferring the token by parameters.
In the embodiment of the present disclosure, the executing entity may be understood as service a, and the target service may be understood as service B. Therefore, embodiments of the present disclosure may be understood as invoking one service by another service. Through the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time are solved, and the like, so that the service calling efficiency is improved.
In step S208, invoking a target service according to the request interception interface and the invocation request carrying the invocation token, including: calling the target service in an asynchronous calling mode under the condition that the target service is busy; and calling the target service in a synchronous calling mode under the condition that the target service is idle.
In the embodiment of the disclosure, calling the target service can determine a calling mode according to the state of the target service, that is, calling the target service in an asynchronous calling mode under the condition that the target service is busy; and calling the target service in a synchronous calling mode under the condition that the target service is idle. Optionally, the busy work percentage and the asynchronous call threshold of the target service are inquired, and when the busy work percentage is larger than the asynchronous call threshold, the target service is called in an asynchronous call mode; and when the work busy percentage is less than the asynchronous call threshold value, calling the target service in a synchronous call mode. The work busy percentage may be a running percentage of the CPU of the device corresponding to the target service.
In order to better understand the technical solutions, the embodiments of the present disclosure also provide an alternative embodiment for explaining the technical solutions.
Fig. 3 schematically illustrates a flowchart of a service invocation method according to an embodiment of the present disclosure, as shown in fig. 3:
s302, calling a remote calling frame from the micro-service center;
s304, creating a remote call interface class corresponding to the remote call framework;
s306, realizing a request interception interface in the remote call interface class;
s308, sending an authentication request to a token authentication service so that the token authentication service generates the calling token according to the authentication request;
s310, sending an access request through sending equipment, wherein the access request carries the call token;
s312, calling the request container through a hijack object algorithm to obtain an access request sent by a target object through sending equipment, and determining a calling token carried in the access request;
s314, writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token;
s316, judging the busy degree of the target service, and determining a calling mode for calling the target service;
and S318, calling the target service according to the calling mode.
According to the method, a remote calling frame is called from a micro-service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved, so that the service calling efficiency is improved.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present disclosure or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a storage medium (such as a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, and an optical disk), and includes several instructions for enabling a terminal device (which may be a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present disclosure.
In this embodiment, a service invoking device is further provided, and the service invoking device is used to implement the foregoing embodiments and preferred embodiments, which have already been described and are not described again. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 4 is a block diagram schematically illustrating a structure of a service invocation apparatus according to an alternative embodiment of the present disclosure, and as shown in fig. 4, the apparatus includes:
a first calling module 402, configured to call a remote calling framework from a micro service center, so as to create a remote calling interface class corresponding to the remote calling framework;
an implementation module 404, configured to implement a request interception interface in the remote call interface class;
a second calling module 406, configured to call the request container through a hijack object algorithm to obtain an access request sent by a target object, and determine a call token carried in the access request;
and a third calling module 408, configured to write the call token into a call request through a request function, and call a target service according to the request interception interface and the call request carrying the call token.
According to the method, a remote calling frame is called from a micro-service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved, so that the service calling efficiency is improved.
Compared with the prior art, the technical scheme provided by the embodiment of the disclosure at least has part or all of the following advantages: calling a remote calling frame from a micro service center to create a remote calling interface class corresponding to the remote calling frame; implementing a request interception interface in the remote call interface class; calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request; and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token. By adopting the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time and the like are solved, so that the service calling efficiency is improved.
Optionally, the first calling module 402 is further configured to receive a class creation instruction sent by the target object through the remote calling framework, and define a class declaration, a constructor, a variable, and a method corresponding to the remote calling interface class according to the class creation instruction; and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class to create the remote call interface class.
The remote calling framework can be a Feign framework, the Feign framework is a lightweight framework called by Http requests, and the Http requests can be called by a Java interface annotation mode. The Feign makes the request templated by processing the annotation, and when the request is actually called, the parameter is transmitted and applied to the request according to the parameter, so that the request is converted into a real request, and the http calling flow is encapsulated. If the Feign framework is not used, if http is needed for calling service, a request header and a request body are configured, then a request can be initiated, and after a response body is obtained, operations such as analysis and the like are needed, so that the operation is very complicated. According to the embodiment of the disclosure, the efficiency and the speed of calling the target service are improved by calling the remote calling framework from the micro-service center. The target object can be a user or a client, a computer terminal and the like used by the user.
Optionally, the remote invocation interface class may be replaced by a remote invocation interface class library, where the remote invocation interface class library includes a plurality of remote invocation interface classes.
Optionally, the first calling module 402 is further configured to receive a class creation instruction sent by the target object through the remote calling framework, and define, according to the class creation instruction, a class declaration, a constructor, a variable, and a method corresponding to each remote calling interface class in the remote calling interface class library; and encapsulating class statements, constructors, variables and methods corresponding to each remote call interface class in the remote call interface class library to create the remote call interface class library.
Optionally, the implementation module 404 is further configured to receive an interface implementation instruction, and perform template conversion operation on the interface implementation instruction in an interface annotation manner through the remote call framework; and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
Through the remote call framework, the template conversion operation of the interface implementation instruction in an interface annotation mode comprises the following steps: annotating the interface implementation instruction, analyzing the annotated interface implementation instruction, and realizing the templating of the interface implementation instruction in the analyzing operation process. The interface implementation instruction may be sent by the target object, or may be sent by the remote call framework after the remote call interface class corresponding to the remote call framework is created.
Optionally, the implementation module 404 is further configured to receive an interface implementation instruction, and perform template conversion operation on the interface implementation instruction in an interface annotation manner through the remote call framework; and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
In the embodiment of the present disclosure, a fault tolerance mechanism is added to the remote call framework, wherein the fault tolerance mechanism may implement the request interception interface again when the request interception interface in the remote call interface class fails to be implemented.
Optionally, the implementation module 404 is further configured to receive an interface creation instruction through the remote call framework, and define an interface statement, a constant, and a method corresponding to the request interception interface according to the interface creation instruction; and packaging the interface statement, the constant and the method corresponding to the request interception interface to create the request interception interface.
In practical operation, the request interception interface may be created in the process of creating the remote invocation interface class: according to the class creating instruction, defining class statements, constructors, variables and methods corresponding to the remote call interface class, and defining interface statements, constants and methods corresponding to the request interception interface; and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class, and encapsulating interface statements, constants and methods corresponding to the request interception interface. Through the technical means, the request interception interface is also created in the process of creating the remote call interface class.
The interface creating instruction may be sent by the target object, or may be sent by the remote call framework after the remote call interface class corresponding to the remote call framework is created.
Optionally, the third module 408 is further configured to invoke a service isolation component to configure a program request object corresponding to the remote invocation framework; and writing the call token into the call request through the request function and the program request object.
In actual operation, the problem that the program request object is empty occurs when the call token is written into the call request through the request function, so that a service isolation component needs to be called, the program request object corresponding to the remote call framework is configured, and the call token is written into the call request through the request function and the program request object. The service isolation component may be hystrix in Feign, and the program request object may be HttpServletRequest in Feign.
Invoking a service isolation component comprising: using a command mode to pack all calls to external services (or dependency relationships) in a HystrixCommand or HystrixObservivableCommand object, and putting the object in a separate thread for execution; each dependency maintains a thread pool (or semaphore), which is exhausted and requests are denied (rather than queued); recording success, failure, timeout and thread rejection of the request; when the percentage of service errors exceeds a threshold value, the fuse switch is automatically opened, and all requests for the service are stopped within a period of time; performing degradation logic when the request fails, is rejected, overtime or is fused; the modification of the index and configuration is monitored in near real time.
Optionally, the second module 406 is further configured to, in a case of logging in a gateway service, send an authentication request to a token authentication service, so that the token authentication service generates the invocation token according to the authentication request; sending the access request through the target object, where the access request includes the invocation token, if the token authentication service returns the invocation token.
The hijack object algorithm may be an application algorithm, wherein the application algorithm functions to merge methods and properties of methods and objects and to point this of methods and objects to the merged object. The embodiment of the disclosure obtains the access request sent by the target object by calling the request container by using the application algorithm.
Optionally, the request container is called by a hijack object algorithm to obtain an access request sent by a target object, and before determining a call token carried in the access request, an authentication request is directly sent to a token authentication service without logging in a gateway service, so that the token authentication service generates the call token according to the authentication request. The token authentication service generates the invocation token in a JWT manner. JWT, or Json web token, is a JSON-based open standard ((RFC 7519) designed to be compact and secure and particularly suitable for single sign-on (SSO) scenarios on distributed sites, implemented for transferring assertions between web application environments.
The token authentication service generates the call token according to the authentication request, actually according to the identification information such as the user ID number in the authentication request, the account number of the application to which the user belongs, and the like.
Optionally, the second module 406 is further configured to write the call token into a request parameter through a built-in function; and calling the target service according to the request interception interface and the request parameter carrying the calling token.
In the embodiment of the present disclosure, the writing of the call token into the request parameter through the built-in function or the writing of the call token into the call request through the request function is to transmit the call token in a manner, that is, to transmit the call token through the request parameter or transmit the call token through the call request. The transfer of the invocation token by requesting the parameters is an explicit way of transferring the token by parameters.
In the embodiment of the present disclosure, the executing entity may be understood as service a, and the target service may be understood as service B. Therefore, embodiments of the present disclosure may be understood as invoking one service by another service. Through the technical means, the problems that in the prior art, when one service calls another service, a user needs to put a token in a request parameter every time are solved, and the like, so that the service calling efficiency is improved.
Optionally, the third module 408 is further configured to invoke the target service by means of asynchronous invocation if the target service is busy; and calling the target service in a synchronous calling mode under the condition that the target service is idle.
In the embodiment of the disclosure, calling the target service can determine a calling mode according to the state of the target service, that is, calling the target service in an asynchronous calling mode under the condition that the target service is busy; and calling the target service in a synchronous calling mode under the condition that the target service is idle. Optionally, the busy work percentage and the asynchronous call threshold of the target service are inquired, and when the busy work percentage is larger than the asynchronous call threshold, the target service is called in an asynchronous call mode; and when the work busy percentage is less than the asynchronous call threshold value, calling the target service in a synchronous call mode. The work busy percentage may be a running percentage of the CPU of the device corresponding to the target service.
It should be noted that, the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in different processors in any combination.
Embodiments of the present disclosure provide an electronic device.
Fig. 5 schematically shows a block diagram of an electronic device provided in an embodiment of the present disclosure.
Referring to fig. 5, an electronic device 500 provided in the embodiment of the present disclosure includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, where the processor 501, the communication interface 502 and the memory 503 complete communication with each other through the communication bus 504; a memory 503 for storing a computer program; the processor 501 is configured to implement the steps in any of the above method embodiments when executing the program stored in the memory.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, calling a remote calling frame from the micro service center to create a remote calling interface class corresponding to the remote calling frame;
s2, realizing a request interception interface in the remote call interface class;
s3, calling the request container through the hijack object algorithm to obtain the access request sent by the target object and determine the calling token carried in the access request;
and S4, writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token.
Embodiments of the present disclosure also provide a computer-readable storage medium. The computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of any of the method embodiments described above.
Alternatively, in the present embodiment, the storage medium may be configured to store a computer program for executing the steps of:
s1, calling a remote calling frame from the micro service center to create a remote calling interface class corresponding to the remote calling frame;
s2, realizing a request interception interface in the remote call interface class;
s3, calling the request container through the hijack object algorithm to obtain the access request sent by the target object and determine the calling token carried in the access request;
and S4, writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token.
The computer-readable storage medium may be contained in the apparatus/device described in the above embodiments; or may be present alone without being assembled into the device/apparatus. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and this embodiment is not described herein again.
It will be apparent to those skilled in the art that the modules or steps of the present disclosure described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. As such, the present disclosure is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure, and various modifications and changes may be made to the present disclosure by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the principle of the present disclosure should be included in the protection scope of the present disclosure.

Claims (10)

1. A service invocation method, characterized by comprising:
calling a remote calling frame from a micro service center to create a remote calling interface class corresponding to the remote calling frame;
implementing a request interception interface in the remote call interface class;
calling a request container through a hijack object algorithm to obtain an access request sent by a target object and determine a calling token carried in the access request;
and writing the call token into a call request through a request function, and calling a target service according to the request interception interface and the call request carrying the call token.
2. The method of claim 1, wherein said invoking a remote invocation framework from a microservice center to create a remote invocation interface class corresponding to the remote invocation framework comprises:
receiving a class creating instruction sent by the target object through the remote calling frame, and defining a class statement, a constructor, a variable and a method corresponding to the remote calling interface class according to the class creating instruction;
and encapsulating class statements, constructors, variables and methods corresponding to the remote call interface class to create the remote call interface class.
3. The method of claim 1, wherein implementing the request interception interface in the remote invocation interface class comprises:
receiving an interface implementation instruction, and performing template conversion operation on the interface implementation instruction in an interface annotation mode through the remote call frame;
and realizing the request interception interface according to the interface realization instruction after the template conversion operation.
4. The method of claim 1, wherein prior to implementing the request interception interface in the remote invocation interface class, the method further comprises:
receiving an interface creating instruction through the remote calling frame, and defining an interface statement, a constant and a method corresponding to the request intercepting interface according to the interface creating instruction;
and packaging the interface statement, the constant and the method corresponding to the request interception interface to create the request interception interface.
5. The method of claim 1, wherein writing the call token into a call request by a request function comprises:
calling a service isolation component to configure a program request object corresponding to the remote call framework;
and writing the call token into the call request through the request function and the program request object.
6. The method according to claim 1, wherein before the request container is called by the hijack object algorithm to obtain the access request sent by the target object and determine the call token carried in the access request, the method further comprises:
under the condition of logging in a gateway service, sending an authentication request to a token authentication service so that the token authentication service generates the calling token according to the authentication request;
sending the access request through the target object, where the access request includes the invocation token, if the token authentication service returns the invocation token.
7. The method according to claim 1, wherein after the request container is called by the hijack object algorithm to obtain the access request sent by the target object and the call token carried in the access request is determined, the method further comprises:
writing the call token into a request parameter through a built-in function;
and calling the target service according to the request interception interface and the request parameter carrying the calling token.
8. The method of claim 1, wherein the invoking the target service according to the request interception interface and the invocation request carrying the invocation token comprises:
calling the target service in an asynchronous calling mode under the condition that the target service is busy;
and calling the target service in a synchronous calling mode under the condition that the target service is idle.
9. A service invocation apparatus, characterized by comprising:
the first calling module is used for calling a remote calling frame from a micro service center so as to create a remote calling interface class corresponding to the remote calling frame;
the realization module is used for realizing a request interception interface in the remote calling interface class;
the second calling module is used for calling the request container through a hijack object algorithm to acquire an access request sent by a target object and determine a calling token carried in the access request;
and the third calling module is used for writing the calling token into a calling request through a request function and calling a target service according to the request intercepting interface and the calling request carrying the calling token.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method of any one of claims 1 to 8.
CN202110937264.XA 2021-08-16 2021-08-16 Service calling method, device and storage medium Pending CN113641518A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110937264.XA CN113641518A (en) 2021-08-16 2021-08-16 Service calling method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110937264.XA CN113641518A (en) 2021-08-16 2021-08-16 Service calling method, device and storage medium

Publications (1)

Publication Number Publication Date
CN113641518A true CN113641518A (en) 2021-11-12

Family

ID=78421999

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110937264.XA Pending CN113641518A (en) 2021-08-16 2021-08-16 Service calling method, device and storage medium

Country Status (1)

Country Link
CN (1) CN113641518A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114721845A (en) * 2022-04-14 2022-07-08 广州有信科技有限公司 Multi-tenant restful API interface management method and device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090271847A1 (en) * 2008-04-25 2009-10-29 Nokia Corporation Methods, Apparatuses, and Computer Program Products for Providing a Single Service Sign-On
US20140007251A1 (en) * 2011-02-24 2014-01-02 Stephan Spitz Method for interchanging data in a secure runtime environment
CN110580234A (en) * 2019-08-22 2019-12-17 广州易起行信息技术有限公司 Fusing method suitable for micro server and external system
US20200259652A1 (en) * 2019-02-08 2020-08-13 Microsoft Technology Licensing, Llc System and method for hardening security between web services using protected forwarded access tokens
CN112612595A (en) * 2020-12-29 2021-04-06 太平金融科技服务(上海)有限公司 Method and device for establishing micro-service calling relationship, computer equipment and storage medium
CN112836204A (en) * 2021-02-03 2021-05-25 中国人民财产保险股份有限公司 Token updating method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090271847A1 (en) * 2008-04-25 2009-10-29 Nokia Corporation Methods, Apparatuses, and Computer Program Products for Providing a Single Service Sign-On
US20140007251A1 (en) * 2011-02-24 2014-01-02 Stephan Spitz Method for interchanging data in a secure runtime environment
US20200259652A1 (en) * 2019-02-08 2020-08-13 Microsoft Technology Licensing, Llc System and method for hardening security between web services using protected forwarded access tokens
CN110580234A (en) * 2019-08-22 2019-12-17 广州易起行信息技术有限公司 Fusing method suitable for micro server and external system
CN112612595A (en) * 2020-12-29 2021-04-06 太平金融科技服务(上海)有限公司 Method and device for establishing micro-service calling relationship, computer equipment and storage medium
CN112836204A (en) * 2021-02-03 2021-05-25 中国人民财产保险股份有限公司 Token updating method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
DIAOYUAN0114: "微服务实战springcloud之feign简介及使用", pages 1 - 4, Retrieved from the Internet <URL:《https://blog.csdn.net/diaoyuan0114/article/details/101501544》> *
陆小叁: "自定义feign拦截器,解决微服务质检feign调用请求丢失问题", pages 1 - 3, Retrieved from the Internet <URL:《https://www.cnblogs.com/aliases/p/14693292.html》> *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114721845A (en) * 2022-04-14 2022-07-08 广州有信科技有限公司 Multi-tenant restful API interface management method and device

Similar Documents

Publication Publication Date Title
CN113676512B (en) Network system, resource processing method and equipment
CN103346980B (en) A kind of business scheduling method, device and the network equipment
CN111356207A (en) Service slice selection method and device
CN113573303B (en) Method and device for determining edge application server
CN111935017B (en) Cross-network application calling method and device and routing equipment
CN108401037A (en) User terminal and the binding method of equipment, device and system
CN109587142B (en) Data security access module and equipment for service flow
CN112769794B (en) Data conversion method and device
CN109614147A (en) A kind of PHY register reading/writing method and device
CN113114706B (en) Multichannel Ethernet message processing method based on power chip
CN111294235A (en) Data processing method, device, gateway and readable storage medium
CN112788128A (en) Business information pushing method and device, storage medium and electronic device
CN114124929A (en) Cross-network data processing method and device
CN113641518A (en) Service calling method, device and storage medium
CN112702362B (en) Method and device for enhancing TCP/IP protocol stack, electronic equipment and storage medium
CN113220481A (en) Request processing and feedback method and device, computer equipment and readable storage medium
CN111984236A (en) Component standardization management method and device, computer equipment and readable storage medium
CN114979148B (en) Data transmission method, device and computer readable storage medium
CN116389323A (en) Throughput test method, device and storage medium
CN110620754A (en) NF (NF) required resource deployment method and device, storage medium and electronic device
CN112650710A (en) Data migration sending method and device, storage medium and electronic device
CN102651881B (en) Parameter modifying method and system in test of external field of wireless network
CN115858661A (en) Method and device for synchronizing environmental parameters, storage medium and electronic device
CN112416321B (en) Application generation method and device, storage medium and electronic device
CN116089347A (en) Inter-core communication method, receiving core, storage medium and electronic device

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