Method, device and equipment for cross-protocol interaction between services and medium

By listening to request messages from different protocols in the service process and using a custom converter, the messages from different protocols are converted into a unified protocol, which solves the problem of interaction between services of different protocols, and realizes direct connection communication across protocols, improving Concurrent processing capabilities and reduce service adaptation transformation.

CN119011693AActive Publication Date: 2024-11-22CHINA CONSTRUCTION BANK +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410955920.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-17
Publication Date
2024-11-22
Estimated Expiration
2044-07-17

AI Technical Summary

Technical Problem

The prior art is difficult to achieve direct interaction between services with different protocols, and requires a large number of adaptation and transformation of services, resulting in wasted time and resources.

Method used

In a service process, two ports are started to listen to request messages from different protocols, and convert messages from different protocols into unified protocol messages through a custom protocol message converter to realize cross-protocol communication interaction.

Benefits of technology

It supports direct communication interaction between services of different protocols, improves concurrent processing capabilities, avoids service adaptation and transformation, and realizes direct communication across programming languages ​​and cross-communication protocols.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119011693A_ABST
    Figure CN119011693A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, in particular to an inter-service cross-protocol interaction method and device, equipment and a medium, and is used for solving the problem that an existing cross-protocol service communication scheme cannot realize inter-service direct communication interaction. The method comprises the following steps: starting two ports to respectively monitor a first protocol request message and a second protocol request message; when a second protocol request message is received, judging whether a service in the second protocol request message is related to the first service or the second service; if the service in the second protocol request message is related to the first service, converting the second protocol request message into a first protocol message by adopting a preset protocol message converter; and calling the first service to process the first protocol message. Based on the method, direct communication between services of cross-programming languages and cross-communication protocols can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a method, apparatus, device and medium for cross-protocol interaction between services. Background Art

[0002] Communication interaction between application services refers to the process of communication between multiple independently running services in a distributed system or microservice architecture. These services may need to share data and work together to complete more complex business processes. The interaction between services can adopt various protocols, such as HTTP / HTTPS (Hypertext Transfer Protocol), RPC (Remote Procedure Call), MQ (Message queue), event-driven architecture, etc. In general, services should use a unified communication protocol for interaction.

[0003] However, in the actual business field, there may be two services that use different protocols or even different development languages. For example, one service uses the standard HTTP protocol, similar to the current general WEB service, and the other service uses a custom TCP (Transmission Control Protocol) protocol message communication. Due to differences in communication protocols and programming languages, these two services cannot directly communicate with each other.

[0004] Existing inter-service communication solutions generally require both services to use a unified message protocol for interaction. Both services need to first define unified interfaces, objects, etc., and then write and generate corresponding interaction files according to their respective programming language syntax, and use the same protocol as the other party to interact. However, these solutions cannot well support direct interaction between two existing services using different protocols, and require a lot of adaptation and transformation of the original services, resulting in a lot of time and resource waste. Summary of the invention

[0005] The embodiments of the present application provide a method, apparatus, device and medium for cross-protocol interaction between services, which are used to solve the problem that existing cross-protocol service communication solutions cannot achieve direct communication interaction between services.

[0006] In a first aspect, the present application provides a method for cross-protocol interaction between services, the method comprising:

[0007] Start two ports to listen to the first protocol request message and the second protocol request message respectively;

[0008] When receiving the second protocol request message, determining whether the service in the second protocol request message is related to the first service or the second service, wherein the first service uses the first protocol for communication and the second service uses the second protocol for communication;

[0009] If the service in the second protocol request message is related to the first service, converting the second protocol request message into a first protocol message using a preset protocol message converter;

[0010] The first service is called to process the first protocol message.

[0011] In a service process on the server side, two different ports are started to listen to the first protocol request message and the second protocol request message respectively, and the mutual conversion of the two different protocol messages is realized through a custom protocol message converter. It supports direct processing after conversion of requests using different protocols or outbound calls to other servers for processing, thus realizing communication interaction between cross-protocol services.

[0012] In a possible embodiment, starting two ports to respectively listen to a first protocol request message and a second protocol request message includes: creating a first thread for receiving and processing the first protocol request message, and starting a first port to listen to the first thread, wherein the first thread is used to call the first service; creating a second thread for receiving and processing the second protocol request message, and starting a second port to listen to the second thread, wherein the second thread is used to call the second service, and the first thread and the second thread belong to the same process.

