A method and device for implementing service call

By using asynchronous response poller and Kafka queue to process asynchronous transaction response results in a microservice environment, the high concurrency performance problem when the database is used as a data coordinator is solved, and more efficient data coordination and resource utilization are achieved.

CN114090210BActive Publication Date: 2025-08-15BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111397560.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-23
Publication Date
2025-08-15
Estimated Expiration
2041-11-23

AI Technical Summary

Technical Problem

In a microservice environment, when using a database as a data coordinator, there are problems such as high performance consumption and low processing efficiency in high concurrency. Especially in the process of asynchronous to synchronous data coordination, the read and write performance caused by the query, insertion and deletion of database tables is poor, and there are a large number of empty polling operations that put pressure on the database.

Method used

The asynchronous response poller and message delivery queue (such as Kafka queue) are used to process the asynchronous transaction response results. The asynchronous response poller determines whether the result belongs to the thread of this service. If so, it is directly passed to the thread. Otherwise, it will be forwarded to the inter-service message delivery queue and processed by the message poller to avoid empty polling operations.

Benefits of technology

In the case of high concurrency, the system resource loss is reduced and processing efficiency is improved. Through the high performance and scale-out capabilities of Kafka queues, it can meet the needs of fast read and write, and improve system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090210B_ABST
    Figure CN114090210B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for implementing service calls, which belongs to big data. The method includes: when an asynchronous response poller of a service provider obtains an asynchronous transaction response result corresponding to a request of a service caller, judging whether the response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller based on the asynchronous transaction response result; if the judgment result is yes, passing the asynchronous transaction response result to the first thread and waking up the first thread to continue execution; if the judgment result is no, forwarding the asynchronous transaction response result to an inter-service messaging queue of the corresponding service provider; a message poller of the inter-service messaging queue obtains the asynchronous transaction response result, passes the asynchronous transaction response result to a second thread pre-blocked in a second service to which it belongs, and waking up the second thread to continue execution. Under high concurrency requirements, the method can effectively reduce the loss of system resources and improve processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed systems, and in particular to a method and device for implementing service invocation. Background Art

[0002] In a microservices environment, a single application is divided into a set of smaller services, called microservices. These services coordinate and collaborate with each other to deliver ultimate value to users. To ensure transactional data consistency, microservices often coordinate data asynchronously by converting data to synchronous data. This process uses a database as a data coordinator, writing asynchronous transaction responses to the database. Multiple microservice applications continuously poll database tables, retrieve and process the asynchronous transaction responses belonging to their respective servers. This asynchronous-to-synchronous data coordination involves querying, inserting, and deleting database tables. These operations involve transactions, which come at a cost in maintaining transaction consistency. This results in poor read and write performance. Hard disk I / O becomes a significant bottleneck when facing high-concurrency read and write demands. Furthermore, a large number of empty polling operations when there is no data can place significant pressure on the database. Therefore, using a database as a data coordinator can lead to high performance consumption and low processing efficiency in high-concurrency scenarios.

[0003] This section is intended to provide a background or context to the embodiments of the invention that are recited in the claims. No statement herein is admitted to be prior art by virtue of its inclusion in this section. Summary of the Invention

[0004] An embodiment of the present invention provides a method for implementing a service call, the method comprising:

[0005] When the asynchronous response poller of the service provider obtains the asynchronous transaction response result corresponding to the request of the service caller, it is determined based on the asynchronous transaction response result whether the asynchronous transaction response result belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller;

[0006] If the judgment result is yes, the asynchronous transaction response result is passed to the first thread, and the first thread is woken up to continue execution;

[0007] If the judgment result is no, forwarding the asynchronous transaction response result to the corresponding inter-service messaging queue of the service provider;

[0008] The message poller of the inter-service messaging queue obtains the asynchronous transaction response result, passes the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs, and wakes up the second thread to continue execution.

[0009] In one embodiment, the method for implementing the above service call further includes:

[0010] When the service provider is started, the preset asynchronous response poller and the message poller are started, and a thread waiting pool is created. The thread waiting pool is used to temporarily store blocked threads.

