Method and apparatus for converting from Socket protocol to Dubbo protocol
By parsing and converting Socket protocol messages in the Socket Server of traditional systems, combining pre-configured mapping relationships and Spring containers, automatic conversion from the Socket protocol to the Dubbo protocol is realized, solving the problem of high development complexity when traditional systems call new line systems, and achieving efficient and low-cost system calls and communication.
Patent Information
- Application Number
- CN202210012734.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-06
- Publication Date
- 2025-06-03
- Estimated Expiration
- 2042-01-06
AI Technical Summary
When the traditional system calls new line systems, the manual hard-coded new interface is complicated, the versatility is not strong, the development cycle is long, the code repeatability is high, and the coding personnel is required, resulting in high development costs and low efficiency.
After receiving the traditional Socket protocol message in Socket Server, it parses the message identification and call parameters, and determines the bean name, class name and method name of the Dubbo interface to be called based on the mapping relationship between the pre-configured Socket protocol message identification and the Dubbo interface, finds the bean instance from the Spring container, obtains the method signature, deserializes the call parameters, triggers the Dubbo RPC call, and serializes the result to generate the Socket protocol message to return.
It realizes the conversion of the Socket protocol of the traditional business system into the Dubbo protocol used in the new line system through pre-configuration files, which simplifies the development process, reduces development costs, improves development efficiency, and breaks the communication barrier between new and old business systems.
Smart Images

Figure CN114327959B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a conversion from a Socket protocol to a Dubbo protocol and a device thereof. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section.
[0003] At present, some financial enterprises that started building IT systems earlier often have business systems that have been running for decades. Due to technological evolution, these traditional systems often use some technologies that seem outdated now, and their internal communication methods are also different from the commonly used communication methods. In order to ensure the connectivity between businesses, data and communication between new business systems and traditional business systems need to be connected to ensure the interconnection between the two systems.
[0004] In traditional systems, the Socket protocol is often used directly as the communication protocol between systems; in new line systems, Dubbo, REST and other RPC protocols are used for communication. In this way, the communication barriers between the old and new business systems make it impossible for the two systems to be interconnected. When the traditional system calls the new line system, the existing solution is generally manual hard coding, which has the problems of cumbersome new interfaces, low versatility, long development cycle, high code duplication, and high requirements for coders, resulting in high development costs and low efficiency. Summary of the invention
[0005] The embodiment of the present invention provides a method for converting from the Socket protocol to the Dubbo protocol, which is used to convert the Socket protocol used by traditional business systems to communicate with each other into the Dubbo protocol used by the new line system by means of a pre-configured file. The method includes:
[0006] When receiving the current traditional Socket protocol message sent by the calling end through the created Socket Server, the current traditional Socket protocol message is parsed to obtain the current Socket protocol message identifier and the current calling parameter;
[0007] According to the current Socket protocol message identifier, the mapping relationship between the pre-configured Socket protocol message identifier and the Dubbo interface, determine the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called;
[0008] Find the corresponding bean instance in the Spring container according to the bean name of the Dubbo interface;
[0009] Obtain the method signature of the method to be invoked according to the class name of the Dubbo interface to be invoked and the method name of the method to be invoked in the Dubbo interface to be invoked;
[0010] Obtain the parameter types of the method to be invoked from the method signature, and deserialize the current invocation parameters into the invocation parameter object used by the method to be invoked according to the parameter types of the invocation;
[0011] Trigger a Dubbo RPC call with the bean instance, the method name of the method to be invoked, and the invocation parameter object used by the method to be invoked as inputs, and obtain the Dubbo call result;
[0012] Serialize the Dubbo call result and generate a Socket protocol message to return to the calling end.
[0013] An embodiment of the present invention further provides a conversion device from the Socket protocol to the Dubbo protocol, which is used to convert the Socket protocol used for mutual communication of traditional business systems into the Dubbo protocol used by the new line system by means of a pre-configured file. The device includes:
[0014] A parsing unit, which is used to parse the current traditional Socket protocol message when receiving the current traditional Socket protocol message sent by the calling end through the created Socket Server, and obtain the current Socket protocol message identifier and the current invocation parameters;
[0015] A determination unit, which is used to determine the bean name of the Dubbo interface to be invoked, the class name of the Dubbo interface to be invoked, and the method name of the method to be invoked in the Dubbo interface to be invoked according to the current Socket protocol message identifier and the mapping relationship between the pre-configured Socket protocol message identifier and the Dubbo interface;
[0016] A search unit, which is used to find the corresponding bean instance in the Spring container according to the bean name of the Dubbo interface;
[0017] An acquisition unit, which is used to obtain the method signature of the method to be invoked according to the class name of the Dubbo interface to be invoked and the method name of the method to be invoked in the Dubbo interface to be invoked;
[0018] A deserialization unit, configured to obtain the call parameter types of the method to be invoked from the method signature, and deserialize the current call parameters into call parameter objects used by the method to be invoked according to the call parameter types;
[0019] A call unit, configured to trigger a Dubbo RPC call with the bean instance, the method name of the method to be invoked, and the call parameter objects used by the method to be invoked as inputs, and obtain a Dubbo call result;
[0020] A feedback unit, configured to serialize the Dubbo call result and generate a Socket protocol message to be returned to the calling end.
[0021] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the above method for converting from the Socket protocol to the Dubbo protocol is implemented.
[0022] An embodiment of the present invention further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the above method for converting from the Socket protocol to the Dubbo protocol is implemented.
[0023] An embodiment of the present invention further provides a computer program product. The computer program product includes a computer program. When the computer program is executed by a processor, the above method for converting from the Socket protocol to the Dubbo protocol is implemented.
[0024] In the embodiment of the present invention, compared with the prior art in which when a traditional system calls a new-line system, manual hard coding has problems such as cumbersome new interfaces, poor generality, long development cycles, high code duplication, and high requirements for coders, resulting in high development costs and low efficiency. By: when the currently traditional Socket protocol message sent by the calling end is received through the created Socket Server, parsing the currently traditional Socket protocol message to obtain the current Socket protocol message identifier and the current call parameters; according to the current Socket protocol message identifier and the pre-configured mapping relationship between the Socket protocol message identifier and the Dubbo interface, determining the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called; according to the bean name of the Dubbo interface, finding the corresponding bean instance from the Spring container; according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtaining the method signature of the method to be called; obtaining the call parameter types of the method to be called from the method signature, and deserializing the current call parameters into the call parameter objects used by the method to be called according to the call parameter types; using the bean instance, the method name of the method to be called, and the call parameter objects used by the method to be called as inputs to trigger a Dubbo RPC call to obtain a Dubbo call result; serializing the Dubbo call result and generating a Socket protocol message to return to the calling end, it is possible to convert the Socket protocol used for communication between traditional business systems into the Dubbo protocol used by the new-line system by means of a pre-configured file, so as to achieve an efficient and low-cost call of the new-line system by the traditional system, and further break the communication barrier between the old and new business systems efficiently and at low cost. Brief Description of the Drawings
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. In the drawings:
[0026] Figure 1 It is a schematic flow chart of the conversion method from the Socket protocol to the Dubbo protocol in the embodiment of the present invention;
[0027] Figure 2 It is a schematic flow chart of the conversion method from the Socket protocol to the Dubbo protocol in another embodiment of the present invention;
[0028] Figure 3 It is a schematic flowchart of the conversion method from the Socket protocol to the Dubbo protocol in another embodiment of the present invention;
[0029] Figure 4 It is a schematic structural diagram of the conversion device from the Socket protocol to the Dubbo protocol in an embodiment of the present invention;
[0030] Figure 5 It is a schematic structural diagram of the conversion device from the Socket protocol to the Dubbo protocol in another embodiment of the present invention. Detailed implementation manners
[0031] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer and more understandable, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Herein, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but not to limit the present invention.
[0032] Dubbo: Dubbo is an open-source, high-performance, lightweight Java RPC framework. It provides three core capabilities: remote method invocation based on interfaces, intelligent fault tolerance and load balancing, and automatic service registration and discovery.
[0033] Service provider (Provider): In a microservices architecture, it is responsible for providing services and registering its own services with the registry.
[0034] Service consumer (Consumer): In a microservices architecture, it is responsible for subscribing to services from the registry and invoking service providers.
[0035] Registry: It is used for the registration and discovery of service providers and service consumers.
[0036] Socket protocol message format: The message header of the Socket protocol is 2 or 4 bytes, indicating the length of the message body. The specific length of the message body of the Socket protocol is defined by the message header.
[0037] In the prior art, in a hard-coded manner, taking the message ID as the basic unit, Socket message parsers and corresponding Dubbo RPC call classes are written one by one to implement the call of the existing traditional system to the new business system. The inventor considered the following technical problems existing in the call of the existing traditional system to the new business system:
[0038] 1. Adding new interfaces is cumbersome, with poor generality and a long development cycle. For each newly added interface, a complete set of business processing logics need to be written, the process is cumbersome, and the development cycle is relatively long.
[0039] 2. High code duplication. All the code has a high degree of duplication, which does not conform to the basic principle of "reuse rather than replication" in software engineering.
[0040] 3. High requirements for coders. Coders need to have higher coding capabilities.
[0041] Since the inventor considered the above technical problems, in order to achieve the invocation of the new business system by the traditional system, a conversion scheme from the Socket protocol to the Dubbo protocol was proposed. By adjusting the configuration file, the Socket protocol used for communication between traditional business systems can be automatically converted into the Dubbo protocol used by the new line system, thus achieving the invocation of the new line system by the traditional system and breaking the communication barrier between the old and new business systems. That is, an automatic conversion scheme from the Socket protocol to the Dubbo protocol was proposed. In this scheme, developers can have an automatic conversion logic from the Socket protocol to the Dubbo protocol through simple configuration, which has stronger versatility, greatly shortens the development cycle, and can also avoid duplicate coding. This scheme mainly includes the following steps:
[0042] 1. Create a Socket Server (socket server) to receive traditional Socket protocol messages.
[0043] 2. After receiving the Socket protocol message, parse the received Socket protocol message to extract the TRANS_ID (message ID) and call parameters (strings).
[0044] 3. According to the mapping relationship between the TRANS_ID and the Dubbo interface (based on configuration, which needs to be maintained in advance), find the class name and method name of the corresponding Dubbo interface.
[0045] 4. According to the class name of the Dubbo interface, find the corresponding class instance from the Spring container;
[0046] 5. Based on the Java reflection mechanism, obtain the corresponding method signature according to the class name and method name of the Dubbo interface.
[0047] 6. Deserialize the call parameters (strings) received in step 2 into the call parameter types in the method signature.
[0048] 7. Trigger a Dubbo RPC call.
[0049] 8. Serialize the data returned by Dubbo.
[0050] 9. Combine the serialized data with other necessary information to generate a return message and return it to the calling end.
[0051] The following is a detailed introduction to the conversion solution from the Socket protocol to the Dubbo protocol.
[0052] Figure 1 It is a schematic flowchart of the conversion method from the Socket protocol to the Dubbo protocol in an embodiment of the present invention. As Figure 1 shown, the method includes the following steps:
[0053] Step 102: When the currently traditional Socket protocol message sent by the calling end is received through the created Socket Server, parse the currently traditional Socket protocol message to obtain the current Socket protocol message identifier and the current call parameters;
[0054] Step 103: According to the current Socket protocol message identifier and the pre-configured mapping relationship between the Socket protocol message identifier and the Dubbo interface, determine the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called;
[0055] Step 104: According to the bean name of the Dubbo interface, find the corresponding bean instance from the Spring container;
[0056] Step 105: According to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtain the method signature of the method to be called;
[0057] Step 106: Obtain the call parameter types of the method to be called from the method signature, and deserialize the current call parameters into call parameter objects used by the method to be called according to the call parameter types;
[0058] Step 107: Trigger a Dubbo RPC call with the bean instance, the method name of the method to be called, and the call parameter objects used by the method to be called as inputs, and obtain a Dubbo call result;
[0059] Step 108: Serialize the Dubbo call result and generate a Socket protocol message to return to the calling end.
[0060] The conversion method from the Socket protocol to the Dubbo protocol provided by the embodiments of the present invention works as follows: When the currently traditional Socket protocol message sent by the calling end is received through the created Socket Server, the currently traditional Socket protocol message is parsed to obtain the current Socket protocol message identifier and the current call parameters; according to the current Socket protocol message identifier and the pre-configured mapping relationship between the Socket protocol message identifier and the Dubbo interface, the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called are determined; according to the bean name of the Dubbo interface, the corresponding bean instance is found from the Spring container; according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, the method signature of the method to be called is obtained; the call parameter type of the method to be called is obtained from the method signature, and the current call parameters are deserialized into the call parameter object used by the method to be called according to the call parameter type; using the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, a Dubbo RPC call is triggered to obtain the Dubbo call result; the Dubbo call result is serialized and processed to generate a Socket protocol message and returned to the calling end, which can realize the conversion of the Socket protocol used for communication between traditional business systems into the Dubbo protocol used by the new line system by means of a pre-configured file, so as to realize the efficient and low-cost call of the traditional system to the new line system, and further break the communication barrier between the old and new business systems efficiently and at low cost. The following combines Figures 2 to 3 to introduce this method in detail.
[0061] First, the pre-preparation stage is introduced, that is, the stage of establishing various mapping relationships in advance.
[0062] 1. In the configuration file, register the Dubbo interfaces to be called as Dubbo consumers in the Dubbo configuration center.
[0063] 2. Register the reference to the Dubbo consumer as a bean under the Spring framework, and the bean name needs to be specified at the same time.
[0064] 3. Configure the TRANS_ID whitelist that supports protocol conversion.
[0065] 4. (Based on the Spring XML configuration file, in the form of Map key-value pairs) Establish the mapping relationship between TRANS_ID and the corresponding Dubbo consumer bean name.
[0066] 5. Establish the mapping relationship between TRANS_ID and the interface class name of the called interface in the Dubbo interface in the form of a Map key-value pair based on the Spring XML configuration file.
[0067] 6. Establish the mapping relationship between TRANS_ID and the method name of the called method in the Dubbo interface in the form of a Map key-value pair based on the Spring XML configuration file.
[0068] In summary, in the above preparation stage, the mapping relationship between the Socket protocol message identifier and the Dubbo interface is pre-configured. This relationship includes the relationship between the Socket protocol message identifier and the bean name, class name of the Dubbo interface, and the method name of the method to be called in the Dubbo interface.
[0069] Second, then introduce the formal stage, namely steps 101 to 108.
[0070] In one embodiment, as Figure 2 shown, before the above step 102, step 101 that can also be included: Create a Socket Server.
[0071] Specifically in implementation, in the above step 101, create a Socket Server for receiving traditional Socket protocol messages.
[0072] In the above step 102, after receiving the Socket protocol message, parse the received Socket protocol message to extract TRANS_ID (message ID) and call parameters (string), that is, the current Socket protocol message identifier and the current call parameters.
[0073] In the above step 103, match the current Socket protocol message identifier to the mapping relationship between the Socket protocol message identifier and the Dubbo interface pre-configured in the above "one" preparation stage to obtain the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called, that is, according to the mapping relationship between TRANS_ID (Socket protocol message identifier) and the Dubbo interface (based on configuration, which needs to be maintained in advance), find the bean name in the Spring container used by the corresponding Dubbo interface, the class name of the corresponding Dubbo interface class, and the method name of the method to be called in the called interface (Dubbo interface to be called).
[0074] In the above step 104, according to the bean (a reusable class) name of the Dubbo interface, the corresponding bean instance is found from the Spring container. The Spring container is the core of Spring. Spring beans are stored in the Spring container, and the Spring container is also a bean factory.
[0075] In the above step 105, in one embodiment, according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtaining the method signature of the method to be called may include: based on the reflection mechanism of Java, according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtaining the method signature of the method to be called.
[0076] Specifically in implementation, based on the reflection mechanism of Java, according to the class name and method name of the Dubbo interface, the corresponding method signature is obtained.
[0077] In the above step 106, the call parameter type of the method to be called is obtained from the method signature, and based on this call parameter type, the call parameter (string, i.e., the current call parameter) received in step 102 is deserialized into the call parameter object used by the method to be called. Deserialization: converting a string into an object of a specific Java data type. For this example, it is to convert the call parameter (string) into the call parameter object used by the method to be called. Generally, the call parameter (string) is stored in JSON format, and the deserialization process can be as follows:
[0078] T object = JSON.parseJSONObject(call parameter string, call parameter type);
[0079] To facilitate understanding of the implementation process of deserialization, an example is shown in Table 1 below:
[0080]
[0081] Table 1
[0082] In the above step 107, using the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, triggering a Dubbo RPC call to obtain a Dubbo call result may include: using the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, based on the reflection mechanism of Java, triggering a Dubbo RPC call to obtain a Dubbo call result.
[0083] During specific implementation, taking the bean instance, the method name of the method to be called, and the call parameters of the method to be called as inputs, based on the reflection mechanism of Java, trigger a Dubbo RPC call to obtain the Dubbo call result.
[0084] In the above step 108, after the Dubbo producer returns data, serialize the Dubbo-returned data (obtain the Dubbo call result), that is, convert the Java object into a string format. If the Dubbo RPC call fails, serialize the error message. Combine the serialized data, that is, the normal return data (the serialized normal Dubbo call result) or the error message (the serialized Dubbo call error message), with other necessary information to generate a return message and return it to the calling end.
[0085] As can be seen from the above, in one embodiment, the method for converting from the Socket protocol to the Dubbo protocol may further include: if the Dubbo RPC call fails, after serializing the Dubbo call error message, obtain the serialized Dubbo call error message; generate a Dubbo call error result message from the serialized Dubbo call error message and return it to the calling end.
[0086] In summary, the method for converting from the Socket protocol to the Dubbo protocol provided by the embodiments of the present invention is an automatic conversion method from the Socket protocol to the Dubbo protocol. This method can automatically convert the Socket protocol to the Dubbo protocol by adjusting the configuration file, that is, automatically convert the Socket protocol used for communication between traditional business systems to the Dubbo protocol used by the new line system, so as to realize the call of the new line system by the traditional system, break the communication barrier between the old and new business systems, and solve the problems of cumbersome new interface addition, poor generality, long development cycle, high code duplication, and high requirements for coders when the traditional system calls the new line system. Furthermore, it reduces the development cost and improves the development efficiency.
[0087] An apparatus for converting from the Socket protocol to the Dubbo protocol is also provided in the embodiments of the present invention, as described in the following embodiments. Since the principle of the apparatus for solving problems is similar to the method for converting from the Socket protocol to the Dubbo protocol, the implementation of the apparatus can refer to the implementation of the method for converting from the Socket protocol to the Dubbo protocol, and the repeated parts will not be elaborated.
[0088] Figure 4 It is a schematic structural diagram of the apparatus for converting from the Socket protocol to the Dubbo protocol in the embodiments of the present invention, as Figure 4 shown, the apparatus includes:
[0089] The parsing unit 02 is configured to parse the current traditional Socket protocol message received from the calling end through the created Socket Server, so as to obtain the current Socket protocol message identifier and the current calling parameter;
[0090] The determining unit 03 is configured to determine the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called according to the mapping relationship between the current Socket protocol message identifier and the Dubbo interface pre-configured;
[0091] The searching unit 04 is configured to search for the corresponding bean instance from the Spring container according to the bean name of the Dubbo interface;
[0092] The obtaining unit 05 is configured to obtain the method signature of the method to be called according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called;
[0093] The deserialization unit 06 is configured to obtain the call parameter type of the method to be called from the method signature, and deserialize the current call parameter into a call parameter object used by the method to be called according to the call parameter type;
[0094] The calling unit 07 is configured to trigger a Dubbo RPC call with the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, so as to obtain a Dubbo call result;
[0095] The feedback unit 08 is configured to serialize the Dubbo call result and then generate a Socket protocol message to return to the calling end.
[0096] Specifically, the above feedback unit includes a call result serialization unit, which serializes the Dubbo call result into a serialized Dubbo call result, and then generates a Socket protocol message to return to the calling end.
[0097] In one embodiment, the above conversion device from the Socket protocol to the Dubbo protocol may further include: an error message serialization unit, which is configured to serialize the Dubbo call error message if the Dubbo RPC call fails, so as to obtain a serialized Dubbo call error message;
[0098] The feedback unit can also be used to generate a Dubbo call error result message from the serialized Dubbo call error information and return it to the calling end.
[0099] In one embodiment, as Figure 5 shown, the above conversion device from the Socket protocol to the Dubbo protocol may further include: a creation unit 01, configured to create a Socket Server.
[0100] In one embodiment, the obtaining unit is specifically configured to: based on the reflection mechanism of Java, obtain the method signature of the method to be called according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called.
[0101] In one embodiment, the calling unit is specifically configured to: take the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, and trigger a Dubbo RPC call based on the reflection mechanism of Java to obtain a Dubbo call result.
[0102] In specific implementation, each module involved in the embodiment of the present invention will be introduced below.
[0103] 1. The mapping relationship maintenance module is responsible for maintaining mapping relationships such as the TRANS_ID whitelist, the mapping relationship between TRANS_ID and the corresponding Dubbo consumer bean name, the mapping relationship between TRANS_ID and the interface class name of the called interface in the Dubbo interface, and the mapping relationship between TRANS_ID and the method name of the called method in the Dubbo interface.
[0104] 2. The Socket protocol message receiving module, that is, the above creation unit, is responsible for creating one or more Socket Servers for receiving Socket protocol messages sent by the legacy system.
[0105] 3. The Socket protocol message parsing module, that is, the above parsing unit. After the Socket protocol message receiving module receives a Socket protocol message, this module is responsible for parsing the received Socket protocol message and extracting the TRANS_ID (message ID) and call parameters (strings).
[0106] 4. The Dubbo remote call triggering module includes the above determination unit, search unit, obtaining unit, deserialization unit, and calling unit. Specifically:
[0107] 1) Based on the mapping relationship between TRANS_ID and the Dubbo interface (which needs to be maintained in advance based on the configuration), find the bean name in the Spring container used by the corresponding Dubbo interface, the class name of the corresponding Dubbo interface class, and the method name of the method to be called in the called interface. This step can be implemented by the above-mentioned determination unit.
[0108] 2) Based on the bean name of the Dubbo interface, find the corresponding bean instance from the Spring container. This step can be implemented by the above-mentioned search unit.
[0109] 3) Based on the Java reflection mechanism, according to the class name and method name of the Dubbo interface, obtain the method signature of the method to be called. This step can be implemented by the above-mentioned acquisition unit.
[0110] 4) Use the call parameter types obtained from the method signature of the method to be called to deserialize the received call parameters (strings) into call parameter objects used by the method to be called. This step can be implemented by the above-mentioned deserialization unit.
[0111] 5) Using the bean instance, the method name of the method to be called, and the call parameters of the method to be called as inputs, trigger a Dubbo RPC call based on the Java reflection mechanism. This step can be implemented by the above-mentioned call unit.
[0112] 5. For the Socket protocol return message serialization module, refer to the above-mentioned feedback unit. Serialize the serialized data (normal return data or error information), and generate a return message in cooperation with other necessary information, and return it to the calling end. Specifically, this module implements:
[0113] 1) After the Dubbo producer returns data, serialize the Dubbo return data.
[0114] 2) If the Dubbo RPC call fails, serialize the error information.
[0115] For the convenience of understanding how the present invention is implemented, the working processes of each module involved in the embodiments of the present invention will be introduced below.
[0116] 1. Maintain relevant mapping relationships in the mapping relationship maintenance module.
[0117] 2. The Socket protocol message receiving module receives the Socket protocol message sent by the traditional system and passes it to the Socket protocol message parsing module.
[0118] 3. The Socket protocol message parsing module is responsible for parsing the received Socket protocol messages. After extracting the TRANS_ID (message ID) and call parameters (strings), it triggers the Dubbo remote call trigger module.
[0119] 4. The Dubbo remote call trigger module deserializes the call parameters (strings) according to the TRANS_ID extracted by the Socket protocol message parsing module and the mapping relationship maintained by the mapping relationship maintenance module for this TRANS_ID, and triggers a Dubbo remote call. After the Dubbo producer returns data, this module is responsible for serializing the Dubbo return data and transmitting the serialized data to the Socket protocol return message serialization module.
[0120] 5. The Socket protocol return message serialization module generates a return message by combining the serialized data (normal return data or error information) with other necessary information and returns it to the calling end.
[0121] In the technical solution of this application, the acquisition, storage, use, processing, etc. of data all comply with the relevant provisions of national laws and regulations.
[0122] The embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the above conversion method from the Socket protocol to the Dubbo protocol.
[0123] The embodiment of the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the above conversion method from the Socket protocol to the Dubbo protocol.
[0124] The embodiment of the present invention also provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the above conversion method from the Socket protocol to the Dubbo protocol.
[0125] In the embodiment of the present invention, compared with the prior art in which when a traditional system calls a new-line system, manual hard coding has problems such as cumbersome new interfaces, poor generality, long development cycles, high code duplication, and high requirements for coders, resulting in high development costs and low efficiency. The conversion solution from the Socket protocol to the Dubbo protocol is achieved by: when the currently traditional Socket protocol message sent by the calling end is received through the created Socket Server, parsing the currently traditional Socket protocol message to obtain the current Socket protocol message identifier and the current call parameters; according to the current Socket protocol message identifier and the pre-configured mapping relationship between the Socket protocol message identifier and the Dubbo interface, determining the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called; according to the bean name of the Dubbo interface, finding the corresponding bean instance from the Spring container; according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtaining the method signature of the method to be called; obtaining the call parameter types of the method to be called from the method signature, and deserializing the current call parameters into call parameter objects used by the method to be called according to the call parameter types; using the bean instance, the method name of the method to be called, and the call parameter objects used by the method to be called as inputs to trigger a Dubbo RPC call to obtain a Dubbo call result; serializing the Dubbo call result and generating a Socket protocol message to be returned to the calling end, which can implement the conversion of the Socket protocol used for communication between traditional business systems into the Dubbo protocol used by the new-line system through a pre-configured file, thereby realizing the efficient and low-cost call of the traditional system to the new-line system, and further breaking the communication barrier between the old and new business systems efficiently and at low cost.
[0126] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0127] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or in multiple blocks.
[0128] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or in multiple blocks.
[0129] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or in multiple blocks.
[0130] The specific embodiments described above further elaborate on the objectives, technical solutions, and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for converting from Socket protocol to Dubbo protocol, characterized in that, it includes: When the current traditional Socket protocol message sent by the calling end is received through the created Socket Server, parse the current traditional Socket protocol message to obtain the current Socket protocol message identifier and the current call parameters; According to the current Socket protocol message identifier and the pre-configured mapping relationship between the Socket protocol message identifier and the Dubbo interface, determine the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called; According to the bean name of the Dubbo interface, find the corresponding bean instance from the Spring container; According to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtain the method signature of the method to be called; Obtain the call parameter types of the method to be called from the method signature, and deserialize the current call parameters according to the call parameter types into call parameter objects used by the method to be called; Use the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs to trigger a Dubbo RPC call to obtain a Dubbo call result; Serialize the Dubbo call result and generate a Socket protocol message to return to the calling end; If the Dubbo RPC call fails, serialize the Dubbo call error information to obtain the serialized Dubbo call error information; Generate a Dubbo call error result message with the serialized Dubbo call error information and return it to the calling end.
2. The method for converting from Socket protocol to Dubbo protocol according to claim 1, characterized in that, it further includes: Create a Socket Server.
3. The method for converting from Socket protocol to Dubbo protocol according to claim 1, characterized in that, Obtaining the method signature of the method to be called according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called includes: Based on the reflection mechanism of Java, according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called, obtain the method signature of the method to be called.
4. The method for converting from Socket protocol to Dubbo protocol according to claim 1, characterized in that, Taking the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, trigger a Dubbo RPC call to obtain a Dubbo call result, including: taking the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, and based on the reflection mechanism of Java, trigger a Dubbo RPC call to obtain a Dubbo call result.
5. A conversion device from the Socket protocol to the Dubbo protocol, characterized in that, it includes: A parsing unit, configured to parse the current traditional Socket protocol message sent by the calling end through the created Socket Server to obtain the current Socket protocol message identifier and the current call parameter; A determination unit, configured to determine the bean name of the Dubbo interface to be called, the class name of the Dubbo interface to be called, and the method name of the method to be called in the Dubbo interface to be called according to the mapping relationship between the current Socket protocol message identifier and the Dubbo interface pre-configured; A search unit, configured to search for the corresponding bean instance from the Spring container according to the bean name of the Dubbo interface; An obtaining unit, configured to obtain the method signature of the method to be called according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called; A deserialization unit, configured to obtain the call parameter type of the method to be called from the method signature, and deserialize the current call parameter into a call parameter object used by the method to be called according to the call parameter type; A call unit, configured to trigger a Dubbo RPC call with the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs to obtain a Dubbo call result; A feedback unit, configured to serialize the Dubbo call result and generate a Socket protocol message to return to the calling end; An error message serialization unit, configured to serialize the Dubbo call error message if the Dubbo RPC call fails to obtain the serialized Dubbo call error message; The feedback unit is further configured to generate a Dubbo call error result message with the serialized Dubbo call error message and return it to the calling end.
6. The conversion device from the Socket protocol to the Dubbo protocol according to claim 5, characterized in that, it further includes: A creation unit, configured to create a Socket Server.
7. The conversion device from the Socket protocol to the Dubbo protocol according to claim 5, characterized in that, The obtaining unit is specifically configured to: based on the reflection mechanism of Java, obtain the method signature of the method to be called according to the class name of the Dubbo interface to be called and the method name of the method to be called in the Dubbo interface to be called.
8. The conversion device from Socket protocol to Dubbo protocol as described in claim 5, characterized in that, the calling unit is specifically configured to: use the bean instance, the method name of the method to be called, and the call parameter object used by the method to be called as inputs, and trigger a Dubbo RPC call based on the reflection mechanism of Java to obtain a Dubbo call result.
9. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, when the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium, characterized in that, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
11. A computer program product, characterized in that, the computer program product includes a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Protocol conversion method, equipment and system
CN113438251A
Interface access request processing method, API gateway, server and system
CN113806104A