[0013] In a possible embodiment, the creation of a second thread for receiving and processing the second protocol request message, and starting a second port to listen to the second thread, includes: creating a connection establishment loop thread, and a selector corresponding to the connection establishment loop thread; creating an event loop processing thread group, binding the event loop processing thread group to the selector; and starting the second port to listen to the connection establishment loop thread.

[0014] The I / O multiplexing mode is adopted to receive and process the second protocol request, thereby improving the concurrent processing capability.

[0015] In a possible embodiment, the format of the second protocol request message is: the first four bytes of the second protocol request message are the message body length, the fifth to sixth bytes are the request type, and the seventh and all subsequent bytes are the request body.

[0016] Customizing the TCP protocol message format solves the problem of packet unpacking and packet sticking that may exist in TCP transmission.

[0017] In a possible embodiment, the use of a preset protocol message converter to convert the second protocol request message into a first protocol message includes: parsing the first four bytes in the second protocol request message to obtain the message body length of the second protocol request message; obtaining the request body of the second protocol request message according to the message body length; performing obfuscation decryption and Bson deserialization on the request body to obtain a Bson object; converting the Bson object into a Json object, and generating the first protocol message based on the Json object.

[0018] In a possible embodiment, after calling the first service to process the first protocol message, it also includes: determining whether the processing result of the first protocol message needs to be fed back to the external server or client that sends the second protocol request message; if the processing result needs to be fed back to the external server or client that sends the second protocol request message, using the preset protocol message converter to convert the processing result into a second protocol message; and sending the second protocol message to the external server or client.

[0019] In a possible embodiment, the use of the preset protocol message converter to convert the processing result into a second protocol message includes: performing Bson compression and encoding on the processing result to obtain a request body corresponding to the processing result and a body length of the request body; assembling the body length, the request type of the processing result and the request body to obtain the second protocol message.

[0020] In a second aspect, the present application provides a device for cross-protocol interaction between services, the device comprising:

[0021] A monitoring module starts two ports to monitor the first protocol request message and the second protocol request message respectively;

[0022] a judgment module, which, when receiving the second protocol request message, judges whether the service in the second protocol request message is related to the first service or the second service, wherein the first service uses the first protocol for communication and the second service uses the second protocol for communication;

[0023] a conversion module, which converts the second protocol request message into a first protocol message by using a preset protocol message converter if the service in the second protocol request message is related to the first service;

[0024] A processing module calls the first service to process the first protocol message.

[0025] In a possible embodiment, the monitoring module is specifically used to: create a first thread for receiving and processing the first protocol request message, and start a first port to monitor the first thread, wherein the first thread is used to call the first service; create a second thread for receiving and processing the second protocol request message, and start a second port to monitor the second thread, wherein the second thread is used to call the second service, and the first thread and the second thread belong to the same process.

[0026] In a possible embodiment, the monitoring module is also used to: create a connection establishment loop thread and a selector corresponding to the connection establishment loop thread; create an event loop processing thread group and bind the event loop processing thread group to the selector; and start the second port to monitor the connection establishment loop thread.

[0027] In a possible embodiment, the format of the second protocol request message is: the first four bytes of the second protocol request message are the message body length, the fifth to sixth bytes are the request type, and the seventh and all subsequent bytes are the request body.

[0028] In a possible embodiment, the conversion module is specifically used to: parse the first four bytes in the second protocol request message to obtain the message body length of the second protocol request message; obtain the request body of the second protocol request message according to the message body length; perform obfuscation decryption and Bson deserialization on the request body to obtain a Bson object; convert the Bson object into a Json object, and generate the first protocol message based on the Json object.

[0029] In a possible embodiment, the device is also used to: determine whether the processing result of the first protocol message needs to be fed back to the external server or client that sends the second protocol request message; if the processing result needs to be fed back to the external server or client that sends the second protocol request message, use the preset protocol message converter to convert the processing result into a second protocol message; and send the second protocol message to the external server or client.