[0011] In one embodiment, before the asynchronous response poller of the service provider obtains the asynchronous transaction response result, the implementation method of the above service call further includes:

[0012] When the service provider receives the transaction request initiated by the service caller, it assembles an asynchronous transaction request message according to the preset interface rules and sends the asynchronous request message to the asynchronous middleware;

[0013] The thread processing the transaction request is stored in the thread waiting pool and the thread is blocked.

[0014] In one embodiment, determining, based on the asynchronous transaction response result, whether the asynchronous transaction response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller includes:

[0015] Parse the asynchronous transaction response result to obtain the application identifier of the service to which the asynchronous transaction response result belongs, and determine whether it belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller based on the application identifier of the service and the mapping relationship between each thread and the application identifier of the service.

[0016] In one embodiment, the inter-service messaging queue is a Kafka queue, and each of the Kafka queues corresponds to an application identifier;

[0017] The step of forwarding the asynchronous transaction response result to the corresponding inter-service messaging queue of the service provider includes:

[0018] According to the application identifier of the service to which the asynchronous transaction response result belongs, the Kafka queue corresponding to the application identifier is determined, and the asynchronous transaction response result is forwarded to the corresponding Kafka queue.

[0019] In one embodiment, the message poller is a Kafka message poller;

[0020] The message poller of the inter-service messaging queue obtains the asynchronous transaction response result and transmits the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs, including:

[0021] The Kafka message poller obtains and parses the asynchronous transaction response result from the Kafka queue to obtain the application identifier of the service to which the asynchronous transaction response result belongs. Based on the application identifier of the service and the mapping relationship between each thread and the application identifier, the second thread to which the asynchronous transaction response result belongs is determined, and the asynchronous transaction response result is passed to the second thread.

[0022] In one embodiment, after waking up the first thread to continue execution or waking up the second thread to continue execution, the method further includes:

[0023] The first thread or the second thread parses the asynchronous request response result according to a preset interface rule, assembles the response result according to the interface rule, and returns the result to the service caller.

[0024] The embodiment of the present invention further provides a device for implementing a service call, comprising: an asynchronous response poller module, a message poller module, a thread waiting pool module, a result delivery module, and a wake-up module, wherein:

[0025] an asynchronous response poller module configured to, upon obtaining an asynchronous transaction response result corresponding to a request of a service caller, determine, based on the asynchronous transaction response result, whether the asynchronous transaction response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller;

[0026] a result delivery module configured to deliver the asynchronous transaction response result to the first thread when the asynchronous response poller module determines that the result is yes; and forward the asynchronous transaction response result to the corresponding inter-service message delivery queue of the service provider when the asynchronous response poller module determines that the result is no;

[0027] The message poller module is configured to obtain the asynchronous transaction response result and pass the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs;

[0028] A wake-up module, configured to wake up the first thread or the second thread to continue execution;

[0029] The thread waiting pool module is used to temporarily store the blocked first thread and the second thread.

[0030] In one embodiment, the inter-service messaging queue is a Kafka queue, and each of the Kafka queues corresponds to an application identifier;

[0031] The result delivery module is specifically used to determine the Kafka queue corresponding to the application identifier of the service to which the asynchronous transaction response result belongs, and forward the asynchronous transaction response result to the corresponding Kafka queue.

[0032] In one embodiment, the message poller module is a Kafka message poller module;

[0033] The Kafka message poller module is specifically used to obtain and parse the asynchronous transaction response result from the Kafka queue, obtain the application identifier of the service to which the asynchronous transaction response result belongs, determine the second thread to which the asynchronous transaction response result belongs based on the application identifier of the service and the mapping relationship between each thread and the application identifier, and pass the asynchronous transaction response result to the second thread.

[0034] In one embodiment, the service call implementation device further includes:

[0035] The result returning module is used to parse the asynchronous request response result according to the preset interface rules, assemble the response result according to the interface rules and return the result to the service caller.

[0036] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned service call implementation method when executing the computer program.

