Synchronous to asynchronous call method, device, system, electronic device and readable medium
Convert synchronous calls to asynchronous calls in a non-invasive way, and simplify configuration and development using proxy classes and asynchronous middleware, solving the problems of cumbersome XML configuration and complex development in the existing technology, and achieving efficient asynchronous call switching.
Patent Information
- Application Number
- CN201810783093.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-07-17
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2038-07-17
AI Technical Summary
The existing synchronous call to asynchronous call methods require cumbersome XML file configuration and complicated producer and consumer registration, and self-produced and sold message queues require additional consumer listening classes, resulting in high development complexity.
In a non-invasive way, the synchronous call request is converted into asynchronous calls using proxy classes and asynchronous middleware, and the method interceptor is used to determine whether the call request is forwarded to the asynchronous middleware, and pass it to the consumer listening service and service provider through asynchronous messages, realizing asynchronous processing.
It simplifies the configuration process, reduces the development complexity, realizes free switching synchronous and asynchronous calls, and improves development efficiency.
Smart Images

Figure CN110727521B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the fields of computers and the Internet, and in particular to a method, system, device, electronic device, and computer-readable medium for converting synchronous calls to asynchronous calls. Background Art
[0002] In the Internet field, message middleware is often used for application communication to simplify the development of communication and input and output. Message middleware can not only simplify application development, but also bring the benefits of asynchrony. Asynchronous calls are non-blocking calls, while the original synchronous calls are blocking calls, that is, the client (main caller) code blocks and waits until the server (the callee) returns. The implementation process is as follows: Figure 1 When faced with coarse-grained service components, the response time is long. In this scenario, you should consider converting synchronous calls to asynchronous calls to achieve more efficient message delivery.
[0003] The existing method of converting synchronous calls to asynchronous calls is usually as follows: configuring the producer, consumer, and listener classes through XML files to access the message middleware. However, the above method has the following disadvantages:
[0004] (1) Requires complex XML file configuration.
[0005] (2) Configuring producers and consumers is too cumbersome. Creating a producer and connecting a consumer requires registering information such as the topic, producer, and monitoring class in the configuration file.
[0006] (3) Consumer: Each consumer needs to implement the onMessage method of the consumer monitoring class to consume the message queue. In fact, each consumer parses the message by converting the message body into a business entity class and then executing its own business code.
[0007] (4) For self-produced and self-sold message queues, when the producer sends a message through the business code, the consumer still needs to implement the above (2) step.
[0008] Therefore, a new method, device, system, electronic device and computer-readable medium for converting synchronous calls to asynchronous calls are needed.
[0009] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not form the prior art that is already known to a person of ordinary skill in the art. Summary of the Invention
[0010] In view of this, the present application provides a method, device, system, electronic device and computer-readable medium for converting synchronous calls to asynchronous calls, which can convert the proxied method into asynchronous processing using an asynchronous processing framework in a non-invasive manner, thereby realizing free switching between synchronous calls and asynchronous calls.
[0011] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by practice of the present disclosure.
[0012] According to a first aspect of an embodiment of the present application, a method for converting a synchronous call to an asynchronous call is provided. The method includes: a service caller sends a call request; a proxy class receives the call request and forwards the call request to an asynchronous middleware; the asynchronous middleware sends the call request to a consumer listening service in the form of an asynchronous message; and the consumer listening service sends the call request to a service provider, so that the service provider responds to the call request.
[0013] In an exemplary embodiment of the present application, it also includes: the service provider sends the return message of the call request to the consumer listening service; the consumer listening service sends the return message to the asynchronous middleware; the asynchronous middleware sends the return message to the proxy class; and the proxy class returns the return message to the service caller to complete the call request.
[0014] In an exemplary embodiment of the present application, the proxy class receives the call request and forwards the call request to the asynchronous middleware, including: the proxy class receives the call request and sends the call request to the method interceptor through the invoke function; the method interceptor determines whether to forward the call request to the asynchronous middleware based on preset parameters; and when the call request meets the preset parameters, forwards the call request to the asynchronous middleware.
[0015] In an exemplary embodiment of the present application, the method interceptor determines whether to forward the call request to the asynchronous middleware according to preset parameters, including: the method interceptor determines whether to forward the call request to the asynchronous middleware according to the annotation type of the method.
[0016] In an exemplary embodiment of the present application, it further includes: when the call request does not meet the preset parameters, the service caller calls the service provider through a synchronous call method.
[0017] In an exemplary embodiment of the present application, forwarding the call request to the asynchronous middleware includes: the method interceptor sending the call request to the message producer through the SendMessage function; and the message producer forwarding the call request to the asynchronous middleware.
[0018] In an exemplary embodiment of the present application, it further includes: creating a proxy class, a consumer monitoring service, and a producer during the initialization process.
[0019] In an exemplary embodiment of the present application, creating a proxy class, a consumer listening service, and a producer during the initialization process includes: Spring core creating a proxy factory through a create function; the proxy factory creating a proxy class, a consumer listening service, and a producer through a create function.
[0020] In an exemplary embodiment of the present application, creating a proxy class, a consumer listening service, and a producer during the initialization process further includes: registering the consumer listening service with a context after creating the consumer listening service; and registering the producer with a context after creating the producer.
[0021] According to the second aspect of the embodiment of the present application, a device for converting a synchronous call to an asynchronous call is proposed, which includes: a request module, used for a service caller to send a call request; a first forwarding module, used for a proxy class to receive the call request and forward the call request to an asynchronous middleware; a second forwarding module, used for the asynchronous middleware to send the call request to a consumer listening service in the form of an asynchronous message; and a response module, used for the consumer listening service to send the call request to a service provider so that the service provider can respond to the call request.
[0022] According to the third aspect of the embodiment of the present application, a system for converting synchronous calls to asynchronous calls is proposed, the system including: a client for sending a call request; a request forwarding server for receiving the call request and forwarding the call request to the asynchronous middleware; the asynchronous middleware sends the call request to the consumer listening service in the form of an asynchronous message; the consumer listening service sends the call request to the server; and a server for responding to the call request.
[0023] According to the fourth aspect of the embodiments of the present application, an electronic device is proposed, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method of converting a synchronous call to an asynchronous call as described in any one of the above items.
[0024] According to a fifth aspect of an embodiment of the present application, a computer-readable medium is proposed, on which a computer program is stored, characterized in that when the program is executed by a processor, the method of converting a synchronous call to an asynchronous call as described in any one of the above items is implemented.
[0025] According to the synchronous call to asynchronous call conversion method, device, system, electronic device and computer-readable medium of the present application, the proxied method can be converted into asynchronous processing using an asynchronous processing framework in a non-invasive manner, thereby realizing free switching between synchronous calls and asynchronous calls.
[0026] It should be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. The drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be derived from these drawings without inventive effort.
[0028] Figure 1 This is a system architecture diagram showing a synchronous calling method according to the prior art.
[0029] Figure 2 The present invention is a system block diagram showing a method and apparatus for converting synchronous calls to asynchronous calls according to an exemplary embodiment.
[0030] Figure 3 The figure is a flowchart showing a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0031] Figure 4 The figure is a flowchart showing a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0032] Figure 5 The figure is a flowchart showing a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0033] Figure 6 It is a system architecture diagram showing a method for converting synchronous calls to asynchronous calls according to another exemplary embodiment.
[0034] Figure 7 It is a system architecture diagram showing a method for converting synchronous calls to asynchronous calls according to another exemplary embodiment.
[0035] Figure 8 The present invention is a block diagram showing a device for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0036] Figure 9 The figure is a schematic diagram of a system for converting synchronous calls to asynchronous calls according to another exemplary embodiment.
[0037] Figure 10 The present invention is a block diagram of an electronic device for converting a synchronous call to an asynchronous call according to an exemplary embodiment. DETAILED DESCRIPTION
[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be embodied in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art. Like reference numerals in the drawings represent like or similar parts, and thus repeated description thereof will be omitted.
[0039] The described features, structures or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solutions of the present invention may be practiced while omitting one or more of the specific details, or alternatively, other methods, components, devices, steps, etc. may be employed. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid obscuring various aspects of the present invention.
[0040] The accompanying drawings are merely schematic illustrations of the present invention. Identical reference numerals denote identical or similar components, and thus their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0041] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all content and steps, nor must they be executed in the order described. For example, some steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.
[0042] Exemplary embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0043] Figure 2 The present invention is a system block diagram showing a method and apparatus for converting synchronous calls to asynchronous calls according to an exemplary embodiment.
[0044] Reference Figure 2The server 205 may be a server that provides various services, such as a background management server (for example only) that supports applications operated by users using the terminal devices 201, 202, and 203. The background management server may analyze and process received data such as messages or change requests, and feed back processing results (for example, verification results, user login results—for example only) to the terminal device.
[0045] The server 205 may, for example, send a call request through a service caller; the server 205 may, for example, receive the call request through a proxy class and forward the call request to an asynchronous middleware; the server 205 may, for example, send the call request to a consumer listening service in the form of an asynchronous message through the asynchronous middleware; the server 205 may, for example, send the call request to a service provider through the consumer listening service so that the service provider can respond to the call request. The server 205 may, for example, send a return message of the call request to the consumer listening service through the service provider; the server 205 may, for example, send the return message to the asynchronous middleware through the consumer listening service; the server 205 may, for example, send the return message to the proxy class through the asynchronous middleware; the server 205 may, for example, send the return message back to the service caller through the proxy class to complete the call request.
[0046] Server 205 can be a physical server, or it can be composed of multiple servers. A part of server 205 can be used as the message sending system in this application, for example, to send the call request to the service provider in the form of an asynchronous message when the service caller sends a call request; and a part of server 205 can also be used as the message response system in this application, for example, to return the return message sent by the service provider to the service caller.
[0047] It should be noted that the method for converting a synchronous call to an asynchronous call provided in the exemplary embodiment of the present application can be executed by the server 205. Accordingly, the apparatus for converting a synchronous call to an asynchronous call can be provided in the server 205. The request end that provides the user with the functions of generating a call request and receiving a return message is generally located in the terminal devices 201, 202, and 203.
[0048] Figure 3 This is a flow chart showing a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment. Figure 3 The method of converting synchronous calls to asynchronous calls shown in the figure can convert the proxy method into asynchronous processing using the asynchronous processing framework in a non-invasive way, thereby achieving free switching between synchronous calls and asynchronous calls. Figure 3 , the method for converting synchronous call to asynchronous call in the exemplary embodiment of the present application is explained.
[0049] In step S310, a service caller sends a call request, wherein the service caller may be, for example, an application program that needs to communicate with other application programs, but the technical solution of the present invention is not limited thereto.
[0050] In step S320, the proxy class receives the call request and forwards the call request to the asynchronous middleware. According to an example embodiment, the proxy class receiving the call request and forwarding the call request to the asynchronous middleware may include: the proxy class receiving the call request and sending the call request to the method interceptor via the invoke function; the method interceptor determining whether to forward the call request to the asynchronous middleware based on preset parameters; and forwarding the call request to the asynchronous middleware when the call request meets the preset parameters.
[0051] Among them, the proxy class is a proxy for the class. The proxy class is a proxy for the class, not directly calling the class methods. The purpose of the proxy class is to solve the problems caused by direct object access. For example: the object to be accessed is on a remote machine. In object-oriented systems, some objects may be difficult to access directly for various reasons (such as high object creation overhead, certain operations requiring security controls, or requiring out-of-process access). Based on this, an access layer to the object can be added when accessing the object, that is, the proxy class. The invoke function calls the method in the class, which can realize dynamic calling.
[0052] According to an example embodiment, the method interceptor determining whether to forward the call request to the asynchronous middleware according to preset parameters may include: the method interceptor determining whether to forward the call request to the asynchronous middleware according to the annotation type of the method.
[0053] Among them, the method interceptor (MethodInterceptor) is used to intercept a method before it is accessed and add certain operations before or after it. In the example embodiment of the present application, the method interceptor can be used to determine whether the current method requests an asynchronous call. The basis for its judgment is the annotation (Annontation) of the method. Annotations provide a safe, comment-like mechanism for associating any information or metadata with program elements (classes, methods, member variables, etc.). Add more intuitive and clearer descriptions to the elements of the program (classes, methods, member variables). These descriptions are independent of the business logic of the program and are used by specified tools or frameworks.
[0054] According to an example embodiment, the method may further include: when the call request does not meet the preset parameters, the service caller calls the service provider through a synchronous call method.
[0055] According to an example embodiment, forwarding the call request to the asynchronous middleware may include: the method interceptor sending the call request to the message producer through a SendMessage function; and the message producer forwarding the call request to the asynchronous middleware.
[0056] The SendMessage function sends a specified message to one or more windows. This function calls the window procedure for the specified window and waits until the window procedure processes the message before returning. A producer is the sender of a message. Asynchronous middleware is independent system software or service programs that enable distributed applications to share resources across different technologies. Middleware resides on top of the client / server operating system and manages computer resources and network communications.
[0057] In step S330, the asynchronous middleware sends the call request to the consumer listening service via an asynchronous message. A consumer is a subscriber to a message. The consumer listening service allows consumers to create a listener to receive messages using a callback model.
[0058] In step S340, the consumer listening service sends the call request to the service provider so that the service provider responds to the call request. According to an example embodiment, the method for converting a synchronous call to an asynchronous call may further include: the service provider sending a return message of the call request to the consumer listening service; the consumer listening service sending the return message to the asynchronous middleware; the asynchronous middleware sending the return message to the proxy class; and the proxy class returning the message to the service caller to complete the call request.
[0059] According to an example embodiment, the method for converting a synchronous call to an asynchronous call may further include: creating a proxy class, a consumer listening service, and a producer during an initialization process.
[0060] According to an example embodiment, creating a proxy class, a consumer listening service, and a producer during the initialization process includes: Spring core creating a proxy factory through a create function; and the proxy factory creating a proxy class, a consumer listening service, and a producer through a create function.
[0061] Spring is an open-source design framework that addresses the problem of loose coupling between the business logic layer and other layers. Therefore, it incorporates interface-oriented programming throughout the entire system application. Spring Core is the core component, containing many key classes, one of which is defining resource access methods. The Create function allows you to create objects through static methods.
[0062] According to an example embodiment, creating the proxy class, the consumer listening service, and the producer during the initialization process may further include: registering the consumer listening service with the context after creating the consumer listening service; and registering the producer with the context after creating the producer.
[0063] Figure 4 The figure is a flowchart showing a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0064] Reference Figure 4 , the methods for converting synchronous calls to asynchronous calls may include:
[0065] In step S410, the service provider sends a return message of the call request to the consumer monitoring service. The service provider may be the object to which the service caller wants to transmit a message. After receiving the message, the service provider returns a response to the message to the consumer monitoring service.
[0066] Step S420: The consumer monitoring service sends the return message to the asynchronous middleware.
[0067] Step S430: The asynchronous middleware sends the return message to the proxy class.
[0068] In step S440, the proxy class sends a return message back to the service caller to complete the call request. According to an exemplary embodiment, the return message is sent to the service caller via the proxy class to complete a complete message transmission process.
[0069] according to Figure 3 、 4 The flowchart of a method for converting a synchronous call to an asynchronous call shows a more concise way to convert the delegated method into an asynchronous execution method, thereby improving development efficiency. In addition, the method can convert the delegated method to use an asynchronous processing framework to achieve asynchronous processing, thereby achieving a downgraded processing effect.
[0070] Figure 5 This is a flowchart of a method for converting a synchronous call to an asynchronous call according to an exemplary embodiment. Figure 5 , the methods for converting synchronous calls to asynchronous calls may include:
[0071] Step S510: The proxy class receives the call request and sends the call request to the method interceptor through the invoke function.
[0072] In step S520, the method interceptor determines whether to forward the call request to the asynchronous middleware based on pre-set parameters. According to an exemplary embodiment, the method interceptor may determine whether to forward the call request to the asynchronous middleware based on the method's annotation type. A method annotation may be declared before the method to describe or annotate it. In this embodiment, the method annotation may, for example, indicate whether the method needs to be converted to an asynchronous call.
[0073] Step S530: When the call request meets the preset parameters, the call request is forwarded to the asynchronous middleware, which transmits the call request to the consumer monitoring service in an asynchronous call manner so that it can be sent to the corresponding service provider.
[0074] According to an example embodiment, when the call request does not meet the preset parameters, the service caller calls the service provider through a synchronous call method.
[0075] Figure 6 It is a system architecture diagram showing a method for converting synchronous calls to asynchronous calls according to another exemplary embodiment.
[0076] Reference Figure 6 The synchronous call to asynchronous call method may include a registration process. The registration process may include step 1: proxy class creation process.
[0077] According to an example embodiment, step 1 may include the following steps:
[0078] Step 1.1, build the proxy class.
[0079] According to an example embodiment, for JMQ-type middleware, a RegisterJMQAnnMethod method annotation class may be declared, including a registrant type (both a producer and a consumer by default) and a produced or subscribed topic.
[0080] Step 1.2, build an asynchronous consumer.
[0081] The consumer refers to the sender of the message, and the consumer established here is an asynchronous call consumer.
[0082] Step 1.3, register the asynchronous consumer to the context.
[0083] The context can store some initialization information of the system. When a user needs to use a related data source, he can first obtain the system context and then read the data source in a certain way.
[0084] Step 1.4, build an asynchronous producer.
[0085] The producer refers to the sender of the message, and the producer established here is an asynchronous call.
[0086] Step 1.5, register the asynchronous producer to the context.
[0087] According to the example embodiment, it may be first determined based on the annotation whether an asynchronous producer and an asynchronous consumer need to be constructed before executing steps 1.4 and 1.5.
[0088] Figure 7 1 is a system architecture diagram showing a method for converting synchronous calls to asynchronous calls according to another exemplary embodiment. Figure 7 The method of converting a synchronous call to an asynchronous call may include the following steps:
[0089] Step 1: The proxy class receives the call request on behalf of the original service provider and forwards it to the asynchronous middleware.
[0090] In step 2, the asynchronous middleware pushes the asynchronous message to the message listening service, which then calls the actual server. BaseCustomerListener is the base consumer listening class, which implements the onMessage method of MessageLister. Define an Object service property (the business class to be executed when consuming JMQ) and a Method method property. The method property retrieves the generic type set of method parameters. The monitored consumer is converted to the method input type of the business class. Then, call method.invoke(service, objArr) to execute the consumer's business code (i.e., the non-producer registered method annotated in step 1).
[0091] Create the RegisterJMQRequire class to implement the BeanPostProcessor interface. When the Spring container completes the instantiation of the Bean, obtain all methods declared in all target classes or interfaces and verify whether they are used. Figure 6 Annotation in the registration process, and declare the registration type as consumer, instantiate a class to convert it into a consumer monitoring class, and set the method and business class for it. The consumer sets the topic and listener, the number of retries, etc., so that all consumer monitoring is automatically registered.
[0092] JmqSendInterceptor intercepts all uses Figure 6 The annotation method in the registration process verifies whether the registration type is producer or both (self-production and self-sales), and sends the message queue (Note: JMQ unified degradation service can be connected here).
[0093] JmqRegisterAspect class, obtains all usage through Aop aspect Figure 6In the registration process, the annotation method is verified to be self-produced or producer, and the method input is converted into a Message message body, which is sent to the corresponding topic queue through MessageProducer. Otherwise, the method is executed according to the original logic.
[0094] The topic is a message identification string that represents a message type and is globally unique. The topic can be used to distinguish different business messages.
[0095] Figure 8 1 is a block diagram of a device for converting a synchronous call to an asynchronous call according to an exemplary embodiment. Figure 8 The synchronous call to asynchronous call conversion device may include: a request module 810, a first forwarding module 820, a second forwarding module 830, and a response module 840.
[0096] In the synchronous-to-asynchronous call conversion apparatus, a request module 810 is used by a service caller to send a call request. A first forwarding module 820 is used by a proxy class to receive the call request and forward it to the asynchronous middleware. A second forwarding module 830 is used by the asynchronous middleware to send the call request to the consumer listening service via an asynchronous message. A response module 840 is used by the consumer listening service to send the call request to the service provider so that the service provider can respond to the call request.
[0097] According to the synchronous call to asynchronous call conversion device of the present application, the proxied method can be converted into asynchronous processing using an asynchronous processing framework in a non-invasive manner, thereby achieving free switching between synchronous calls and asynchronous calls.
[0098] Figure 9 FIG. 1 is a schematic diagram of a system for converting synchronous calls to asynchronous calls according to another exemplary embodiment. Figure 9 The synchronous call to asynchronous call system may include: a client 910, a request forwarding server 920, and a server 930.
[0099] In the synchronous-to-asynchronous call system, client 910 sends a call request. Request forwarding server 920 receives the call request and forwards it to the asynchronous middleware. The asynchronous middleware sends the call request to the consumer listening service via an asynchronous message. The consumer listening service sends the call request to the server. Server 930 responds to the call request.
[0100] According to the synchronous call to asynchronous call system of the present application, the proxied method can be converted into asynchronous processing using an asynchronous processing framework in a non-invasive manner, thereby achieving free switching between synchronous calls and asynchronous calls.
[0101] Figure 10The present invention is a block diagram of an electronic device for converting a synchronous call to an asynchronous call according to an exemplary embodiment.
[0102] Refer to the following Figure 10 1000 according to this embodiment of the present application will be described. Figure 10 The electronic device 1000 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present disclosure.
[0103] like Figure 10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 to the random access memory (RAM) 1003. Various programs and data required for system operation are also stored in the RAM 1003. The CPU 1001, ROM 1002, and RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 804.
[0104] The following components are connected to the I / O interface 1005: an input section 1006 including a touch screen, keyboard, etc.; an output section 1007 including a liquid crystal display (LCD), speakers, etc.; a storage section 1008 including a flash memory, etc.; and a communication section 1009 including a wireless network card, a high-speed network card, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a semiconductor memory or a magnetic disk, is installed in the drive 1010 as needed, so that a computer program read therefrom can be installed in the storage section 1008 as needed.
[0105] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions of the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, a USB flash drive, a mobile hard disk, etc.) and includes a number of instructions for causing a computing device (such as a personal computer, a server, a mobile terminal, or a smart device, etc.) to execute the method according to the embodiments of the present invention.
[0106] Furthermore, the above-described figures are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention and are not intended to be limiting. It is readily understood that the processes illustrated in the above-described figures do not indicate or limit the temporal order of these processes. Furthermore, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0107] Other embodiments of the present invention will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow from the general principles of the invention and include common knowledge or customary techniques in the art not claimed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the invention being indicated by the claims.
[0108] It should be understood that the present invention is not limited to the detailed structures, drawings or implementations shown herein, but rather is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.
Claims
1. A method for converting a synchronous call to an asynchronous call, characterized in that: include: The service caller sends a call request; The proxy class receives the call request and forwards the call request to the asynchronous middleware; The asynchronous middleware sends the call request to the consumer listening service in the form of an asynchronous message; as well as The consumer monitoring service sends the call request to the service provider so that the service provider responds to the call request; The proxy class receives the call request and forwards the call request to the asynchronous middleware, including: The proxy class sends the call request to the method interceptor; The method interceptor determines whether to forward the call request to the asynchronous middleware according to preset parameters; and When the call request meets the preset parameters, the call request is forwarded to the asynchronous middleware.
2. The method according to claim 1, wherein Also includes: The service provider sends the return message of the call request to the consumer monitoring service; The consumer monitoring service sends the return message to the asynchronous middleware; The asynchronous middleware sends the return message to the proxy class; as well as The proxy class returns the return message to the service caller to complete the call request.
3. The method according to claim 1, wherein The proxy class receives the call request and forwards the call request to the asynchronous middleware, including: The proxy class receives the call request and sends the call request to the method interceptor through the invoke function.
4. The method according to claim 3, wherein The method interceptor determines whether to forward the call request to the asynchronous middleware according to preset parameters, including: The method interceptor determines whether to forward the call request to the asynchronous middleware according to the annotation type of the method.
5. The method according to claim 3, wherein Also includes: When the call request does not meet the preset parameters, the service caller calls the service provider through a synchronous call method.
6. The method according to claim 3, wherein Forwarding the call request to the asynchronous middleware includes: The method interceptor sends the call request to the message producer through the SendMessage function; and The message producer forwards the call request to the asynchronous middleware.
7. The method according to claim 1, wherein Also includes: Create the proxy class, consumer listening service, and producer during the initialization process.
8. The method according to claim 7, wherein The initialization process creates the proxy class, consumer listening service, and producer including: Spring core creates a proxy factory through the create function; The proxy factory creates the proxy class, consumer monitoring service, and producer through the create function.
9. The method according to claim 7, wherein The creation of proxy classes, consumer listening services, and producers during the initialization process also includes: After creating the consumer listening service, registering the consumer listening service with the context; and After the producer is created, the producer is registered with the context.
10. A device for converting synchronous calls to asynchronous calls, characterized in that: include: Request module, used for service callers to send call requests; A first forwarding module is used for the proxy class to receive the call request and forward the call request to the asynchronous middleware; The second forwarding module is used for the asynchronous middleware to send the call request to the consumer monitoring service in the form of an asynchronous message; as well as A response module, configured for the consumer to monitor the service and send the call request to the service provider so that the service provider can respond to the call request; The first forwarding module is used for the proxy class to send the call request to the method interceptor; the method interceptor determines whether to forward the call request to the asynchronous middleware based on preset parameters; and when the call request meets the preset parameters, forwards the call request to the asynchronous middleware.
11. A system for converting synchronous calls to asynchronous calls, characterized in that: include: Client, used to send call requests; A request forwarding server is used to receive the call request and send the call request to the method interceptor through the proxy class; The method interceptor determines whether to forward the call request to the asynchronous middleware according to preset parameters; and forwards the call request to the asynchronous middleware when the call request meets the preset parameters; the asynchronous middleware sends the call request to the consumer monitoring service in the form of an asynchronous message; the consumer monitoring service sends the call request to the server; as well as The server is configured to respond to the call request.
12. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 9.
13. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Data interaction processing method, apparatus and system
CN107277083A
Request message processing method, device and system, storage medium and processor
CN107819750A