[0030] In a possible embodiment, the device is also used to: perform Bson compression and encoding on the processing result to obtain the request text corresponding to the processing result and the text length of the request text; assemble the text length, the request type of the processing result and the request text to obtain the second protocol message.

[0031] In a third aspect, the present application provides an electronic device, including:

[0032] A memory for storing program instructions;

[0033] The processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods in the first aspect according to the obtained program instructions.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes any one of the methods described in the first aspect.

[0035] In a fifth aspect, the present application provides a computer program product, comprising: a computer program code, when the computer program code is run on a computer, the computer executes any one of the methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 A flowchart of a method for cross-protocol interaction between services provided in an embodiment of the present application;

[0037] Figure 2 A schematic diagram of the structure of a WEB server provided in an embodiment of the present application;

[0038] Figure 3 A schematic diagram of the structure of an RPC request processing server provided in an embodiment of the present application;

[0039] Figure 4 A schematic diagram of a custom TCP message format provided in an embodiment of the present application;

[0040] Figure 5 A schematic diagram of a device for cross-protocol interaction between services provided in an embodiment of the present application;

[0041] Figure 6 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0043] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.

[0044] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description. It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0045] In the technical solution of this application, the acquisition, transmission, storage, and use of data are in compliance with the requirements of relevant national laws and regulations.

[0046] In order to facilitate those skilled in the art to better understand the technical solutions provided by the embodiments of the present application, the following is a brief description of the professional terms involved:

[0047] Socket communication: is a concept of network programming, which provides a method to establish and maintain a connection between two computers in a network. The socket interface allows programmers to create and manage inter-process network communication endpoints, which are called sockets and can be used to transmit data packets.

[0048] I / O multiplexing: is a technology that manages multiple I / O operations simultaneously in a single process or thread. It allows a program to wait for multiple descriptors (or sockets), and when any descriptor is ready to read or write, the system will notify the program without polling each descriptor. This method can more effectively utilize system resources and improve the concurrent performance of the server.

[0049] Java NIO (Non-Blocking I / O): It is a new feature introduced in Java 1.4. It is an extension of the standard Java IO API. In traditional Java IO, read and write operations are blocking, which means that when a thread performs reading or writing, if the data is not ready, the thread will be blocked until the data is ready. This may become a performance bottleneck when processing high-concurrency I / O operations. Java NIO provides concepts such as selectors, channels, and buffers, allowing programs to handle multiple connections at the same time, thereby improving the concurrency of the system. It supports buffer-oriented, non-blocking I / O operations, and can read data from multiple streams at the same time, and write data to multiple streams without creating a separate thread for each stream.

[0050] Before introducing a method for cross-protocol interaction between services provided by an embodiment of the present application, in order to facilitate understanding, the technical background of the embodiment of the present application is first introduced in detail below.

[0051] At present, most business support platforms have multiple servers using different communication protocols. For example, in a business support platform, there are multiple web microservices developed in Java that communicate via HTTP protocol, and some RPC servers and client software developed in C++ that communicate based on TCP protocol. Since the communication protocols and message formats between these services are different, communication interaction between services cannot be achieved.

[0052] Most of the existing cross-language and cross-protocol service communication solutions use message middleware or files for interaction, which requires a lot of modification and adaptation of the original services. It is impossible to achieve direct communication interaction between services, which consumes a lot of time and resources.

[0053] To solve the above problems, an embodiment of the present application provides a method for cross-protocol interaction between services. In a service process, a port is started to listen for and process HTTP protocol requests. Based on Socket communication, a thread for receiving and processing RPC requests is created in the original service. In addition, a port is bound to receive related requests. The service supports processing HTTP requests from browsers and WEB services as well as requests from TCP servers and client software, and is adaptable to a variety of external services and software. Through a custom protocol message converter, it supports conversion between standard HTTP protocol messages and various custom TCP protocol messages, and supports direct processing after conversion of requests using different communication protocols or outbound calls to other types of servers for processing and returning processing results. This method realizes direct communication between services across programming languages ​​and communication protocols.

[0054] The solution provided by the embodiment of the present application can be applied to most scenarios of communication between different services across protocols, and is not limited to the communication interaction between the WEB service using the HTTP protocol and the RPC service using the TCP protocol described above. The above communication scenario is only used to illustrate the embodiment of the present application and is not a limitation. In the specific implementation process, the technical solution provided by the embodiment of the present application can be flexibly applied according to actual needs.