[0037] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for implementing the above-mentioned service call is implemented.

[0038] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the implementation method of the above-mentioned service call is implemented.

[0039] In an embodiment of the present invention, when the asynchronous response poller of the service provider provided by the embodiment of the present invention obtains the asynchronous transaction response result corresponding to the request of the service caller, if the response result is the first thread pre-blocked in the first service corresponding to the asynchronous response poller, the first thread is directly sent and awakened for subsequent processing of the response result. If not, it is forwarded to the inter-service message passing queue so that the inter-service message passing queue message poller can determine the second thread pre-blocked in the second service to which it belongs based on the response result, and pass it and awaken the second thread for subsequent processing of the response result. In the asynchronous to synchronous data coordination process, the embodiment of the present invention preferentially uses the asynchronous response poller to determine whether it is processed by the blocked thread in the service application. If not, it is transferred to the corresponding thread in other service applications for processing. Compared with the technical solution of using a database as a data coordinator in the prior art, a large number of empty polling operations are avoided during the processing process. Under high concurrency requirements, it can effectively reduce the loss of system resources and improve processing efficiency.

[0040] In addition, the embodiment of the present invention further utilizes the Kafka queue and the corresponding Kafka message poller. The Kafka queue is a distributed message queue with high performance, persistence, multi-copy backup, and horizontal expansion capabilities. Through the Kafka queue and the corresponding Kafka message poller, fast reading and writing can be met in high concurrency situations, meeting the high performance requirements of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0042] Figure 1 This is one of the flow charts of the implementation method of service call in an embodiment of the present invention;

[0043] Figure 2 This is the second flowchart of the method for implementing service call in an embodiment of the present invention;

[0044] Figure 3 This is the third flowchart of the method for implementing service call in an embodiment of the present invention;

[0045] Figure 4 This is an information interaction diagram of an example in an embodiment of the present invention;

[0046] Figure 5This is a structural block diagram of a device for implementing service calls in an embodiment of the present invention. DETAILED DESCRIPTION

[0047] To make the purpose, technical solutions and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0048] The present invention belongs to big data technology. The embodiment of the present invention provides a method for implementing service call, referring to Figure 1 As shown, the following steps are included:

[0049] S11. When the asynchronous response poller of the service provider obtains the asynchronous transaction response result corresponding to the service caller's request, the service provider determines, based on the asynchronous transaction response result, whether the asynchronous transaction response result belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller; if the determination result is yes, executing the following step S12; otherwise, executing the following step S13;

[0050] In this step S11, by parsing the asynchronous transaction response result, the application identifier of the service to which the asynchronous transaction response result belongs can be obtained, and then based on the application identifier of the service and the mapping relationship between each thread and the application identifier, it is determined whether it belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller.

[0051] S12. Deliver the asynchronous transaction response result to the first thread, and wake up the first thread to continue execution;

[0052] S13: forwarding the asynchronous transaction response result to the corresponding inter-service messaging queue of the service provider;

[0053] S14. The message poller of the inter-service messaging queue obtains the asynchronous transaction response result, passes the asynchronous transaction response result to the pre-blocked second thread in the second service to which it belongs, and wakes up the second thread to continue execution.

[0054] When the asynchronous response poller of the service provider provided by the embodiment of the present invention obtains the asynchronous transaction response result corresponding to the request of the service caller, if the response result is the first thread pre-blocked in the first service corresponding to the asynchronous response poller, it directly sends and wakes up the first thread for subsequent processing of the response result. If not, it continues to be forwarded to the inter-service message passing queue, so that the inter-service message passing queue message poller can determine the second thread pre-blocked in the second service to which it belongs based on the response result, and pass it and wake up the second thread for subsequent processing of the response result. In the asynchronous to synchronous data coordination process, the embodiment of the present invention preferentially uses the asynchronous response poller to determine whether it is processed by the blocked thread in the service application. If not, it is transferred to the corresponding thread in other service applications for processing. A large number of empty polling operations are avoided in the processing process. Under high concurrency requirements, it can effectively reduce the loss of system resources and improve processing efficiency.

