A micro-service framework gateway processing method, a protocol conversion gateway, an electronic device and a storage medium
The protocol conversion gateway and asynchronous coroutine high-concurrency mode solve the problem of protocol inconsistency between microservices, realize flexible configuration and resource reuse of heterogeneous protocols, and reduce system construction costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- THE QUARTERMASTER RES INST OF THE GENERAL LOGISTICS DEPT OF THE CPLA
- Filing Date
- 2024-09-20
- Publication Date
- 2026-05-01
AI Technical Summary
In a microservices framework, different microservices may be developed at different times, which may lead to the use of different network communication protocols, resulting in the inability of microservices to communicate and call each other.
A protocol conversion gateway enables a high-concurrency asynchronous coroutine mode, parses service call requests, obtains communication protocol configurations, retrieves protocol conversion rules from the configuration center, and automatically generates or uses existing functions in the protocol processor to perform protocol conversion, ensuring the consistency of communication protocols between different microservices.
It enables the reuse of microservice resources across different technologies and environments, reduces the cost of building new services, and improves the system's management and monitoring capabilities.
Smart Images

Figure CN119996381B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a microservices framework gateway processing method, a protocol conversion gateway, an electronic device, and a storage medium. Background Technology
[0002] Microservice frameworks make applications more modular, easier to develop and maintain, and each microservice runs in a different process, which is isolated from each other, so the failure of one service process will not cause the whole system to become unavailable.
[0003] A gateway is a key component in a microservice architecture. Its main function is to encapsulate the interfaces of all microservices, providing a unified access interface to the outside world. It routes client requests to the appropriate microservice instances and repackages the responses returned by the microservices into a format that meets the client's expectations. Internally, the gateway can also act as the entry point for microservices, managing and monitoring their status and performance by registering them with the gateway center. In this way, the gateway can control all traffic and provide a centralized control point for microservices, making the entire application easier to manage and monitor.
[0004] The gateway needs to identify the protocol of the requests sent by the client to determine the protocol type used by the client. Based on the protocol type used by the client, the gateway translates the client's request into a protocol type supported by the backend service to complete the request proxy. For different types of data sources, different microservice technologies can be used for querying and accessing the data based on its format and characteristics. For example, the lightweight FLASK backend framework can be used to query relational databases like MySQL, the high-compression gRPC protocol can be used to transmit large-scale time-series data, and the Spring framework can be used to access non-relational databases like MongoDB.
[0005] In existing technologies, under the microservice framework, there is a problem that different microservices may not be able to communicate and call each other due to different network communication protocols used at different development times. Summary of the Invention
[0006] To address the aforementioned technical problems, this invention provides a microservice framework gateway processing method, a protocol conversion gateway, an electronic device, and a storage medium, wherein...
[0007] A gateway processing method for a microservice framework includes the following steps:
[0008] Step S101: The business processing microservice in the business system registers the registration information with the registration center;
[0009] Step S102: The business system administrator publishes the protocol format configuration file and protocol conversion configuration file used by the business processing microservice to the configuration center;
[0010] Step S103: When the first business processing microservice needs to use the function of the second business processing microservice, it sends a service call request for the second business processing microservice to the protocol conversion gateway. The first business processing microservice is the source service of the service call request, and the second business processing microservice is the target service of the service call request. The service call request uses the communication protocol used by the source service.
[0011] Step S104: The protocol conversion gateway receives the service call request and performs subsequent processing on the service call request in an asynchronous coroutine high-concurrency mode;
[0012] Step S105: The protocol conversion gateway parses the service call request, obtains the target service, and retrieves the communication protocol configuration of the source service and the target service of the service call request from the configuration center;
[0013] Step S106: The protocol conversion gateway determines whether the communication protocols used by the source service and the target service of the service call request are consistent;
[0014] Step S107: If the communication protocol used by the source service and the target service of the service call request is inconsistent, the communication protocol used by the service call request is converted to the communication protocol used by the target service using the protocol conversion gateway. If the communication protocol used by the source service and the target service of the service call request is consistent, the service call request is not processed.
[0015] Step S108: Send the service call request to the target service to complete the service call.
[0016] Further, step S101 specifically includes: the business processing microservice sends registration information to the registration center; the registration center writes the received new registration information into the registry and deletes the old registration information of the business processing microservice, so that the business processing microservice can be discovered and accessed by other business processing microservices. A business processing microservice has multiple microservice instances; different instances of the same business processing microservice have the same IP address and different port numbers; any microservice instance can implement all the functions of the business processing microservice; and the registration center records the registration information of all business processing microservices in the entire business system.
[0017] Furthermore, step S101 also includes:
[0018] For successfully registered business processing microservices, the registry center periodically performs health checks on their microservice instances. Health checks involve checking relevant parameters of the microservice instance's running status. Microservice instances that pass the check provide service discovery to other business processing microservices, while microservice instances that fail the check are automatically taken offline and their registration information is deleted from the registry center. Business system administrators can manually deregister business processing microservices and update their registration information as needed.
[0019] Further, in step S102, the protocol format configuration file and the protocol conversion configuration file between different communication protocols in the configuration center are published in XML format and can be manually configured; the protocol format configuration file records the protocol name, basic protocol parameters and parameter types, protocol transmission data encapsulation format, and protocol transmission data type; the protocol conversion configuration file records the mapping relationship between different data types between the two specified different communication protocols and the protocol processing function name that implements the conversion function of the two specified different communication protocols.
[0020] A protocol conversion gateway, comprising:
[0021] The request receiving module is used to obtain service call requests from clients or business processing microservices deployed in a microservice cluster, wherein the service call requests use the communication protocol used by their source services;
[0022] The communication module is used to implement concurrent processing of service call requests;
[0023] The protocol parsing module is used to parse the received service call request and obtain the source service and target service of the service call request;
[0024] The protocol judgment module is used to determine whether the communication protocol used by the currently processed service call request is the same as the communication protocol used by the target service. When the communication protocol used by the service call request is the same as the communication protocol used by the target service, the service call request is directly allowed.
[0025] The protocol conversion module is used to convert the communication protocol used in the service call request to the communication protocol used in the target service when the communication protocol used in the service call request is different from the communication protocol used in the target service.
[0026] The request forwarding module is used to send service call requests to the target service.
[0027] Furthermore, the communication module is also used to implement the following steps: using an asynchronous coroutine high-concurrency mode to concurrently process call requests. When the protocol conversion gateway receives a service call request, it enables an asynchronous coroutine to process the service call request, avoiding blocking the main thread while maintaining responsiveness to other service call requests. Specifically, a coroutine pool is used to maintain each coroutine that processes a service call request, a mutex lock class is used to control concurrent access, an event loop is used to schedule and manage all coroutines and asynchronous IO events, and the relevant coroutines are notified to continue execution when an IO event occurs.
[0028] Furthermore, the protocol conversion module includes:
[0029] The configuration reading unit is used to obtain the protocol format configuration file and protocol conversion configuration file of the communication protocol used by the source service and the target service of the service call request. It reads the protocol format configuration file of the communication protocol used by the source service of the service call request, the protocol format configuration file of the communication protocol used by the target service of the service call request, and the protocol conversion configuration file of the two protocols from the configuration center, and obtains the protocol format used by the two services and the mapping rules for the two services.
[0030] The conversion judgment unit is used to determine whether the protocol processor can complete the conversion of the protocol used in the service call request, and to determine whether there is a protocol processing function in the protocol processor that takes the protocol format configuration file of the communication protocol used by the source service of the service call request and the protocol format configuration file of the communication protocol used by the target service of the service call request as input.
[0031] The method generation unit is used to generate a protocol processing function in the protocol processor according to the read conversion configuration file. If there is no corresponding protocol processing function in the protocol processor, the protocol processing function is automatically generated in the protocol processor according to the protocol conversion configuration files of the two protocols.
[0032] A protocol processor is used to convert the communication protocol used in the service call request into the communication protocol used by the target service of the service call request. If a corresponding protocol processing function exists in the protocol processor, the protocol format configuration file of the communication protocol used by the source service of the service call request and the protocol format configuration file of the communication protocol used by the target service of the service call request are input into the protocol processor to convert the communication protocol used in the service call request into the communication protocol used by the target service of the service call request.
[0033] Furthermore, the request forwarding module is also used to implement the following steps: using a round-robin algorithm to discover business processing microservices and perform round-robin load balancing. First, the name of the business processing microservice is taken as input. Then, a service call request is sent, all microservice instances of the specified business processing microservice are generated in a loop, and the next microservice instance is selected through a round-robin algorithm.
[0034] Each time a microservice instance is generated, an index value is added to ensure that all microservice instances are polled evenly. If the index value is greater than the length of the microservice instance list, it is reset to zero to achieve cyclic polling and avoid forwarding service call requests to a single microservice instance.
[0035] Furthermore, the method generation unit generates a protocol processing function, which includes the following steps:
[0036] The function is declared, and according to the preset protocol processing function template, the preset function name is replaced with the processing function name in the read protocol conversion configuration file. The preset inputs are set sequentially as the service request, the protocol format configuration file of the communication protocol used by the source service of the service request, the protocol format configuration file of the communication protocol used by the target service of the service request, and the protocol conversion configuration file of the two communication protocols. The preset output is set as the service call request using the communication protocol used by the target service, and the function name is recorded in the generated function declaration file.
[0037] The function parses the communication protocol attribute fields and data fields carried in the service call request from the service request. According to the mapping rules of the communication protocol used by the source service and the communication protocol used by the target service in the protocol conversion file, the function converts the parsed communication protocol attribute fields and data fields carried in the service call request into the format required by the communication protocol used by the target service as needed. The function then concatenates the converted attribute fields and data fields according to the format requirements of the communication protocol used by the target service and outputs them as the function output.
[0038] An electronic device includes a memory, a processor, a communication bus, and a communication interface. The memory stores a computer program, and the processor executes the computer program to perform the steps of the microservice framework gateway processing method described above.
[0039] A computer-readable storage medium storing a computer program configured to execute the steps of the microservice framework gateway processing method described above at runtime.
[0040] This invention enables flexible configuration of heterogeneous protocol conversion rules, greatly improving the reuse and common use of service resources in different technologies and environments. Attached Figure Description
[0041] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0042] Figure 1 This is a flowchart of a microservice framework gateway processing method provided in an embodiment of the present invention;
[0043] Figure 2 This is a schematic diagram of a heterogeneous protocol microservice system provided in an embodiment of the present invention;
[0044] Figure 3 This is a schematic diagram of the protocol conversion gateway provided in an embodiment of the present invention;
[0045] Figure 4 This is a schematic diagram of the protocol conversion module provided in an embodiment of the present invention;
[0046] Figure 5 A protocol conversion flowchart provided for embodiments of the present invention;
[0047] Figure 6 This is a schematic diagram illustrating the protocol conversion principle provided in an embodiment of the present invention;
[0048] Figure 7 This is a schematic diagram of an electronic device with a configurable heterogeneous protocol provided in an embodiment of the present invention. Detailed Implementation
[0049] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.
[0050] Microservices architecture makes applications more modular, easier to develop and maintain, and each microservice runs in a separate process, isolated from each other, so the failure of one service process will not cause the entire system to become unavailable. However, because the development time of each microservice is different, the network transmission protocols used by different microservices may be different. In this case, when a microservice calls other microservices in the system, there is a protocol conversion problem between microservices.
[0051] To maximize the reuse and common use of microservice resources across different technologies and environments, and to reduce the construction cost of new services, this invention provides a configurable heterogeneous protocol conversion microservice framework gateway processing method and a protocol conversion gateway applied to a heterogeneous protocol microservice system. The heterogeneous protocol microservice system includes a client, a registry center, a configuration center, a protocol conversion gateway, and a microservice cluster. Specifically, as shown... Figure 2 As shown:
[0052] On the client side, users send call requests to a specific microservice in the microservice system through a visual interface, and the system returns the response to the user.
[0053] Registration Center 201 records the registration information provided by services in a healthy state in the system, so that other services can discover and call them.
[0054] Protocol conversion gateway 202 receives service call requests from clients for a specific service in the microservice cluster or from a microservice in the microservice cluster for another microservice in the microservice cluster. It converts the communication protocol used in the received service call request into a service call request using the target service's communication protocol according to the target service of the service call request, and sends the converted service call request to the microservice instance running the target service to complete the service call.
[0055] Configuration Center 203 publishes microservice configurations and protocol conversion configuration files between microservices using different communication protocols.
[0056] Microservice cluster 204 runs multiple microservices with heterogeneous protocols that provide services to the system, where each microservice has multiple microservice instances.
[0057] In this embodiment of the invention, the registration center forwards service call requests to healthy instances in the target microservice cluster to complete mutual calls between microservices using heterogeneous protocols. The configuration center publishes protocol format configuration files for all microservices and protocol conversion configuration files between different microservices. All microservices can read the required configuration files from the configuration center. Through the protocol conversion gateway, service call requests using different communication protocols can be converted into service call requests using the communication protocol used by the target service. Thus, for a new microservice, there is no need to configure the existing microservices separately. The new microservice only needs to register its registration information with the registration center and publish the relevant configuration of the new microservice in the configuration center to access the system for its existing microservices to call and invoke the existing microservices. This avoids the incompatibility problem of communication protocols between different microservices, achieves efficient utilization of old microservices, and reduces the system construction cost of new microservices.
[0058] This invention provides a configurable microservice framework gateway processing method for heterogeneous protocols, such as... Figure 1 As shown, the method includes:
[0059] S102, publish the protocol format configuration file and protocol conversion configuration file used by the business processing microservice to the configuration center. The configuration center publishes the protocol format configuration files supported by all microservices and the protocol conversion configuration files between different communication protocols. The protocol format configuration files and protocol conversion configuration files are written and published in XML format. After adding a microservice, it is only necessary to publish the protocol format configuration file of the communication protocol used by the new microservice and the protocol conversion configuration file between the new microservice and the existing microservice in the configuration center to complete the configuration of the system after adding the microservice.
[0060] S103, when the first business processing microservice needs to use the functionality of the second business processing microservice, it sends a service call request for the second business processing microservice to the protocol conversion gateway. Here, the first business processing microservice is the source service of the service call request, and the second business processing microservice is the target service of the service call request. The service call request uses the communication protocol used by the source service. For example, the protocol used by the first microservice may include HTTP, gRPC, TCP, etc.
[0061] S104, the protocol conversion gateway receives the service call request and processes it in a high-concurrency asynchronous coroutine mode. Upon receiving the service call request, the protocol conversion gateway uses asynchronous coroutine technology to process the received service call request in parallel.
[0062] S105, the protocol conversion gateway parses the service call request, obtains the target service, and retrieves the communication protocol configuration of the source service and target service from the configuration center. Upon receiving the service call request, the protocol conversion gateway parses it to obtain the source service address, encapsulated data, target service address, and target call method contained in the request. It then retrieves the corresponding service name from the registry based on the source and target service addresses, and finally retrieves the communication protocol configuration of the source and target services from the configuration center based on the obtained service name.
[0063] S106, the protocol conversion gateway determines whether the communication protocols used by the source service and the target service in a service call request are consistent. It uses a protocol format configuration file obtained from the configuration center to determine the consistency of the communication protocols used by the source and target services. The determination method involves forward and reverse matching of the fields in the protocol format configuration file. First, the source service's protocol format configuration file is read line by line, and then a match is searched in the target service's protocol format configuration file. If the content in the source service's protocol format configuration file can be matched in the target service's protocol format configuration file, then a reverse match is performed. The target service's protocol format configuration file is read line by line, and then a match is searched in the source service's protocol format configuration file. If the content in the target service's protocol format configuration file can be matched in the source service's protocol format configuration file, then the communication protocols used by the source and target services are considered consistent.
[0064] S107, if the communication protocols of the requesting source service and the target service are inconsistent, the protocol conversion gateway is used to convert the communication protocol used in the service call request to the communication protocol used by the target service. The protocol conversion gateway inputs the service call request, the protocol format configuration file of the source service, and the protocol format configuration file of the target service into its built-in protocol processor, and converts the communication protocol used in the service call request to the communication protocol used by the target service. If the communication protocols used by the source service and the target service are consistent, the service call request is not processed.
[0065] Step S108: Send the service call request to the target service to complete the service call. The protocol conversion gateway forwards the service call request to the target microservice instance with a lower load to complete the service call, based on the usage of the target microservice instance.
[0066] This invention provides a protocol conversion gateway, comprising six modules: a request receiving module, a communication module, a protocol parsing module, a protocol judgment module, a protocol conversion module, and a response forwarding module. Figure 3 As shown:
[0067] The request receiving module 301 is used to obtain service call requests from clients or business processing microservices deployed in a microservice cluster, wherein the service call requests use the communication protocol of their source service.
[0068] The communication module 302 uses an asynchronous high-concurrency mode to achieve concurrent processing of service call requests;
[0069] The protocol parsing module 303 is used to parse the received service call request and obtain the source service and target service of the service call request;
[0070] The protocol judgment module 304 is used to determine whether the communication protocol used by the currently processed service call request is the same as the communication protocol used by the target service. When the communication protocol used by the service call request is the same as the communication protocol used by the target service, the service call request is directly allowed.
[0071] The protocol conversion module 305 is used to convert the communication protocol used in the service call request to the communication protocol used in the target service when the communication protocol used in the service call request is different from the communication protocol used in the target service.
[0072] The request forwarding module 306 is used to send service call requests to the target service and perform load balancing on microservice instances.
[0073] In this embodiment of the invention, an asynchronous coroutine high-concurrency mode is used in the communication module to process service call requests received by the gateway.
[0074] Asynchronous processing relies on I / O multiplexing mechanisms, which avoid the resource waste and inefficiency of blocking I / O. In the asynchronous programming model, each task is non-blocking, and the system uses an event loop to manage task execution and event processing. When a task needs to perform I / O operations or wait, the system converts it into an event and adds it to the event queue, then continues executing other tasks until an event is triggered and processed. The I / O input module responds to user service call requests through sockets and distributes these requests to different processes for processing. Each process can be divided into several threads, and these threads are implemented using a coroutine mechanism. The coroutine mechanism is a key technology for asynchronous coroutine high-concurrency mode, allowing the management of the execution and switching of multiple coroutine tasks within a single thread. Each coroutine task can execute and suspend independently, reducing thread context switching and improving efficiency. For example, in the gateway communication module, the program can use Gevent to implement asynchronous I / O operations as coroutines. It uses greenlet coroutines to encapsulate native Python coroutines, achieving high-concurrency processing. When processing HTTP requests, the relevant modules use the coroutine-based HTTP client provided by Gevent to achieve non-blocking network communication, and use coroutines to handle requests and responses, thereby achieving efficient concurrent processing capabilities.
[0075] This invention provides a protocol conversion module, such as... Figure 4 As shown, it includes:
[0076] The configuration reading unit 401 is used to obtain the format of the communication protocol used by the source service of the service call request and the mapping rules between the communication protocol used by the target service of the service call request.
[0077] The conversion judgment unit 402 is used to determine whether the protocol processor can complete the conversion of the service call request using the communication protocol.
[0078] The method generation unit 403 is used to generate protocol processing functions within the protocol processor based on the read protocol conversion configuration file. The method generation unit refers to a preset protocol processing function template within the protocol processor and the protocol conversion configuration file read from the configuration center to generate protocol processing functions for the protocol processor that can implement the two communication protocols recorded in the conversion configuration file.
[0079] Protocol processor 404 is used to convert the communication protocol used in the service call request into the communication protocol used by the target service of the call request.
[0080] This invention provides a protocol conversion method, such as... Figure 5 As shown, the specific implementation steps are as follows:
[0081] Step S501: Read the protocol format configuration file of the communication protocol used by the source service of the service call request, the protocol format configuration file of the communication protocol used by the target service of the service call request, and the protocol conversion configuration file of the two protocols from the configuration center, and obtain the protocol format used by the two services and the mapping rules for the two services.
[0082] Step S502: Determine whether a protocol processing function exists in the protocol processor that takes the protocol format configuration file of the communication protocol used by the source service of the call request and the protocol format configuration file of the communication protocol used by the target service of the call request as input.
[0083] Step S503: If there is no corresponding protocol processing function in the protocol processor, the protocol processing function will be automatically generated in the protocol processor according to the protocol conversion configuration file of the two communication protocols.
[0084] Step S504: If the protocol processor has a corresponding protocol processing function, input the protocol format configuration file of the communication protocol used by the source service of the call request and the protocol format configuration file of the communication protocol used by the target service of the call request into the protocol processor, so as to convert the communication protocol used by the service call request into the communication protocol used by the target service of the service call request.
[0085] The method generation unit, referring to the preset protocol conversion method template within the protocol processor and the protocol conversion configuration file read from the configuration center, generates protocol processing functions for the protocol processor that can perform the conversion of the two communication protocols recorded in the protocol conversion configuration file. This embodiment of the invention provides a method for generating protocol processing functions in the method generation unit, the principle of which is as follows: Figure 6 As shown, the specific implementation steps are as follows:
[0086] Step 1: Declare the function. Based on the preset protocol processing function template, replace the preset function name with the processing function name in the read protocol conversion configuration file. Set the preset inputs sequentially as the service request, the protocol format configuration file of the communication protocol used by the source service of the service request, the protocol format configuration file of the communication protocol used by the target service of the service request, and the protocol conversion configuration file of the two communication protocols. Set the preset output as the service call request using the communication protocol used by the target service, and record the function name in the generated function declaration file.
[0087] Step 2: Implement a function to parse the communication protocol attribute fields and data fields carried in the service call request from the service request. According to the mapping rules of the communication protocol used by the source service and the communication protocol used by the target service in the protocol conversion file, the parsed attributes and data fields of the communication protocol used by the source service and the target service of the service call request are converted into the format required by the communication protocol of the target service as needed. The converted attributes and data fields are then concatenated according to the format requirements of the communication protocol of the target service and output as the function.
[0088] This invention provides an electronic device, such as... Figure 7 As shown, it includes: a communication bus 701, a processor 702, a memory 703, and a communication interface 704, which are described in detail below:
[0089] The communication bus 701 is the main communication path connecting various components. It can transmit data and control signals to enable communication and coordination between components. The communication bus can be a peripheral component interconnect standard (PCI) bus or an extended industry standard structure (EISA) bus, etc., and usually includes various sub-buses such as address bus, data bus, and control bus to support data transmission, address identification, and control signal transmission between devices.
[0090] The processor 702 is one of the core components of the electronic device. It is configured to run a specific computer program to perform the steps described in any of the above method embodiments, and is responsible for processing and analyzing the received data, controlling the operating state of the device, and performing various functional operations as needed. The processor can be a general-purpose processor, mainly including: a central processing unit (CPU), a network processor (NP), or a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0091] The memory 703 is used to store computer programs, data, and temporarily stored information required for the operation of the electronic device. The computer programs stored include instructions for implementing the method steps, as well as other necessary software and data. The memory mainly includes random access memory (RAM) and non-volatile memory. In addition, the memory may also be one or more storage devices located away from the aforementioned processor.
[0092] Communication interface 704 is the interface through which the aforementioned conversion gateway communicates with electronic devices. It is responsible for managing data transmission and communication connections between electronic devices and other devices, so as to realize interaction and data exchange with other devices.
[0093] This invention provides a computer-readable storage medium storing a computer program containing a series of instructions. These instructions are intended to execute the steps in any of the above-described protocol conversion method embodiments when run on a computer system. When the instructions in the storage medium are executed on the computer system, they enable the computer to effectively convert service requesters' requests into requests for different protocols applicable to multiple microservices, eliminating the need to develop dedicated gateways for each different protocol, thereby greatly simplifying the development process and improving development efficiency.
[0094] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A gateway processing method for a microservice framework, characterized in that, The method is applied to a heterogeneous protocol microservice system, which includes a client, a registry center, a configuration center, a protocol conversion gateway, and a microservice cluster, and includes the following steps: Step S101: The business processing microservice in the business system registers the registration information with the registration center; Step S102: The business system administrator publishes the protocol format configuration file and protocol conversion configuration file used by the business processing microservice to the configuration center. The configuration center publishes the protocol format configuration files supported by all microservices to the microservice cluster and the protocol conversion configuration files between different communication protocols to the protocol conversion gateway. Step S103: When the first business processing microservice needs to use the function of the second business processing microservice, it sends a service call request for the second business processing microservice to the protocol conversion gateway. The first business processing microservice is the source service of the service call request, and the second business processing microservice is the target service of the service call request. The service call request uses the communication protocol used by the source service. Step S104: The protocol conversion gateway receives the service call request and performs subsequent processing on the service call request in an asynchronous coroutine high-concurrency mode; Step S105: The protocol conversion gateway parses the service call request, obtains the target service, and retrieves the communication protocol configuration of the source service and the target service of the service call request from the configuration center; Step S106: The protocol conversion gateway determines whether the communication protocols used by the source service and the target service of the service call request are consistent; Step S107: If the communication protocols used by the source service and the target service of the service call request are inconsistent, the communication protocol used by the service call request is converted to the communication protocol used by the target service using the protocol conversion gateway. If the communication protocols used by the source service and the target service are consistent, the service call request is not processed. The protocol conversion gateway dynamically generates corresponding protocol processing functions to perform protocol conversion based on the protocol conversion configuration file read from the configuration center. The protocol processing functions include: The function declaration is used to replace the preset function name with the processing function name in the read protocol conversion configuration file according to the preset protocol processing function template. The preset input is set sequentially as the service request, the protocol format configuration file of the communication protocol used by the source service of the service request, the protocol format configuration file of the communication protocol used by the target service of the service request, and the protocol conversion configuration file of the two communication protocols. The preset output is set as the service call request using the communication protocol used by the target service, and the function name is recorded in the generated function declaration file. The function is implemented to parse the attribute fields of the communication protocol used by the source service of the service call request and the data fields carried in the request from the service request. According to the mapping rules of the communication protocol used by the source service of the service request and the communication protocol used by the target service of the service request in the protocol conversion configuration file, the function converts the parsed attribute fields of the communication protocol used by the source service of the service call request and the data fields carried in the service call request into the format required by the communication protocol used by the target service of the service call request as needed. The function then concatenates the converted attribute fields and data fields according to the format requirements of the communication protocol used by the target service of the service call request and outputs them as functions. Step S108: Send the service call request to the target service to complete the service call.
2. The microservice framework gateway processing method according to claim 1, characterized in that, Step S101 specifically includes: the business processing microservice sends its registration information to the registration center; the registration center writes the received new registration information into the registry and deletes the old registration information of the business processing microservice, so that the business processing microservice can be discovered and accessed by other business processing microservices. A business processing microservice has multiple microservice instances; different instances of the same business processing microservice have the same IP address and different port numbers; any microservice instance can implement all the functions of the business processing microservice; and the registration center records the registration information of all business processing microservices in the entire business system.
3. The microservice framework gateway processing method according to claim 2, characterized in that, Step S101 further includes: For successfully registered business processing microservices, the registry center periodically performs health checks on their microservice instances. Health checks involve checking relevant parameters of the microservice instance's running status. Microservice instances that pass the check provide service discovery to other business processing microservices, while microservice instances that fail the check are automatically taken offline and their registration information is deleted from the registry center. Business system administrators can manually deregister business processing microservices and update their registration information as needed.
4. The microservice framework gateway processing method according to claim 1, characterized in that, In step S102, the protocol format configuration file and the protocol conversion configuration file between different communication protocols in the configuration center are published in XML format and can be manually configured. The protocol format configuration file records the protocol name, basic protocol parameters and parameter types, protocol transmission data encapsulation format, and protocol transmission data type. The protocol conversion configuration file records the mapping relationship between different data types of the specified two different communication protocols and the protocol processing function name that implements the conversion function of the specified two different communication protocols.
5. A protocol conversion gateway, characterized in that, include: The request receiving module is used to obtain service call requests from clients or business processing microservices deployed in a microservice cluster, wherein the service call requests use the communication protocol used by their source services; The communication module is used to implement concurrent processing of service call requests; The protocol parsing module is used to parse the received service call request and obtain the source service and target service of the service call request; The protocol judgment module is used to determine whether the communication protocol used by the currently processed service call request is the same as the communication protocol used by the target service. When the communication protocol used by the service call request is the same as the communication protocol used by the target service, the service call request is directly allowed. A protocol conversion module is configured to convert the communication protocol used in the service call request to the communication protocol used in the target service when the communication protocol used in the service call request is different from that used in the target service. The protocol conversion module includes: The configuration reading unit is used to obtain the protocol format configuration file and protocol conversion configuration file of the communication protocol used by the source service and the target service of the service call request. It reads the protocol format configuration file of the communication protocol used by the source service of the service call request, the protocol format configuration file of the communication protocol used by the target service of the service call request, and the protocol conversion configuration file of the two protocols from the configuration center, and obtains the protocol format used by the two services and the mapping rules for the two services. The conversion judgment unit is used to determine whether the protocol processor can complete the conversion of the protocol used in the service call request, and to determine whether there is a protocol processing function in the protocol processor that takes the protocol format configuration file of the communication protocol used by the source service of the service call request and the protocol format configuration file of the communication protocol used by the target service of the service call request as input. The method generation unit is used to generate protocol processing functions within the protocol processor based on the read conversion configuration file. If a corresponding protocol processing function does not exist within the protocol processor, the protocol processing function is automatically generated within the protocol processor according to the protocol conversion configuration files of the two protocols. The generation of the protocol processing function includes the following steps: The function is declared, and according to the preset protocol processing function template, the preset function name is replaced with the processing function name in the read protocol conversion configuration file. The preset inputs are set sequentially as the service request, the protocol format configuration file of the communication protocol used by the source service of the service request, the protocol format configuration file of the communication protocol used by the target service of the service request, and the protocol conversion configuration file of the two communication protocols. The preset output is set as the service call request using the communication protocol used by the target service, and the function name is recorded in the generated function declaration file. The function parses the communication protocol attribute fields and data fields carried in the service call request from the service request. According to the mapping rules of the communication protocol used by the source service and the communication protocol used by the target service in the protocol conversion file, the function converts the parsed communication protocol attribute fields and data fields carried in the service call request into the format required by the communication protocol used by the target service as needed. The function then concatenates the converted attribute fields and data fields according to the format requirements of the communication protocol used by the target service and outputs them as a function. A protocol processor is used to convert the communication protocol used in the service call request into the communication protocol used by the target service of the service call request. If a corresponding protocol processing function exists in the protocol processor, the protocol format configuration file of the communication protocol used by the source service of the service call request and the protocol format configuration file of the communication protocol used by the target service of the service call request are input into the protocol processor to convert the communication protocol used in the service call request into the communication protocol used by the target service of the service call request. The request forwarding module is used to send service call requests to the target service.
6. A protocol conversion gateway according to claim 5, characterized in that, The communication module is also used to implement the following steps: using an asynchronous coroutine high-concurrency mode to concurrently process call requests. When the protocol conversion gateway receives a service call request, it enables an asynchronous coroutine to process the service call request, avoiding blocking the main thread while maintaining responsiveness to other service call requests. Specifically, a coroutine pool is used to maintain each coroutine that processes a service call request, a mutex lock class is used to control concurrent access, an event loop is used to schedule and manage all coroutines and asynchronous IO events, and when an IO event occurs, the relevant coroutine is notified to continue execution.
7. A protocol conversion gateway according to claim 5, characterized in that, The request forwarding module is also used to implement the following steps: using a round-robin algorithm to discover business processing microservices and perform round-robin load balancing. First, the name of the business processing microservice is taken as input. Then, a service call request is sent. All microservice instances of the specified business processing microservice are generated in a loop. The next microservice instance is selected through a round-robin algorithm. Each time a microservice instance is generated, an index value is added to ensure that all microservice instances are polled evenly. If the index value is greater than the length of the microservice instance list, it is reset to zero to achieve cyclic polling and avoid forwarding service call requests to a single microservice instance.
8. An electronic device, characterized in that, The system includes a memory, a processor, a communication bus, and a communication interface. The memory stores a computer program, and the processor executes the computer program to perform the steps of the microservice framework gateway processing method according to any one of claims 1-4.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program configured to perform the steps of the microservice framework gateway processing method as described in any one of claims 1-4 when the computer program is run.
Citation Information
Patent Citations
Service calling method and device, storage medium and electronic device
CN113301166A
Data gateway for multi-path protocol conversion
CN118282806A