[0055] The method provided by the embodiment of the present application is described in detail below with reference to the accompanying drawings. Figure 1 As shown, it is a flow chart of a method for cross-protocol interaction between services provided by an embodiment of the present application. The method is applied to the server side, and the specific implementation process of the method is as follows:

[0056] Step 101: Start two ports to respectively listen to the first protocol request message and the second protocol request message;

[0057] In the embodiment of the present application, the first protocol may be but is not limited to the HTTP protocol, and the second protocol may be but is not limited to the TCP protocol.

[0058] Specifically, in a service process, a first thread is created to receive and process a first protocol request message, and a first port is started to listen to the first thread, and the first thread is used to call a first service; at the same time, a second thread is created to receive and process a second protocol request message, and a second port is started to listen to the second thread, and the second thread is used to call a second service, wherein the first service uses a first protocol for communication, and the second service uses a second protocol for communication, and the first service and the second service can be internal services of the server to which the method is applied, or they can be services provided by an external server.

[0059] The internal services of the server can include WEB services and RPC services. The construction process of the server is as follows:

[0060] First, build a general WEB server application, use Tomcat as the built-in server, bind the first port to listen and process HTTP requests, and the structure of the built WEB server is as follows: Figure 2 As shown, the first service is provided based on the WEB server.

[0061] Then, a second thread is started in the WEB service, and the second port is bound to listen to and process the TCP request message. At the same time, the I / O multiplexing mode can be adopted, and the Selector, Channel and other functions provided by Java NIO are used to receive and process the TCP request message, which greatly improves the concurrency capability.

[0062] Create an RPC request processing server based on the I / O multiplexing mode. Its structure is as follows Figure 3 As shown, specifically, create a connection establishment loop thread and a selector corresponding to the connection establishment loop thread, which are used to receive and process client or external server connection events (OP_ACCEPT); create an event loop processing thread group, which is responsible for processing specific requests, and bind the event loop processing thread group to the selector Selector. Specifically, whenever a new client establishes a connection, a new Channel will be added, and the Channel will be registered with the selector Selector for listening; whenever the I / O on a Channel is ready, the event loop processing thread will trigger subsequent processing according to the bound Selector, process the request and return the processing result. Start the second port to listen to the connection establishment loop thread.

[0063] Based on I / O multiplexing technology, an asynchronous, non-blocking I / O model is used to build an RPC request processing server. Through event-driven methods, the server can efficiently handle concurrent connections and a large number of requests.

[0064] By building a WEB service in a server and starting another thread in the WEB service to build an RPC service, the server can simultaneously support processing HTTP requests from browsers and WEB services and TCP requests from TCP services and client software, and adapt to a variety of external services and software.

[0065] Step 102: When receiving the second protocol request message, determine whether the service in the second protocol request message is related to the first service or the second service;

[0066] In the embodiment of the present application, when the second protocol request message is a TCP message, it can come from an external client or a TCP server. When the second port monitors the second protocol request message, the second protocol request message is received, and it is determined whether the service in the second protocol request message is related to the first service or the second service.

[0067] In a possible implementation, if the business in the second protocol request message is related to the second service, the internal RPC server is directly called for processing, or the second protocol request message is forwarded to other external RPC servers for processing.

[0068] In a possible implementation manner, if the service in the second protocol request message is related to the first service, the operation of the following step 103 is performed.

[0069] Step 103: If the service in the second protocol request message is related to the first service, convert the second protocol request message into the first protocol message using a preset protocol message converter;

[0070] In an embodiment of the present application, the preset protocol message converter is a custom message converter, which is used to convert messages of different protocols.

[0071] When the preset protocol message converter is used to convert the second protocol request message into the first protocol message, it is necessary to obtain the complete request body of the second protocol request message. When the second protocol request message is a TCP message, due to the single transmission limit of the TCP message, a single request may be sent multiple times. In order to ensure that the complete request is obtained before processing, multiple request messages need to be merged, so the message format is defined, such as Figure 4 The following is a custom TCP message format. The first four bytes are the message body length, the next two bytes, that is, the fifth to sixth bytes are the request type, and the seventh and all subsequent bytes are the request body. Among them, the request type is an internally defined request type, such as 1-RPC request, 2-data subscription request, etc.