[0055] In this embodiment of the present invention, a service provider has multiple services, each of which requires at least one thread from a thread pool to execute its corresponding tasks at runtime. The service provider also has an asynchronous response poller (a resident thread responsible for polling responses to external asynchronous transactions), an inter-service messaging queue and a message poller for the inter-service messaging queue, and a thread wait pool for temporarily storing blocked threads.

[0056] In an embodiment of the present invention, in order to provide the fastest transaction response result to the service caller's request, improve the response speed and efficiency, and avoid the time caused by operations such as starting the asynchronous response poller, message poller, and creating a thread waiting pool when processing the response request, when the service provider starts, the preset asynchronous response poller and message poller are directly started, and a thread waiting pool is created.

[0057] In one embodiment, referring to Figure 2 As shown, before the asynchronous response poller of the service provider in step S11 obtains the asynchronous transaction response result, the method further performs the following steps S15 and S16;

[0058] S15. When the service provider receives the transaction request initiated by the service caller, it assembles the asynchronous transaction request message according to the preset interface rules and sends the asynchronous request message to the asynchronous middleware;

[0059] The above-mentioned asynchronous middleware may adopt message middleware such as Message Queue (MQ) to realize asynchronous processing of request messages.

[0060] S16: storing the thread processing the transaction request into the thread waiting pool and blocking the thread.

[0061] Blocking the current process means temporarily suspending the thread, stopping processing, and waiting for the asynchronous transaction response result to arrive before resuming to the awake state.

[0062] In one embodiment, the inter-service message transmission queue may be, for example, a Kafka queue, and each of the Kafka queues corresponds to an application identifier;

[0063] Correspondingly, in the above step S13, the asynchronous transaction response result is forwarded to the corresponding inter-service messaging queue of the service provider, which can be achieved, for example, by the following methods:

[0064] According to the application identifier of the service to which the asynchronous transaction response result belongs, the Kafka queue corresponding to the application identifier is determined, and the asynchronous transaction response result is forwarded to the corresponding Kafka queue.

[0065] The message poller may be, for example, a Kafka message poller;

[0066] Correspondingly, the above step S14 can be implemented, for example, in the following manner:

[0067] The Kafka message poller obtains and parses the asynchronous transaction response result to obtain the application identifier of the service to which the asynchronous transaction response result belongs. Based on the application identifier of the service and the mapping relationship between each thread and the application identifier, the Kafka message poller determines the second thread to which the asynchronous transaction response result belongs, passes the asynchronous transaction response result to the second thread, and wakes up the second thread to continue execution.

[0068] For example, each service application has a Kafka queue. The Kafka queue name can be the application ID of the service, and the application ID and the thread have a corresponding relationship. The Kafka message poller can find the thread that should process the asynchronous transaction response result based on the application ID of the service obtained by parsing, and pass the asynchronous transaction response result to it.

[0069] Kafka is a distributed publish-subscribe messaging system with high throughput and fast processing speed. A Kafka queue is a distributed message queue. It offers high performance, persistence, multiple replicas, and horizontal scalability. Producers write messages to the queue, and consumers retrieve messages from the queue to execute business logic. Kafka generally facilitates decoupling, peak load shaving, and asynchronous processing in architectural design. Kafka uses the concept of topics, where producers write messages and consumers read messages.

[0070] To achieve horizontal scalability, a topic is actually composed of multiple partitions. When encountering system bottlenecks, you can scale out by increasing the number of partitions. Message ordering is guaranteed within a single partition. Kafka appends each new message to the corresponding file, resulting in very high performance.

[0071] Kafka queues and Kafka message pollers are used to distribute asynchronous transaction response results. In high concurrency situations, this can achieve the effects of fast forwarding and fast processing, thereby improving response speed.

[0072] In one embodiment, referring to Figure 3 As shown, the implementation method of the service call provided by the embodiment of the present invention further performs the following step S17 after the above step S12 or S14:

