CN114327959A - Method and device for converting Socket protocol into Dubbo protocol - Google Patents

Method and device for converting Socket protocol into Dubbo protocol Download PDF

Info

Publication number
CN114327959A
CN114327959A CN202210012734.6A CN202210012734A CN114327959A CN 114327959 A CN114327959 A CN 114327959A CN 202210012734 A CN202210012734 A CN 202210012734A CN 114327959 A CN114327959 A CN 114327959A
Authority
CN
China
Prior art keywords
dubbo
called
calling
name
interface
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210012734.6A
Other languages
Chinese (zh)
Inventor
马文建
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202210012734.6A priority Critical patent/CN114327959A/en
Publication of CN114327959A publication Critical patent/CN114327959A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method and a device for converting a Socket protocol into a Dubbo protocol, which relate to the field of big data, and the method comprises the following steps: analyzing a traditional Socket protocol message to obtain a current message identifier and a calling parameter; determining the bean name, class name and method name of the Dubbo interface to be called according to the current message identifier, the mapping relation between the preconfigured message identifier and the Dubbo interface; finding an example according to the bean name; acquiring a method signature according to the class name and the method name so as to acquire a calling parameter type, and deserializing a current calling parameter into a calling parameter object based on the type; and triggering and calling by taking the instance, the method name and the object as input. The invention can realize that the Socket protocol used by the traditional service system is converted into the Dubbo protocol used by the new line system in a way of pre-configuring the file, thereby realizing the high-efficiency and low-cost calling of the traditional system to the new line system.

Description