[0072] By customizing the same TCP message format standard, the problem of packet unpacking and packet sticking that may exist in TCP transmission can be solved.

[0073] Specifically, the process of converting the second protocol request message into the first protocol message by using the preset protocol message converter is as follows:

[0074] Parse the first four bytes in the second protocol request message to obtain the complete message body length of the second protocol request message. Continue to read data from the Socket stream according to the message body length to obtain the complete request body of the second protocol request message. After confirming that the complete message data has been received, perform obfuscation and decryption on the body message and deserialize it into Bson to convert it into a Bson object. Then, by implementing BsonConvert, convert the Bson object into a Json object, and generate the first protocol message, i.e., HTTP message, based on the Json object.

[0075] Through the custom protocol message converter, it supports the conversion between standard HTTP protocol messages and various custom TCP protocol messages, thereby realizing direct communication interaction between services across programming languages ​​and communication protocols.

[0076] Step 104: Call the first service to process the first protocol message.

[0077] Specifically, after converting the second protocol request message into the first protocol message, the first service is called to process the first protocol message. The first service can be an internal service of the server of the method application, that is, an internally constructed WEB service, or a service provided by an external server.

[0078] Further, after calling the first service to process the first protocol message, determine whether the processing result of the first protocol message needs to be fed back to the external server or client that sent the second protocol request message. For example, if the request of the second protocol request message is to write, it is not necessary to feed back the processing result to the external server or client that sent the second protocol request message; if the request of the second protocol request message is to read, it is necessary to feed back the processing result to the external server or client that sent the second protocol request message. Whether the processing result needs to be fed back can be determined by parsing the request type in the second protocol request message. It is worth noting that the method for determining whether the processing result needs to be fed back is not limited to parsing the request type.

[0079] In a possible implementation, if the processing result needs to be fed back to the external server or client that sends the second protocol request message, a preset protocol message converter is used to convert the processing result into a second protocol message, and the second protocol message is sent to the external server or client.

[0080] Specifically, the process of converting the processing result into the second protocol message by using the preset protocol message converter is as follows:

[0081] The processing result is compressed and encoded using Bson to obtain a request body corresponding to the processing result and a body length of the request body; the body length, the request type of the processing result and the request body are assembled to obtain a second protocol message.

[0082] This application starts a port in a service process to listen for HTTP protocol requests, creates a thread in the original service to receive and process RPC requests based on Socket communication, and binds a port to receive related requests. The service also supports processing HTTP requests from browsers and WEB services as well as requests from TCP servers and client software, and is adaptable to a variety of external services and software. Through a custom protocol message converter, it supports the conversion between standard HTTP protocol messages and various custom TCP protocol messages, and supports converting requests using different communication protocols and then directly processing them or calling other types of servers for processing and returning the processing results, thereby realizing direct communication between services across programming languages ​​and communication protocols.

[0083] Based on the same inventive concept, the present application embodiment provides a device for cross-protocol interaction between services, please refer to Figure 5 , the device comprises:

[0084] A monitoring module 501 starts two ports to monitor the first protocol request message and the second protocol request message respectively;

[0085] The judgment module 502, when receiving the second protocol request message, judges whether the service in the second protocol request message is related to the first service or the second service, wherein the first service uses the first protocol for communication and the second service uses the second protocol for communication;

[0086] The conversion module 503 converts the second protocol request message into a first protocol message by using a preset protocol message converter if the service in the second protocol request message is related to the first service;

[0087] The processing module 504 calls the first service to process the first protocol message.

[0088] In a possible embodiment, the monitoring module 501 is specifically used to: create a first thread for receiving and processing the first protocol request message, and start a first port to monitor the first thread, wherein the first thread is used to call the first service; create a second thread for receiving and processing the second protocol request message, and start a second port to monitor the second thread, wherein the second thread is used to call the second service, and the first thread and the second thread belong to the same process.

[0089] In a possible embodiment, the monitoring module 501 is also used to: create a connection establishment loop thread and a selector corresponding to the connection establishment loop thread; create an event loop processing thread group and bind the event loop processing thread group to the selector; and start the second port to monitor the connection establishment loop thread.

[0090] In a possible embodiment, the format of the second protocol request message is: the first four bytes of the second protocol request message are the message body length, the fifth to sixth bytes are the request type, and the seventh and all subsequent bytes are the request body.

[0091] In a possible embodiment, the conversion module 503 is specifically used to: parse the first four bytes in the second protocol request message to obtain the message body length of the second protocol request message; obtain the request body of the second protocol request message according to the message body length; perform obfuscation decryption and Bson deserialization on the request body to obtain a Bson object; convert the Bson object into a Json object, and generate the first protocol message based on the Json object.

[0092] In a possible embodiment, the device is also used to: determine whether the processing result of the first protocol message needs to be fed back to the external server or client that sends the second protocol request message; if the processing result needs to be fed back to the external server or client that sends the second protocol request message, use the preset protocol message converter to convert the processing result into a second protocol message; and send the second protocol message to the external server or client.

[0093] In a possible embodiment, the device is also used to: perform Bson compression and encoding on the processing result to obtain the request text corresponding to the processing result and the text length of the request text; assemble the text length, the request type of the processing result and the request text to obtain the second protocol message.

[0094] Based on the same inventive concept, an electronic device is also provided in an embodiment of the present application, and the electronic device can realize the function of the aforementioned device for cross-protocol interaction between services, referring to Figure 6 , the electronic device comprises:

[0095] At least one processor 601, and a memory 602 connected to the at least one processor 601. The specific connection medium between the processor 601 and the memory 602 is not limited in the embodiment of the present application. Figure 6 In the example, the processor 601 and the memory 602 are connected via a bus 600. The bus 600 is Figure 6 The connection between other components is shown by bold lines, and is not intended to be limiting. The bus 600 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 601 can also be called a controller, and there is no limitation on the name.

[0096] In the embodiment of the present application, the memory 602 stores instructions that can be executed by at least one processor 601. The at least one processor 601 can execute the method for cross-protocol interaction between services discussed above by executing the instructions stored in the memory 602. The processor 601 can implement Figure 5 The functions of each module in the device shown.

[0097] Among them, the processor 601 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 602 and calling the data stored in the memory 602, the various functions of the device and processing data, the device can be monitored as a whole.

[0098] In one possible design, the processor 601 may include one or more processing units, and the processor 601 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 601. In some embodiments, the processor 601 and the memory 602 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.

[0099] Processor 601 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method for cross-protocol interaction between services disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or a combination of hardware and software modules in the processor for execution.

[0100] The memory 602 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 602 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 602 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 602 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0101] By designing and programming the processor 601, the code corresponding to the method for cross-protocol interaction between services introduced in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 1The steps of the method for cross-protocol interaction between services in the illustrated embodiment. How to design and program the processor 601 is a technique known to those skilled in the art and will not be described in detail here.

[0102] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, and a computer program product includes: a computer program code, when the computer program code is executed on a computer, the computer executes any of the methods for cross-protocol interaction between services discussed above. Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to the method for cross-protocol interaction between services, the implementation of the above-mentioned computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.

[0103] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the methods for cross-protocol interaction between services discussed above. Since the principle of solving the problem by the above computer program product is similar to the method for cross-protocol interaction between services, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.

[0104] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0105] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, 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 flowchart and / or block diagram. 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.

[0106] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate 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 A function specified in one or more boxes.

[0107] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of user-operated steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0108] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for cross-protocol interaction between services, characterized in that: The method is applied to the server, and the method includes: Start two ports to listen to the first protocol request message and the second protocol request message respectively; When receiving the second protocol request message, determining whether the service in the second protocol request message is related to the first service or the second service, wherein the first service uses the first protocol for communication and the second service uses the second protocol for communication; If the service in the second protocol request message is related to the first service, converting the second protocol request message into a first protocol message using a preset protocol message converter; The first service is called to process the first protocol message.

2. The method according to claim 1, characterized in that The step of starting two ports to respectively listen to the first protocol request message and the second protocol request message comprises: Creating a first thread for receiving and processing the first protocol request message, and starting a first port to monitor the first thread, wherein the first thread is used to call the first service; A second thread for receiving and processing the second protocol request message is created, and a second port is started to monitor the second thread, wherein the second thread is used to call the second service, and the first thread and the second thread belong to the same process.

3. The method according to claim 2, characterized in that The step of creating a second thread for receiving and processing the second protocol request message, and starting a second port to monitor the second thread, includes: Creating a connection establishment loop thread and a selector corresponding to the connection establishment loop thread; Creating an event loop processing thread group, and binding the event loop processing thread group to the selector; The second port is started to monitor the connection establishment loop thread.

4. The method according to claim 1, characterized in that The format of the second protocol request message is: The first four bytes of the second protocol request message are the message body length, the fifth to sixth bytes are the request type, and the seventh and all subsequent bytes are the request body.

5. The method according to claim 1, characterized in that The converting the second protocol request message into the first protocol message by using a preset protocol message converter includes: Parsing the first four bytes in the second protocol request message to obtain the message body length of the second protocol request message; According to the message body length, obtaining the request body of the second protocol request message; Obfuscate and decrypt the request body and deserialize it into Bson to obtain a Bson object; The Bson object is converted into a Json object, and the first protocol message is generated based on the Json object.

6. The method according to claim 1, characterized in that After calling the first service to process the first protocol message, the method further includes: Determine whether the processing result of the first protocol message needs to be fed back to the external server or client that sends the second protocol request message; If the processing result needs to be fed back to the external server or client that sends the second protocol request message, the preset protocol message converter is used to convert the processing result into a second protocol message; The second protocol message is sent to the external server or client.

7. The method according to claim 6, characterized in that The using the preset protocol message converter to convert the processing result into a second protocol message includes: Perform Bson compression and encoding on the processing result to obtain the request body corresponding to the processing result and the body length of the request body; The text length, the request type of the processing result and the request text are assembled to obtain the second protocol message.

8. A device for cross-protocol interaction between services, characterized in that: The device comprises: A monitoring module starts two ports to monitor the first protocol request message and the second protocol request message respectively; a judgment module, which, when receiving the second protocol request message, judges whether the service in the second protocol request message is related to the first service or the second service, wherein the first service uses the first protocol for communication and the second service uses the second protocol for communication; a conversion module, which converts the second protocol request message into a first protocol message by using a preset protocol message converter if the service in the second protocol request message is related to the first service; A processing module calls the first service to process the first protocol message.

9. The device according to claim 8, characterized in that The monitoring module is specifically used for: Creating a first thread for receiving and processing the first protocol request message, and starting a first port to monitor the first thread, wherein the first thread is used to call the first service; A second thread for receiving and processing the second protocol request message is created, and a second port is started to monitor the second thread, wherein the second thread is used to call the second service, and the first thread and the second thread belong to the same process.

10. The device according to claim 8, characterized in that The monitoring module is also used for: Creating a connection establishment loop thread and a selector corresponding to the connection establishment loop thread; Creating an event loop processing thread group, and binding the event loop processing thread group to the selector; The second port is started to monitor the connection establishment loop thread.

11. The device according to claim 8, characterized in that The conversion module is specifically used for: Parsing the first four bytes in the second protocol request message to obtain the message body length of the second protocol request message; According to the message body length, obtaining the request body of the second protocol request message; Obfuscate and decrypt the request body and deserialize it into Bson to obtain a Bson object; The Bson object is converted into a Json object, and the first protocol message is generated based on the Json object.

12. The device according to claim 8, characterized in that The device is also used for: Determine whether the processing result of the first protocol message needs to be fed back to the external server or client that sends the second protocol request message; If the processing result needs to be fed back to the external server or client that sends the second protocol request message, the preset protocol message converter is used to convert the processing result into a second protocol message; The second protocol message is sent to the external server or client.

13. An electronic device, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of claims 1-7 according to the obtained program instructions.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method according to any one of claims 1 to 7.

15. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • On-premises agent for mobile cloud service

    CN105900397A

  • Method and system for dynamically expanding non-HTTP (Hyper Text Transport Protocol) based on micro-service gateway

    CN116192933A

  • Cross-service calling method and device, electronic equipment and storage medium

    CN117201571A

  • Method and device for realizing unified configuration of service system based on JSONPath

    CN117742830A

  • Data conversion handler for a run-time execution environment

    US10915507B1