[0073] S17. The first thread or the second thread parses the asynchronous request response result according to the preset interface rules, assembles the response result according to the interface rules, and returns the result to the service caller.

[0074] Let's take a simple example to illustrate. The signal flow diagram of this example is as follows Figure 4 The whole process is briefly described as follows:

[0075] 1. When the service provider starts, it synchronously starts the asynchronous response poller and Kafka message poller, and creates a thread waiting pool;

[0076] 2. When the service provider receives a transaction request initiated by the service caller, it completes logic such as data checking.

[0077] 3. Assemble the asynchronous transaction request message according to the interface rules. After sending the asynchronous transaction request message to the asynchronous middleware, store the current thread in the thread waiting pool and block it, waiting for the asynchronous transaction response result.

[0078] 4. The asynchronous response poller obtains the response result, parses the service application ID, and determines whether the thread is blocked within the application of this service. If so, execute 5; otherwise, execute 6.

[0079] A service provider has multiple services (e.g. Figure 4In the process of sending a request, the service caller may call one of the multiple services of the service provider, and one of the multiple services will process and return a response result. Therefore, when the asynchronous transaction response result of the transaction request is obtained, the asynchronous response poller needs to determine whether the asynchronous response result is processed by its own service. If so, it will be processed directly. Otherwise, it will be sent to other services for subsequent processing through the inter-service message queue.

[0080] Assuming that the service to which the asynchronous response poller belongs is service 1, and the application identifier of the service parsed from the asynchronous transaction response result belongs to service 2, then it is determined that the asynchronous transaction response result is not processed by the thread of service 1, and the following step 6 is executed. Conversely, if the application identifier of the service parsed from the asynchronous transaction response result belongs to service 1, then the following step 5 is directly executed.

[0081] 5. Parse the asynchronous request messageId from the response result, map the blocked thread according to the messageId, pass the response result to the blocked thread corresponding to the messageId and wake it up to continue execution.

[0082] 6. According to the service application ID, the asynchronous transaction response result is forwarded to the inter-service provider messaging Kafka queue (each service application has one Kafka queue, and the queue name is the application ID of the service).

[0083] According to the above example, the asynchronous transaction response result will be forwarded to the Kafka queue corresponding to the application identifier of service 2.

[0084] 7. The Kafka message poller obtains the asynchronous request response result belonging to the corresponding service from the Kafka queue, parses the response result to obtain the asynchronous request messageId, maps the blocked thread according to the messageId, passes the response result to the blocked thread corresponding to the messageId and wakes it up to continue execution.

[0085] For example, the Kafka message poller will obtain the asynchronous request response result from the Kafka queue corresponding to the application identifier of service 2, and then find the corresponding blocked thread based on the message identifier (messageId) of the asynchronous request contained in the asynchronous response result, and wake it up to continue executing the next steps.

[0086] 8. Parse the asynchronous request response result according to the interface rules, assemble the response result according to the interface rules and return the result to the service caller.

[0087] After being awakened, the thread will continue to assemble the asynchronous request response results according to the preset interface rules and then return them to the external service caller.

[0088] The present invention also provides a device for implementing a service call, as described in the following embodiments. Since the principle of the device to solve the problem is similar to the implementation method of the service call, the implementation of the device can refer to the implementation of the aforementioned service call implementation method, and the repeated parts will not be repeated.

[0089] An implementation device for service call provided by an embodiment of the present invention, referring to Figure 5 As shown, it includes: an asynchronous response poller module 51, a message poller module 52, a thread waiting pool module 53, a result delivery module 54 and a wake-up module 55, wherein:

[0090] The asynchronous response poller module 51 is configured to, upon obtaining an asynchronous transaction response result corresponding to a request from a service caller, determine, based on the asynchronous transaction response result, whether the asynchronous transaction response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller;

[0091] The result delivery module 54 is configured to deliver the asynchronous transaction response result to the first thread when the asynchronous response poller module determines that the result is yes; and forward the asynchronous transaction response result to the corresponding inter-service message delivery queue of the service provider when the asynchronous response poller module determines that the result is no;

[0092] A message poller module 52 is configured to obtain the asynchronous transaction response result and transmit the asynchronous transaction response result to a pre-blocked second thread in the second service to which the asynchronous transaction response result belongs;

[0093] A wake-up module 55 is configured to wake up the first thread or the second thread to continue execution;

[0094] The thread waiting pool module 53 is used to temporarily store the blocked first thread and the second thread.

[0095] In one embodiment, the inter-service messaging queue is a Kafka queue, and each of the Kafka queues corresponds to an application identifier;

[0096] Correspondingly, the result delivery module 54 is specifically configured to determine the Kafka queue corresponding to the application identifier of the service to which the asynchronous transaction response result belongs, and forward the asynchronous transaction response result to the corresponding Kafka queue.

[0097] In one embodiment, the above-mentioned message poller module 52 is a Kafka message poller module; the Kafka message poller module is specifically used to obtain and parse the asynchronous transaction response result from the Kafka queue, obtain the application identifier of the service to which the asynchronous transaction response result belongs, and determine the second thread to which the asynchronous transaction response result belongs based on the application identifier of the service and the mapping relationship between each thread and the application identifier, and pass the asynchronous transaction response result to the second thread.

[0098] An implementation device for service call provided by an embodiment of the present invention, referring to Figure 5 As shown, it also includes:

[0099] The result returning module 56 is used to parse the asynchronous request response result according to the preset interface rules, assemble the response result according to the interface rules and return the result to the service caller.

[0100] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.

[0101] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for implementing the above-mentioned service call is implemented.

[0102] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the implementation method of the above-mentioned service call is implemented.

[0103] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0104] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0105] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0106] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0107] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for implementing a service call, characterized in that: include: When the asynchronous response poller of the service provider obtains the asynchronous transaction response result corresponding to the request of the service caller, it is determined based on the asynchronous transaction response result whether the asynchronous transaction response result belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller; If the judgment result is yes, the asynchronous transaction response result is passed to the first thread, and the first thread is woken up to continue execution; If the judgment result is no, forwarding the asynchronous transaction response result to the corresponding inter-service messaging queue of the service provider; The message poller of the inter-service messaging queue obtains the asynchronous transaction response result, passes the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs, and wakes up the second thread to continue execution; Determining, according to the asynchronous transaction response result, whether the asynchronous transaction response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller includes: Parsing the asynchronous transaction response result to obtain an application identifier of the service to which the asynchronous transaction response result belongs, and determining whether the asynchronous transaction response result belongs to a first thread pre-blocked in the first service corresponding to the asynchronous response poller based on the application identifier of the service and a mapping relationship between each thread and the application identifier of the service; The inter-service messaging queue is a Kafka queue, and each of the Kafka queues corresponds to an application identifier; The step of forwarding the asynchronous transaction response result to the corresponding inter-service messaging queue of the service provider includes: Determine the Kafka queue corresponding to the application identifier of the service to which the asynchronous transaction response result belongs, and forward the asynchronous transaction response result to the corresponding Kafka queue; The message poller is a Kafka message poller; The message poller of the inter-service messaging queue obtains the asynchronous transaction response result and transmits the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs, including: The Kafka message poller obtains and parses the asynchronous transaction response result from the Kafka queue to obtain the application identifier of the service to which the asynchronous transaction response result belongs. Based on the application identifier of the service and the mapping relationship between each thread and the application identifier, the second thread to which the asynchronous transaction response result belongs is determined, and the asynchronous transaction response result is passed to the second thread.