Method and device for converting Socket protocol into Dubbo protocol
Technical Field
The invention relates to the technical field of big data, in particular to a conversion device from a Socket protocol to a Dubbo protocol.
Background
This section is intended to provide a background or context to the embodiments of the invention that are recited in the claims. The description herein is not admitted to be prior art by inclusion in this section.
Currently, for some financial enterprises with early IT system construction, some business systems which have been operated for decades often exist. Because of the evolution of technology, these conventional systems often employ technology that is now viewed as obsolete and their internal communication is different from what is now commonly used. In order to ensure the connectivity between services, data and communication between the new service system and the conventional service system need to be communicated, so as to ensure the interconnection between the two systems.
In a traditional system, a Socket protocol is often directly adopted as a communication protocol between systems; in the new line system, the communication is performed by using RPC protocols such as Dubbo, REST and the like. Therefore, communication barriers between the new service system and the old service system cannot realize interconnection between the two systems. When a traditional system calls a new line system, the existing scheme generally solves the problems of complicated new interfaces, low universality, long development period, high code repetition degree, high requirement on coding personnel and the like existing in manual hard coding, so that the development cost is high and the efficiency is low.
Disclosure of Invention
The embodiment of the invention provides a method for converting a Socket protocol to a Dubbo protocol, which is used for converting the Socket protocol used by the mutual communication of traditional service systems into the Dubbo protocol used by a new line system in a way of pre-configuring a file, and comprises the following steps:
when a created Socket Server receives a current traditional Socket protocol message sent by a calling end, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identification, a mapping relation between the pre-configured Socket protocol message identification and the Dubbo interface;
according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container;
acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called;
obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and a calling parameter object used by the method to be called as input, so as to obtain a Dubbo calling result;
and serializing the Dubbo calling result to generate a Socket protocol message and returning the Socket protocol message to the calling end.
The embodiment of the invention also provides a device for converting the Socket protocol to the Dubbo protocol, which is used for converting the Socket protocol used by the mutual communication of the traditional service system into the Dubbo protocol used by the new line system in a way of pre-configuring files, and comprises the following steps:
the system comprises an analysis unit, a calling unit and a processing unit, wherein the analysis unit is used for analyzing a current traditional Socket protocol message sent by a calling end when the created Socket Server receives the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
the determining unit is used for determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identifier, a preset mapping relation between the Socket protocol message identifier and the Dubbo interface;
the searching unit is used for searching the corresponding bean example from the Spring container according to the bean name of the Dubbo interface;
the obtaining unit is used for obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called;
the deserialization unit is used for acquiring the calling parameter type of the method to be called from the method signature and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
the calling unit is used for triggering Dubbo RPC calling by taking the bean example, the method name of the method to be called and a calling parameter object used by the method to be called as input so as to obtain a Dubbo calling result;
and the feedback unit is used for generating a Socket protocol message after the Dubbo calling result is serialized and returning the Socket protocol message to the calling end.
The embodiment of the invention also provides computer equipment which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the processor realizes the conversion method from the Socket protocol to the Dubbo protocol when executing the computer program.
An embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the method for converting a Socket protocol into a Dubbo protocol is implemented.
An embodiment of the present invention further provides a computer program product, where the computer program product includes a computer program, and when executed by a processor, the computer program implements the method for converting a Socket protocol into a Dubbo protocol.
In the embodiment of the present invention, compared with the technical scheme in the prior art that when a traditional system calls a new line system, the problem of complicated new interfaces, low universality, long development period, high code repetition degree, high requirement on encoding personnel and the like in manual hard coding causes high development cost and low efficiency, the scheme for converting the Socket protocol to the Dubbo protocol is characterized in that: when a current traditional Socket protocol message sent by a calling end is received through a created Socket Server, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter; determining a bean name of a to-be-called Dubbo interface, a class name of the to-be-called Dubbo interface and a method name of a to-be-called method in the to-be-called Dubbo interface according to the current Socket protocol message identifier, a preset mapping relation between the Socket protocol message identifier and the Dubbo interface; according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container; acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called; obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type; triggering Dubbo RPC calling by taking a bean example, a method name of a method to be called and a calling parameter object used by the method to be called as input, and obtaining a Dubbo calling result; the Socket protocol message generated after the Dubbo calling result is serialized is returned to the calling end, so that the Socket protocol used by the mutual communication of the traditional service systems can be converted into the Dubbo protocol used by the new line system in a file pre-configuration mode, the high-efficiency and low-cost calling of the new line system by the traditional system is realized, and the communication barrier between the new service system and the old service system is broken efficiently and low-cost.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts. In the drawings:
fig. 1 is a schematic flow chart of a method for converting a Socket protocol into a Dubbo protocol in the embodiment of the present invention;
fig. 2 is a schematic flow chart of a method for converting a Socket protocol into a Dubbo protocol according to another embodiment of the present invention;
fig. 3 is a schematic flow chart of a method for converting a Socket protocol into a Dubbo protocol according to another embodiment of the present invention;
fig. 4 is a schematic structural diagram of a conversion device from a Socket protocol to a Dubbo protocol in the embodiment of the present invention;
fig. 5 is a schematic structural diagram of a conversion device from Socket protocol to Dubbo protocol in another embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. The exemplary embodiments and descriptions of the present invention are provided to explain the present invention, but not to limit the present invention.
Dubbo: dubbo is an open-sourced, high-performance, lightweight, open-sourced Java RPC framework that provides three core capabilities: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic registration and discovery of services.
Service producer (Provider): in the micro-service architecture, it is responsible for providing services and registering its own services with a registry.
Service Consumer (Consumer): in the micro-service architecture, it is responsible for subscribing to services from the registry and invoking the service producer.
Registry (Registry): for registration and discovery of service producers and service consumers.
Socket protocol message format: the message header of the Socket protocol is 2 or 4 bytes, which represents the length of the message body, and the specific length of the message body of the Socket protocol is defined by the message header.
In the prior art, a hard coding mode is adopted, a packet message parser and a corresponding Dubbo RPC calling class are written one by taking a message ID as a basic unit, and the calling of a traditional system to a new service system is realized. The inventor considers the technical problems existing in the calling of the traditional system to the new business system as follows:
1. the newly added interface is complicated, the universality is not strong, and the development period is long. Every time an interface is added, a whole set of service processing logic needs to be compiled, the process is complicated, and the development period is long.
2. The code repetition degree is high. All codes have higher code repetition degree, and do not conform to the basic principle of 'multiplexing rather than copying' in software engineering.
3. The requirements on encoding personnel are high. The encoding personnel need to have a higher encoding capacity.
In the scheme, developers can have a set of automatic conversion logic from the Socket protocol to the Dubbo protocol through simple configuration, the universality is stronger, the development period is greatly shortened, and repeated coding can be avoided. The scheme mainly comprises the following steps:
1. a Socket Server is created to receive the traditional Socket protocol message.
2. After receiving the Socket protocol message, analyzing the received Socket protocol message, and extracting a TRANS _ ID (message ID) and a calling parameter (character string).
3. And finding the class name and the method name of the corresponding Dubbo interface according to the mapping relation (based on configuration and needing to be maintained in advance) between the TRANS _ ID and the Dubbo interface.
4. Finding a corresponding class instance from a Spring container according to the class name of the Dubbo interface;
5. based on a reflection mechanism of Java, a corresponding method signature is obtained according to the class name and the method name of the Dubbo interface.
6. Deserializing the call parameters (strings) received in step 2 into call parameter types in the method signature.
7. Triggering the Dubbo RPC call.
8. The data returned by Dubbo is serialized.
9. And generating a return message by matching the serialized data with other necessary information, and returning the return message to the calling end.
The conversion scheme from the Socket protocol to the Dubbo protocol is described in detail below.
Fig. 1 is a schematic flow chart of a method for converting a Socket protocol to a Dubbo protocol in an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step 102: when a created Socket Server receives a current traditional Socket protocol message sent by a calling end, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
step 103: determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identification, a mapping relation between the pre-configured Socket protocol message identification and the Dubbo interface;
step 104: according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container;
step 105: acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called;
step 106: obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
step 107: triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and a calling parameter object used by the method to be called as input, so as to obtain a Dubbo calling result;
step 108: and serializing the Dubbo calling result to generate a Socket protocol message and returning the Socket protocol message to the calling end.
The method for converting the Socket protocol into the Dubbo protocol provided by the embodiment of the invention works as follows: when a current traditional Socket protocol message sent by a calling end is received through a created Socket Server, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter; determining a bean name of a to-be-called Dubbo interface, a class name of the to-be-called Dubbo interface and a method name of a to-be-called method in the to-be-called Dubbo interface according to the current Socket protocol message identifier, a preset mapping relation between the Socket protocol message identifier and the Dubbo interface; according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container; acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called; obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type; triggering Dubbo RPC calling by taking a bean example, a method name of a method to be called and a calling parameter object used by the method to be called as input, and obtaining a Dubbo calling result; the Socket protocol message generated after the Dubbo calling result is serialized is returned to the calling end, so that the Socket protocol used by the mutual communication of the traditional service systems can be converted into the Dubbo protocol used by the new line system in a file pre-configuration mode, the high-efficiency and low-cost calling of the new line system by the traditional system is realized, and the communication barrier between the new service system and the old service system is broken efficiently and low-cost. The method is described in detail below with reference to fig. 2 to 3.
Firstly, a pre-preparation stage, namely a stage of pre-establishing each mapping relation, is introduced.
1. In the configuration file, the Dubbo interface to be invoked is registered as a Dubbo consumer to the Dubbo configuration center.
2. The reference to the Dubbo consumer is registered as a bean under the Spring framework, and the name of the bean is specified.
3. A TRANS _ ID white list supporting protocol conversion is configured.
(in the form of Map key-value pairs based on Spring XML configuration files) establishing a mapping relationship between the TRANS _ ID and the corresponding Dubbo consumer bean name.
And 5, (based on the Spring XML configuration file, adopting the form of Map key value pairs), establishing a mapping relation between the TRANS _ ID and the interface class name of the called interface in the Dubbo interface.
And 6, (based on the Spring XML configuration file, adopting the form of Map key value pairs), establishing a mapping relation between the TRANS _ ID and the name of the method called in the Dubbo interface.
In summary, the preparation stage is configured with a mapping relationship between the Socket protocol message identifier and the Dubbo interface in advance, and the relationship includes a relationship between the Socket protocol message identifier and a bean name and a class name of the Dubbo interface, and a method name of a method to be called in the Dubbo interface.
Next, the formal phases, i.e., steps 101 to 108, are introduced.
In one embodiment, as shown in fig. 2, before the step 102, a step 101 may be further included: a Socket Server is created.
In the specific implementation, in step 101, a Socket Server is created to receive a conventional Socket protocol packet.
In step 102, after receiving the Socket protocol packet, the received Socket protocol packet is analyzed, and a TRANS _ ID (packet ID) and a call parameter (character string), that is, a current Socket protocol packet identifier and a current call parameter, are extracted.
In the step 103, matching the pre-configured Socket protocol message identifier in the preparation stage of identifying the current Socket protocol message to the "one" with the mapping relationship of the Dubbo interface 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, that is, finding 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 (the Dubbo interface to be called) according to the mapping relationship (based on configuration and maintenance in advance) between TRANS _ ID (Socket protocol message identifier) and the Dubbo interface.
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 the Spring, and the Spring beans are all stored in the Spring container, namely a bean factory.
In step 105, in an embodiment, obtaining a method signature of the method to be called according to the class name of the to-be-called Dubbo interface and the name of the method to be called in the to-be-called Dubbo interface may include: and based on a reflection mechanism of Java, obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called.
In specific implementation, based on a reflection mechanism of Java, a corresponding method signature is obtained according to the class name and method name of the Dubbo interface.
In the above step 106, the calling parameter type of the method to be called is obtained from the method signature, and the calling parameter (character string, i.e. current calling parameter) received in the step 102 is deserialized into a calling parameter object used by the method to be called based on the calling parameter type. Deserialization: the character string is converted into an object of a specific Java data type. For this example, the call parameters (strings) are converted to call parameter objects to be used by the called method. The general calling parameter (character string) is stored in the JSON format, and the deserialization process can be as follows:
parsejssoobject (call parameter string, call parameter type);
to facilitate understanding of the implementation of the deserialization, one example is shown in table 1 below:
Figure BDA0003458311860000081
TABLE 1
In step 107, triggering a Dubbo RPC call by using the bean instance, the name of the method to be called, and the call parameter object used by the method to be called as inputs, and obtaining a Dubbo call result, which may include: and triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and the calling parameter object used by the method to be called as input based on a Java reflection mechanism to obtain a Dubbo calling result.
In specific implementation, a bean example, a method name of a method to be called and a calling parameter of the method to be called are used as input, and the Dubbo RPC calling is triggered based on a Java reflection mechanism to obtain a Dubbo calling result.
In step 108, after the Dubbo producer returns the data, serializing the data returned by the Dubbo (obtaining the Dubbo calling result), that is, converting the Java object into a string format. If the Dubbo RPC call fails, the error information is serialized. And generating a return message by matching the serialized data, namely the normal return data (the serialized normal Dubbo calling result) or the error information (the serialized Dubbo calling error information) with other necessary information, and returning the return message to the calling end.
As can be seen from the above, in an embodiment, the method for converting from the Socket protocol to the Dubbo protocol may further include: if the Dubbo RPC call fails, serializing the Dubbo call error information to obtain serialized Dubbo call error information; and generating a Dubbo calling error result message from the serialized Dubbo calling error information and returning the Dubbo calling error result message to the calling end.
To sum up, the method for converting a Socket protocol to a Dubbo protocol provided in the embodiments of the present invention is an automatic conversion method from a Socket protocol to a Dubbo protocol, and the method can automatically convert the Socket protocol to the Dubbo protocol by adjusting a configuration file, that is, automatically convert the Socket protocol used for mutual communication of the conventional service systems to the Dubbo protocol used by the new line system, thereby realizing the call of the conventional system to the new line system, breaking the communication wall between the new and old service systems, and solving the problems of complicated new interfaces, low generality, long development period, high code repetition, high requirement on encoding personnel, and the like existing in manual hard coding when the conventional system calls the new line system, thereby reducing the development cost and improving the development efficiency.
The embodiment of the invention also provides a device for converting a Socket protocol into a Dubbo protocol, which is described in the following embodiments. Because the principle of the device for solving the problems is similar to the method for converting the Socket protocol into the Dubbo protocol, the implementation of the device can be seen in the implementation of the method for converting the Socket protocol into the Dubbo protocol, and repeated details are omitted.
Fig. 4 is a schematic structural diagram of a conversion apparatus from Socket protocol to Dubbo protocol in the embodiment of the present invention, and as shown in fig. 4, the apparatus includes:
the analysis unit 02 is used for analyzing the current traditional Socket protocol message sent by the calling end when the created Socket Server receives the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
a determining unit 03, configured to determine, according to the current Socket protocol message identifier, a mapping relationship between a preconfigured Socket protocol message identifier and a Dubbo interface, a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called, and a method name of a method to be called in the Dubbo interface to be called;
the searching unit 04 is used for searching the corresponding bean example from the Spring container according to the bean name of the Dubbo interface;
the obtaining unit 05 is configured to obtain a method signature of the method to be called according to the class name of the to-be-called Dubbo interface and the name of the method to be called in the to-be-called Dubbo interface;
the deserialization unit 06 is configured to obtain a calling parameter type of the method to be called from the method signature, and deserialize the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
the calling unit 07 is used for triggering the Dubbo RPC calling by taking the bean example, the method name of the method to be called and the calling parameter object used by the method to be called as input, so as to obtain a Dubbo calling result;
and the feedback unit 08 is used for generating a Socket protocol message after the Dubbo calling result is serialized and returning the Socket protocol message to the calling end.
In specific implementation, the 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 from the serialized Dubbo call result and returns the Socket protocol message to the call end.
In an embodiment, the above apparatus for converting Socket protocol to Dubbo protocol may further include: the error information serialization unit is used for serializing the Dubbo call error information to obtain serialized Dubbo call error information if the Dubbo RPC call fails;
the feedback unit may be further configured to generate a Dubbo invocation error result message from the serialized Dubbo invocation error information and return the Dubbo invocation error result message to the invocation end.
In an embodiment, as shown in fig. 5, the above-mentioned conversion apparatus from Socket protocol to Dubbo protocol may further include: and the creating unit 01 is used for creating a Socket Server.
In one embodiment, the obtaining unit is specifically configured to: and based on a reflection mechanism of Java, obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called.
In one embodiment, the calling unit is specifically configured to: and triggering DubboRPC calling by taking the bean example, the name of the method to be called and a calling parameter object used by the method to be called as input based on a reflection mechanism of Java to obtain a Dubbo calling result.
In specific implementation, each module related to the embodiment of the present invention is described below.
1. And the mapping relation maintenance module is responsible for maintaining a TRANS _ ID white list, a mapping relation between the TRANS _ ID and the corresponding Dubbo consumer bean name, a mapping relation between the TRANS _ ID and the interface class name of a called interface in the Dubbo interface, a mapping relation between the TRANS _ ID and the method name of the called method in the Dubbo interface and the like.
2. The Socket protocol message receiving module, namely the creating unit, is responsible for creating one or more Socket servers, and is used for receiving the Socket protocol messages sent by the traditional system.
3. And the Socket protocol message analysis module is the analysis unit. After receiving the Socket protocol message, the Socket protocol message receiving module is responsible for analyzing the received Socket protocol message and extracting a TRANS _ ID (message ID) and a calling parameter (character string).
4. The Dubbo remote call triggering module comprises the determining unit, the searching unit, the obtaining unit, the deserializing unit and the calling unit, and specifically comprises the following steps:
1) according to the mapping relationship between the TRANS _ ID and the Dubbo interface (based on configuration, maintenance is needed in advance), the bean name in the Spring container used by the corresponding Dubbo interface, the class name corresponding to the Dubbo interface class, and the method name of the method to be called in the called interface are found, and the step can be realized by the determining unit.
2) According to the bean name of the Dubbo interface, finding the corresponding bean instance from the Spring container, and the step can be realized by the finding unit.
3) Based on the reflection mechanism of Java, the method signature of the method to be called is obtained according to the class name and the method name of the Dubbo interface, and this step can be implemented by the obtaining unit.
4) The step of deserializing the received call parameter (character string) into a call parameter object used by the method to be called by using the call parameter type obtained from the method signature of the method to be called can be realized by the deserializing unit.
5) The method comprises the steps of taking a bean example, the name of a method to be called and a calling parameter of the method to be called as input, triggering Dubbo RPC calling based on a Java reflection mechanism, and realizing the step through the calling unit.
5. The Socket protocol returns to the message serialization module, which is referred to as the feedback unit. And (4) matching the serialized data (normal return data or error information) with other necessary information to generate a return message, and returning the return message to the calling end. In particular, the module implements:
1) after the data is returned by the Dubbo producer, the data returned by the Dubbo is serialized.
2) If the Dubbo RPC call fails, the error information is serialized.
In order to facilitate understanding of how the present invention is implemented, the operation of each module related to the embodiment of the present invention is described below.
1. And maintaining the relevant mapping relation in a mapping relation maintenance module.
2. The Socket protocol message receiving module receives a Socket protocol message sent by a traditional system and transmits the Socket protocol message to the Socket protocol message analyzing module.
3. The Socket protocol message analysis module is responsible for analyzing the received Socket protocol message, extracting a TRANS _ ID (message ID) and a calling parameter (character string), and triggering the Dubbo remote calling triggering module.
4. And the Dubbo remote call triggering module deserializes call parameters (character strings) and triggers Dubbo remote call according to the TRANS _ ID extracted by the Socket protocol message analysis module and the mapping relation maintained by the TRANS _ ID in the mapping relation maintenance module. After the Dubbo producer returns data, the module is responsible for serializing the data returned by the Dubbo and transmitting the serialized data to the Socket protocol return message serialization module.
5. And the Socket protocol return message serialization module generates a return message by matching the serialized data (normal return data or error information) with other necessary information, and returns the return message to the calling end.
According to the technical scheme, the data acquisition, storage, use, processing and the like meet relevant regulations of national laws and regulations.
The embodiment of the invention also provides computer equipment which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the processor realizes the conversion method from the Socket protocol to the Dubbo protocol when executing the computer program.
An embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the method for converting a Socket protocol into a Dubbo protocol is implemented.
An embodiment of the present invention further provides a computer program product, where the computer program product includes a computer program, and when executed by a processor, the computer program implements the method for converting a Socket protocol into a Dubbo protocol.
In the embodiment of the present invention, compared with the technical scheme in the prior art that when a traditional system calls a new line system, the problem of complicated new interfaces, low universality, long development period, high code repetition degree, high requirement on encoding personnel and the like in manual hard coding causes high development cost and low efficiency, the scheme for converting the Socket protocol to the Dubbo protocol is characterized in that: when a created Socket Server receives a current traditional Socket protocol message sent by a calling end, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter; determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identification, a mapping relation between the pre-configured Socket protocol message identification and the Dubbo interface; according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container; acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called; obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type; triggering DubboRPC calling by taking the bean example, the name of the method to be called and a calling parameter object used by the method to be called as input, so as to obtain a Dubbo calling result; and after the Dubbo calling result is serialized, a Socket protocol message is generated and returned to the calling end, so that the Socket protocol used by the mutual communication of the traditional service systems can be converted into the Dubbo protocol used by the new line system in a file pre-configuration mode, the high-efficiency and low-cost calling of the new line system by the traditional system is realized, and the communication barrier between the new service system and the old service system is broken efficiently and at low cost.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (13)