2. The method according to claim 1, wherein The method further comprises: When the service provider is started, the preset asynchronous response poller and the message poller are started, and a thread waiting pool is created. The thread waiting pool is used to temporarily store blocked threads.

3. The method according to claim 2, wherein Before the asynchronous response poller of the service provider obtains the asynchronous transaction response result, the method further includes: When the service provider receives a transaction request initiated by the service caller, it assembles an asynchronous transaction request message according to the preset interface rules and sends the asynchronous request message to the asynchronous middleware; The thread processing the transaction request is stored in the thread waiting pool and the thread is blocked.

4. The method according to any one of claims 1 to 3, wherein After waking up the first thread to continue execution or waking up the second thread to continue execution, the method further includes: The first thread or the second thread parses the asynchronous request response result according to the preset interface rules, assembles the response result according to the interface rules and returns the result to the service caller.

5. A device for implementing a service call, characterized in that: include: Asynchronous response poller module, message poller module, thread waiting pool module, result delivery module and wake-up module, wherein: an asynchronous response poller module configured to, upon obtaining an asynchronous transaction response result corresponding to a request of a service caller, determine, based on the asynchronous transaction response result, whether the asynchronous transaction response result belongs to a first thread pre-blocked in a first service corresponding to the asynchronous response poller; a result delivery module configured to deliver the asynchronous transaction response result to the first thread when the asynchronous response poller module determines that the result is yes; and forward the asynchronous transaction response result to an inter-service messaging queue of a corresponding service provider when the asynchronous response poller module determines that the result is no; The message poller module is configured to obtain the asynchronous transaction response result and pass the asynchronous transaction response result to a pre-blocked second thread in the second service to which it belongs; A wake-up module, configured to wake up the first thread or the second thread to continue execution; A thread waiting pool module, used for temporarily storing the blocked first thread and the second thread; The asynchronous response poller module is specifically used to: parse the asynchronous transaction response result, obtain the application identifier of the service to which the asynchronous transaction response result belongs, and determine whether it belongs to the first thread pre-blocked in the first service corresponding to the asynchronous response poller based on the application identifier of the service and the mapping relationship between each thread and the application identifier of the service; the inter-service message passing queue is a Kafka queue, and each of the Kafka queues corresponds to the application identifier; forwarding the asynchronous transaction response result to the corresponding inter-service message passing queue of the service provider includes: determining the Kafka queue corresponding to the application identifier based on the application identifier of the service to which the asynchronous transaction response result belongs , and forwards the asynchronous transaction response result to the corresponding Kafka queue; the message poller is a Kafka message poller; the message poller of the inter-service messaging queue obtains the asynchronous transaction response result, and passes the asynchronous transaction response result to the second thread pre-blocked in the second service to which it belongs, including: the Kafka message poller obtains the asynchronous transaction response result from the Kafka queue and parses it to obtain the application identifier of the service to which the asynchronous transaction response result belongs, determines the second thread to which the asynchronous transaction response result belongs according to the application identifier of the service and the mapping relationship between each thread and the application identifier, and passes the asynchronous transaction response result to the second thread.

6. The device according to claim 5, characterized in that The inter-service messaging queue is a Kafka queue, and each of the Kafka queues corresponds to an application identifier; The result delivery module is specifically used to determine the Kafka queue corresponding to the application identifier of the service to which the asynchronous transaction response result belongs, and forward the asynchronous transaction response result to the corresponding Kafka queue.

7. The device according to claim 6, characterized in that The message poller module is a Kafka message poller module; The Kafka message poller module is specifically used to obtain and parse the asynchronous transaction response result from the Kafka queue, obtain the application identifier of the service to which the asynchronous transaction response result belongs, determine the second thread to which the asynchronous transaction response result belongs based on the application identifier of the service and the mapping relationship between each thread and the application identifier, and pass the asynchronous transaction response result to the second thread.

8. The device according to any one of claims 5 to 7, characterized in that Also includes: The result return module is used to parse the asynchronous request response results according to the preset interface rules, assemble the response results according to the interface rules and return the results to the service caller.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method for implementing the service call according to any one of claims 1 to 4 is implemented.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for implementing the service call according to any one of claims 1 to 4 is implemented.

11. A computer program product, characterized in that The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the service call implementation method of any one of claims 1 to 4.

Citation Information

Patent Citations

  • Synchronous communication method and system for distributed cloud platform and Internet of Things intelligent terminal based on MQTT asynchronous communication scene

    CN111580995A

  • Asynchronous data processing method and device

    CN112099864A