1. A method for converting a Socket protocol into a Dubbo protocol is characterized by comprising the following steps:
when a created Socket Server receives a current traditional Socket protocol message sent by a calling end, analyzing the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identification, a mapping relation between the pre-configured Socket protocol message identification and the Dubbo interface;
according to the bean name of the Dubbo interface, finding a corresponding bean example from the Spring container;
acquiring a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called;
obtaining the calling parameter type of the method to be called from the method signature, and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and a calling parameter object used by the method to be called as input, so as to obtain a Dubbo calling result;
and serializing the Dubbo calling result to generate a Socket protocol message and returning the Socket protocol message to the calling end.
2. The method for converting Socket protocol to Dubbo protocol according to claim 1, further comprising:
if the Dubbo RPC call fails, serializing the Dubbo call error information to obtain serialized Dubbo call error information;
and generating a Dubbo calling error result message from the serialized Dubbo calling error information and returning the Dubbo calling error result message to the calling end.
3. The method for converting Socket protocol to Dubbo protocol according to claim 1, further comprising: a Socket Server is created.
4. The method for converting Socket protocol to Dubbo protocol according to claim 1, wherein obtaining the method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called comprises: and based on a reflection mechanism of Java, obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called.
5. The method for converting Socket protocol to Dubbo protocol according to claim 1, wherein the method name of the method to be called and the call parameter object used by the method to be called are used as input to trigger the Dubbo RPC call, and the result of the Dubbo call is obtained, and the method comprises: and triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and the calling parameter object used by the method to be called as input based on a Java reflection mechanism to obtain a Dubbo calling result.
6. A conversion apparatus from Socket protocol to Dubbo protocol, comprising:
the system comprises an analysis unit, a calling unit and a processing unit, wherein the analysis unit is used for analyzing a current traditional Socket protocol message sent by a calling end when the created Socket Server receives the current traditional Socket protocol message to obtain a current Socket protocol message identifier and a current calling parameter;
the determining unit is used for determining a bean name of the Dubbo interface to be called, a class name of the Dubbo interface to be called and a method name of a method to be called in the Dubbo interface to be called according to the current Socket protocol message identifier, a preset mapping relation between the Socket protocol message identifier and the Dubbo interface;
the searching unit is used for searching the corresponding bean example from the Spring container according to the bean name of the Dubbo interface;
the obtaining unit is used for obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called;
the deserialization unit is used for acquiring the calling parameter type of the method to be called from the method signature and deserializing the current calling parameter into a calling parameter object used by the method to be called according to the calling parameter type;
the calling unit is used for triggering Dubbo RPC calling by taking the bean example, the method name of the method to be called and a calling parameter object used by the method to be called as input so as to obtain a Dubbo calling result;
and the feedback unit is used for generating a Socket protocol message after the Dubbo calling result is serialized and returning the Socket protocol message to the calling end.
7. The apparatus for converting Socket protocol to Dubbo protocol according to claim 6, further comprising: the error information serialization unit is used for serializing the Dubbo call error information to obtain serialized Dubbo call error information if the Dubbo RPC call fails;
the feedback unit is further configured to generate a Dubbo call error result message from the serialized Dubbo call error information and return the Dubbo call error result message to the call end.
8. The apparatus for converting Socket protocol to Dubbo protocol according to claim 6, further comprising: and the creating unit is used for creating a Socket Server.
9. The apparatus for converting a Socket protocol into a Dubbo protocol according to claim 6, wherein said obtaining unit is specifically configured to: and based on a reflection mechanism of Java, obtaining a method signature of the method to be called according to the class name of the Dubbo interface to be called and the name of the method to be called in the Dubbo interface to be called.
10. The apparatus for converting a Socket protocol into a Dubbo protocol according to claim 6, wherein said invoking unit is specifically configured to: and triggering Dubbo RPC calling by taking the bean example, the name of the method to be called and the calling parameter object used by the method to be called as input based on a Java reflection mechanism to obtain a Dubbo calling result.
11. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any one of claims 1 to 5 when executing the computer program.
12. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, implements the method of any of claims 1 to 5.
13. A computer program product, characterized in that the computer program product comprises a computer program which, when being executed by a processor, carries out the method of any one of claims 1 to 5.
CN202210012734.6A 2022-01-06 2022-01-06 Method and device for converting Socket protocol into Dubbo protocol Pending CN114327959A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210012734.6A CN114327959A (en) 2022-01-06 2022-01-06 Method and device for converting Socket protocol into Dubbo protocol

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210012734.6A CN114327959A (en) 2022-01-06 2022-01-06 Method and device for converting Socket protocol into Dubbo protocol

Publications (1)

Publication Number Publication Date
CN114327959A true CN114327959A (en) 2022-04-12

Family

ID=81025265

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210012734.6A Pending CN114327959A (en) 2022-01-06 2022-01-06 Method and device for converting Socket protocol into Dubbo protocol

Country Status (1)

Country Link
CN (1) CN114327959A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370231A (en) * 2023-12-07 2024-01-09 芯动微电子科技(武汉)有限公司 Protocol conversion module and method for realizing network bus access on chip of GPU (graphics processing Unit)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370231A (en) * 2023-12-07 2024-01-09 芯动微电子科技(武汉)有限公司 Protocol conversion module and method for realizing network bus access on chip of GPU (graphics processing Unit)
CN117370231B (en) * 2023-12-07 2024-04-12 芯动微电子科技(武汉)有限公司 Protocol conversion module and method for realizing network bus access on chip of GPU (graphics processing Unit)

Similar Documents

Publication Publication Date Title
US6757899B2 (en) Dynamic CORBA gateway for CORBA and non-CORBA clients and services
US20030009539A1 (en) Distributed object middleware connection method
CN107241315B (en) Access method and device of bank gateway interface and computer readable storage medium
CN109815025B (en) Service model calling method, device and storage medium
US11561997B2 (en) Methods, systems, and computer readable media for data translation using a representational state transfer (REST) application programming interface (API)
CN111552568B (en) Cloud service calling method and device
CN108446105B (en) Lightweight API Server development framework and development method
CN109739624B (en) Distributed transaction processing method and device, electronic equipment and computer readable medium
CN113515278A (en) Low code model processing method, system, electronic device and storage medium
CN116915829A (en) Optical communication system
CN114327959A (en) Method and device for converting Socket protocol into Dubbo protocol
CN112988409B (en) Interface calling method and device, computer equipment and storage medium
US8250587B2 (en) Non-persistent and persistent information setting method and system for inter-process communication
US20220245080A1 (en) Method for communication of a componentized application, computing device and computer storage medium
CN113360386B (en) Method and device for testing driving of switching chip, electronic equipment and storage medium
CN113448655B (en) C standard dynamic library calling method and device
US20070106778A1 (en) Information and status and statistics messaging method and system for inter-process communication
WO2013016994A1 (en) Message sending method and system
CN112134900B (en) Data message processing method and device
US20200110584A1 (en) Automated code generation for functional testing of software applications
CN116204239A (en) Service processing method, device and computer readable storage medium
CN111258940B (en) Configuration method, business auditing system, business auditing equipment and storage medium
CN114675821B (en) Service standardization system and method based on low codes
CN104270453A (en) Method for data communication between multilevel servers and servers
CN111459492A (en) Method, device, storage medium and equipment for detecting compatibility of Dubbo service interface

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination