A communication method and device based on a message middleware general interface
By encapsulating unified units and heterogeneous middleware units, a universal interface call for message middleware is realized, solving the problem of increased interface complexity and improving communication efficiency and adaptability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU EBOYLAMP ELECTRONICS CO LTD
- Filing Date
- 2023-11-02
- Publication Date
- 2026-07-24
AI Technical Summary
Existing heterogeneous message middleware processing methods increase the complexity of interface calls and affect communication efficiency, especially when frequently switching or integrating multiple types of message middleware.
A communication method based on a general interface for message middleware is adopted. Different types of message middleware are encapsulated through unified units and heterogeneous middleware units, and unified interface calls are implemented. This includes the selection of task information processing, registration management, heartbeat signal monitoring, shared memory and network communication methods, thereby enabling flexible communication interface calls.
It reduces the complexity of interface calls, improves communication efficiency, adapts to various application scenarios and frequent switching, and ensures the efficiency and flexibility of communication.
Smart Images

Figure CN117591305B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a communication method and apparatus based on a message middleware general interface. Background Technology
[0002] During project development, using message middleware to enable communication between different modules can effectively solve the coupling problem between business modules. However, it is important to note that different types of message middleware have different interface requirements. In practical applications, when it is necessary to frequently switch between message middleware types, or to integrate multiple types of message middleware simultaneously within the same software, heterogeneous processing of message middleware is adopted, that is, different types of message middleware are assigned to different tasks.
[0003] Existing heterogeneous processing methods are all one-to-one, that is, a corresponding interface and interface calling method are established for each type of message middleware. However, when there are many application scenarios or frequent changes, the types of message middleware will increase accordingly, which will easily lead to an increase in the number of corresponding interfaces and interface calling methods, and the complexity of calling interfaces will also increase, thus affecting the corresponding communication efficiency. Summary of the Invention
[0004] To address the increased complexity of calling message middleware interfaces mentioned above, this application provides a communication method and apparatus based on a general message middleware interface, the technical solution of which is as follows:
[0005] In a first aspect, embodiments of this application provide a communication method based on a message middleware general interface, including:
[0006] The system receives task information from a first object and determines a first function corresponding to the task type in the task information from a preset first function library based on a unified unit; wherein, the first function library includes at least two task types and a first function corresponding to each task type;
[0007] Based on the middleware heterogeneous unit, a second function corresponding to the middleware type in the task information is determined in the second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type;
[0008] When the middleware type is identified as network type, the communication method of the first object is obtained based on the preset management database;
[0009] The type of the first interface is determined based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface.
[0010] In one alternative embodiment of the first aspect, after receiving the task information of the first object and before determining the first function corresponding to the task type in the task information based on the unified unit in a preset first function library, the process includes:
[0011] When the middleware type in the task information is identified as network type, the registration information of the first object is sent to the preset management database so that the preset management database can perform registration processing on the first object;
[0012] When a registration success message is received from the preset management database, the heartbeat signal of the first object is obtained at preset time intervals.
[0013] In another alternative to the first aspect, after acquiring the heartbeat signal of the first object at preset time intervals, the process includes:
[0014] If the heartbeat signal of the first object is not obtained within at least two time intervals, the unregistration information of the first object is sent to the preset management database, so that the preset management database can perform unregistration processing on the first object based on the unregistration information.
[0015] In another alternative to the first aspect, the communication method of the first object is obtained based on a preset management database, including:
[0016] Based on the topic information in the task information, the target topic library corresponding to the topic information is determined in the preset management database;
[0017] Based on the identity information in the task information, the address information of the second object is determined in the target topic library; wherein, the preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information, the target topic library includes at least two types of identity information and address information corresponding to each type of identity information, and the identity information in the task information is inconsistent with the identity information of the second object;
[0018] When the address information in the task information is found to be consistent with the address information of the second object, the shared memory method will be used as the communication method of the first object.
[0019] When the address information in the task information is found to be inconsistent with the address information of the second object, the network communication method is used as the communication method of the first object.
[0020] In another alternative to the first aspect, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the process includes:
[0021] When it is identified that the middleware type is not a network type, the type of the second interface is determined based on the preset communication method and the second function, and the first object calls the second interface according to the type of the second interface.
[0022] In another alternative to the first aspect, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0023] When the middleware type is identified as network type, the first subscription data is obtained based on the second function and the preset first subscription method;
[0024] When it is detected that the first subscription data is not empty, send the first subscription data and subscription success information to the first object;
[0025] When the first subscription data is detected to be empty, the second subscription data is obtained based on the second function and the preset second subscription method;
[0026] When it is detected that the second subscription data is not empty, send the second subscription data and subscription success information to the first object;
[0027] When the second subscription data is detected to be empty, a subscription failure message is sent to the first object.
[0028] In another alternative to the first aspect, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0029] When the middleware type is identified as network type, the first publishing interface is called based on the second function and the preset first publishing method;
[0030] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0031] If no release status code is received within the preset release time, the second release interface is called based on the second function and the preset second release method;
[0032] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0033] If a publication status code is not received within the preset publication time, a publication failure message is sent to the first object.
[0034] Secondly, embodiments of this application provide a communication device based on a message middleware general interface, comprising:
[0035] The first processing module is used to receive task information of the first object and determine the first function corresponding to the task type in the task information based on the unified unit in the preset first function library; wherein, the first function library includes at least two task types and the first function corresponding to each task type;
[0036] The second processing module is used to determine, based on the middleware heterogeneous unit, the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type;
[0037] The third processing module is used to obtain the communication method of the first object based on a preset management database when the middleware type is identified as network type.
[0038] The fourth processing module is used to determine the type of the first interface based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface.
[0039] Thirdly, embodiments of this application also provide a communication device based on a message middleware general interface, including a processor and a memory;
[0040] The processor is connected to the memory;
[0041] Memory, used to store executable program code;
[0042] The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to implement the communication method based on the message middleware general interface provided by the first aspect or any implementation of the first aspect of the embodiments of this application.
[0043] Fourthly, embodiments of this application provide a computer storage medium storing a computer program, which includes program instructions. When executed by a processor, the program instructions can implement the communication method based on a message middleware general interface provided by the first aspect or any implementation of the first aspect of this application.
[0044] The beneficial effects of the technical solutions provided in some embodiments of this specification include at least the following:
[0045] In the communication process based on the general interface of the message middleware, the task information of the first object is received, and the first function corresponding to the task type in the task information is determined in the preset first function library based on the unified unit; the second function corresponding to the middleware type in the task information is determined in the second function library corresponding to the first function based on the middleware heterogeneous unit; when the middleware type is identified as network type, the communication method of the first object is obtained based on the preset management database; the type of the first interface is determined based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface. By obtaining the second function corresponding to the first object through the unified unit and the middleware heterogeneous unit, and determining the communication method corresponding to the first object according to the middleware type, the communication method can be combined with the second function as a parameter to flexibly call the communication interface corresponding to the first object, so as to realize the convenience and efficiency of the first object calling the corresponding communication interface, ensuring that the complexity of calling the middleware interface does not increase with the increase of middleware types, thereby improving communication efficiency and adapting to various application scenarios and frequent switching of application scenarios. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 A flowchart illustrating an overall communication method based on a message middleware general interface, provided for embodiments of this application;
[0048] Figure 2 A flowchart illustrating another communication method based on a message middleware general interface provided in this application embodiment;
[0049] Figure 3 A block diagram of a communication system based on a message middleware general interface is provided for embodiments of this application;
[0050] Figure 4 A schematic diagram illustrating the working principle of a management center provided in this application embodiment;
[0051] Figure 5 A schematic diagram of the structure of a communication device based on a message middleware general interface provided in an embodiment of this application;
[0052] Figure 6 This is a schematic diagram of the structure of another communication device based on a message middleware general interface provided in the embodiments of this application. Detailed Implementation
[0053] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0054] In the following description, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The following description provides multiple embodiments of this application, which can be substituted or combined with each other. Therefore, this application can also be considered to include all possible combinations of the same and / or different embodiments described. Thus, if one embodiment includes features A, B, and C, and another embodiment includes features B and D, then this application should also be considered to include embodiments containing one or more other possible combinations of A, B, C, and D, even if such embodiments are not explicitly described in the following text.
[0055] The following description provides examples and does not limit the scope, applicability, or examples set forth in the claims. Changes may be made to the function and arrangement of the described elements without departing from the scope of this application. Various processes or components may be appropriately omitted, substituted, or added to the examples. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Furthermore, features described with respect to some examples may be combined into other examples.
[0056] Please see Figure 1 , Figure 1 The diagram shows an overall flowchart of a communication method based on a message middleware general interface provided in an embodiment of this application.
[0057] like Figure 1 As shown, this communication method based on a message middleware general interface may include at least the following steps:
[0058] Step 101: Receive the task information of the first object, and determine the first function corresponding to the task type in the task information in the preset first function library based on the unified unit.
[0059] The preset first function library includes at least two task types and a first function corresponding to each task type.
[0060] In this embodiment, the communication method based on the message middleware general interface can be applied to mobile terminals, but is not limited to them. By using the unified unit and the middleware heterogeneous unit in the message middleware general interface, different types of message middleware are encapsulated and unified with external interfaces, which solves the problem of inconsistent message middleware interfaces in the past. This allows the method to be applied to flexible and varied application scenarios while ensuring communication efficiency.
[0061] Specifically, in the communication process based on the general interface of message middleware, after receiving the communication request of the first object, the task information of the object for this communication can be obtained. The first object includes, but is not limited to, hardware devices, software applications, or network services. Since this application adopts a publish-subscribe mechanism design pattern for communication, the task information includes at least the identity information of the first object (subscriber or publisher), topic information (subscribed or published topic name and topic content, etc.), task type (creating a topic, subscribing to a topic, or publishing a topic, etc.), address information (the IP address of the object), and the type of middleware to be used for this communication.
[0062] Furthermore, the unified unit determines the first function from a pre-defined first function library based on the task type of the first object. The unified unit consists of multiple abstract interfaces, each defining communication and interaction rules between objects corresponding to different task types. These rules include functions, methods, and data structures that can be called by other programs to enable data transfer and function calls between objects. Simultaneously, each abstract interface corresponds to a first function, which is a specific code block used to execute operations corresponding to the task type. It can be understood that the abstract interfaces in the unified unit describe the external behavior and capabilities of the object, while the first function contains the specific implementation details and logic. For example, when the task type is subscription to a topic, the abstract interfaces in the unified unit must at least include a subscription interface, and the first function library must at least include a first function that implements the specific process of the subscription interface (such as inputting callback function pointers and outputting subscription results).
[0063] As an optional embodiment of this application, after receiving the task information of the first object, before determining the first function corresponding to the task type in the task information based on the unified unit in the preset first function library, the following steps are included:
[0064] When the middleware type in the task information is identified as network type, the registration information of the first object is sent to the preset management database so that the preset management database can perform registration processing on the first object;
[0065] When a registration success message is received from the preset management database, the heartbeat signal of the first object is obtained at preset time intervals.
[0066] Specifically, after obtaining the task information of the first object and before determining the corresponding first function, the middleware type in the task information of the object can be determined first. When the determination result is a network type, the object's identity information, topic information, and address information can be collected into registration information and sent to a preset management database. The collection method includes, but is not limited to, using data types such as lists, arrays, or key-value pairs. Next, the preset management database performs registration processing on the object, that is, stores the object's registration information in the database and generates a corresponding unique identifier (ID). After the preset management database completes the registration processing, a registration success message sent from the preset management database can be received. At this time, the object will send heartbeat signals at preset time intervals to indicate that it is in a normal communication state. Then, the object's heartbeat signals can be acquired at preset time intervals to monitor the object's communication state; or the object has been continuously sending heartbeat signals at preset time intervals since its creation to indicate that it is in a normal communication state. When a registration success message is received from the preset management database, the object's heartbeat signals can be acquired at preset time intervals to monitor the object's communication state.
[0067] It is worth noting that the preset management database can be, but is not limited to, execution in the cloud; that is, the registration process and sending registration success information mentioned above can both be executed in the cloud. At the same time, the operation of obtaining the object's heartbeat signal can be performed not only by the mobile terminal but also by the cloud.
[0068] As another optional embodiment of this application, after acquiring the heartbeat signal of the first object at preset time intervals, the method includes:
[0069] If the heartbeat signal of the first object is not obtained within at least two time intervals, the unregistration information of the first object is sent to the preset management database, so that the preset management database can perform unregistration processing on the first object based on the unregistration information.
[0070] Specifically, after acquiring the heartbeat signal of the first object at preset time intervals, if no heartbeat signal is acquired from the object after two preset time intervals, it indicates that the object is in a communication termination state. The object's deregistration information will then be sent to a preset management database. This deregistration information includes at least the object's registration information and a deregistration request. Next, the preset management database will perform deregistration processing on the object based on the deregistration information, i.e., delete the object's registration information and corresponding ID, indicating that the object has exited system communication.
[0071] Step 102: Based on the middleware heterogeneous unit, determine the second function corresponding to the middleware type in the task information in the second function library corresponding to the first function.
[0072] The pre-defined second function library includes at least two middleware types and a second function corresponding to each middleware type.
[0073] Specifically, after determining the first function corresponding to the task type of the first object, the middleware heterogeneous unit can determine the corresponding second function based on the first function and the middleware type in the task information. The specific determination method can be as follows: based on the function name of the first function, find all second functions in the second function library with the same function name as the first function; then, based on the middleware type in the task information, determine the unique second function corresponding to the middleware type from all the aforementioned second functions. The correspondence can be, but is not limited to, different middleware types corresponding to different numbers or types of parameters in the second function. For example, middleware type A corresponds to a second function with two integer parameters; middleware type B corresponds to a second function with one integer parameter and two floating-point parameters; and middleware type C corresponds to a second function with no parameters.
[0074] Step 103: When the middleware type is identified as network type, the communication method of the first object is obtained based on the preset management database.
[0075] Specifically, after determining the second function corresponding to the task information of the first object, it is possible to determine whether the middleware type in the task information is a network type. When the determination result is yes, the relevant information of another object (i.e., the second object) that communicates with the first object can be retrieved from the preset management database based on the task information of the first object.
[0076] Furthermore, the communication method of the first object can be determined based on the amount of data transmitted between the first object and the second object, the transmission speed requirements, etc., or based on the relevant information of the second object, such as address information, etc.
[0077] As another optional embodiment of this application, the communication method of the first object is obtained based on a preset management database, including:
[0078] Based on the topic information in the task information, the target topic library corresponding to the topic information is determined in the preset management database;
[0079] Based on the identity information in the task information, the address information of the second object is determined in the target topic library; wherein, the preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information, the target topic library includes at least two types of identity information and address information corresponding to each type of identity information, and the identity information in the task information is inconsistent with the identity information of the second object;
[0080] When the address information in the task information is found to be consistent with the address information of the second object, the shared memory method will be used as the communication method of the first object.
[0081] When the address information in the task information is found to be inconsistent with the address information of the second object, the network communication method is used as the communication method of the first object.
[0082] Specifically, in determining the communication method of the first object based on the preset management database, the target topic library corresponding to the topic information in the task information of the first object is first selected from the preset management database. The target topic library is a sub-library divided from the preset management database based on the topic information. Next, a second object with different identity information from the first object (i.e., one is a publisher, and the other is a subscriber) is found in the target topic library corresponding to the topic information, and the address information of the second object is obtained.
[0083] It is worth noting that the preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information. Furthermore, the target topic library includes at least two types of identity information and address information corresponding to each type of identity information. For example, the preset management database includes topic A, topic B, a target topic library C corresponding to topic A, and a target topic library D corresponding to topic B. Target topic library C includes subscriber 1, subscriber 2, publisher 1, the address information of subscriber 1, the address information of subscriber 2, and the address information of publisher 1 for topic A. Target topic library D includes subscriber 3, subscriber 4, publisher 2, publisher 3, the address information of subscriber 3, the address information of subscriber 4, the address information of publisher 2, and the address information of publisher 3 for topic B.
[0084] Subsequently, based on the comparison results between the address information of the first object and the address information of the second object, the corresponding communication method is selected as the communication method between the two. Specifically, the determination method is as follows: when the comparison result shows that the address information of the two objects is consistent, the shared memory method is selected as the communication method for the first object to communicate; when the comparison result shows that the address information of the two objects is inconsistent, the network communication method is selected as the communication method for the first object to communicate.
[0085] Understandably, when the first object is subscriber 1 as described above, according to the query results of the preset management database, only publisher 1 meets the search criteria for the second object. Therefore, publisher 1 is selected as the second object, and its address information is obtained. When subscriber 1 and publisher 1 have the same address information, subscriber 1 uses shared memory for subscription; when subscriber 1 and publisher 1 have different address information, subscriber 1 uses network communication for subscription. Furthermore, if there are multiple second objects that meet the search criteria for the second object (i.e., their identity information is different from the first object), such as in the case of target subject database D mentioned above, the communication methods between the first object and each second object will be determined sequentially.
[0086] Step 104: Determine the type of the first interface based on the communication method and the second function, and have the first object call the first interface according to the type of the first interface.
[0087] Specifically, after identifying the middleware type as a network type and determining the communication method of the first object, the communication method can be passed as parameter information to the second function, and the second function can determine the type of the first interface corresponding to the task information of the first object.
[0088] Furthermore, the first object calls the first interface according to the type of the first interface, wherein the first interface can be a specific interface corresponding to the task type and the middleware type. For example, when the task type is a subscription topic and the middleware type is class A, the first interface is the subscription interface A1 of class A middleware.
[0089] As another optional embodiment of this application, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method includes:
[0090] When it is identified that the middleware type is not a network type, the type of the second interface is determined based on the preset communication method and the second function, and the first object calls the second interface according to the type of the second interface.
[0091] Specifically, after determining the second function corresponding to the task information of the first object, it can be determined whether the middleware type in the task information is a network type. If the determination result is negative, the preset communication method corresponding to that middleware type can be obtained, such as the preset communication method 'a' for type A middleware and 'b' for type B middleware. This preset communication method is passed as parameter information to the second function, which then determines the type of the second interface corresponding to the task information of the first object. Next, the first object calls the second interface according to its type. The second interface can be a specific interface corresponding to the task type and the middleware type. For example, when the task type is publishing a topic and the middleware type is type B, the second interface is the publishing interface B1 of type B middleware.
[0092] As another optional embodiment of this application, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0093] When the middleware type is identified as network type, the first subscription data is obtained based on the second function and the preset first subscription method;
[0094] When it is detected that the first subscription data is not empty, send the first subscription data and subscription success information to the first object;
[0095] When the first subscription data is detected to be empty, the second subscription data is obtained based on the second function and the preset second subscription method;
[0096] When it is detected that the second subscription data is not empty, send the second subscription data and subscription success information to the first object;
[0097] When the second subscription data is detected to be empty, a subscription failure message is sent to the first object.
[0098] Specifically, after determining the second function corresponding to the task information of the first object, it is possible to determine whether the middleware type in the task information is a network type. When the determination result is yes, and the task type is a subscription topic, a preset first subscription method can be passed as parameter information to the second function, and the corresponding first subscription data can be obtained through the second function. The preset first subscription method includes, but is not limited to, shared memory method and network communication method.
[0099] Next, a non-empty check can be performed on the first subscription data, that is, to check whether the first subscription data is empty. When the first subscription data is detected to be not empty, it indicates that the subscription to the topic is successful, and the first subscription data and subscription success information can be sent to the first object; when the first subscription data is detected to be empty, a preset second subscription method can be passed as parameter information to the second function, and the corresponding second subscription data can be obtained through the second function. The preset second subscription method includes, but is not limited to, shared memory method and network communication method, and the preset second subscription method is different from the preset first subscription method.
[0100] Next, a non-empty check can be performed on the second subscription data, that is, to check whether the second subscription data is empty. When the second subscription data is detected to be not empty, it means that the subscription to the topic was successful, and the second subscription data and subscription success information can be sent to the first object; when the second subscription data is detected to be empty, it means that the subscription to the topic failed, and subscription failure information can be sent to the first object.
[0101] It is worth noting that the communication process of the subscription operation can be performed by the mobile terminal, but is not limited to the mobile terminal, and can also be performed by the first object.
[0102] As another optional embodiment of this application, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0103] When the middleware type is identified as network type, the first publishing interface is called based on the second function and the preset first publishing method;
[0104] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0105] If no release status code is received within the preset release time, the second release interface is called based on the second function and the preset second release method;
[0106] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0107] If a publication status code is not received within the preset publication time, a publication failure message is sent to the first object.
[0108] Specifically, after determining the second function corresponding to the task information of the first object, it is possible to determine whether the middleware type in the task information is a network type. If the determination result is yes, and the task type is a publishing topic, a preset first publishing method can be passed as parameter information to the second function, and the corresponding first publishing interface can be called through the second function to realize the communication of the publishing operation. The preset first publishing method includes, but is not limited to, shared memory method and network communication method.
[0109] Next, the system can check whether a publishing status code has been received within a preset publishing time. This status code can be, but is not limited to, a three-digit code generated based on information such as the number of publications in the publishing log, indicating successful publishing, such as 200. If a publishing status code is received within the preset time, it indicates successful topic publishing, and a publishing success message can be sent to the first object. If no publishing status code is received within the preset time, a preset second publishing method can be passed as a parameter to the second function, which then calls the corresponding second publishing interface to achieve communication for the publishing operation. The preset second publishing method includes, but is not limited to, shared memory and network communication methods, and it is different from the preset first publishing method.
[0110] Next, the system can check again within a preset publishing time to see if a publishing status code has been received. If a publishing status code is received within the preset publishing time, it means that the topic has been successfully published, and a publishing success message can be sent to the first object. If no publishing status code is received within the preset publishing time, it means that the topic has failed to be published, and a publishing failure message can be sent to the first object.
[0111] It is worth noting that the communication process for publishing operations can be executed by the terminal, but is not limited to the terminal; it can also be executed by the object.
[0112] Here, when the task type is to create a topic, the topic can be created based on the identity information and topic information in the task information of the first object. The creation method includes, but is not limited to, creating a corresponding record in a preset database, and outputting the creation result based on the number of records or database logs, i.e., creation success information or creation failure information.
[0113] When the task type is querying a topic, the query interface corresponding to the middleware type can be called according to the topic information to query whether there is a record corresponding to the topic information in the corresponding database. If the corresponding record is found within the preset timeout period (e.g., 30s), the query success message will be output; otherwise, the timeout message will be output.
[0114] When the task type is to read a topic, the read interface corresponding to the middleware type can be called according to the topic information, cache address, and cache length to retrieve the record corresponding to the topic information in the corresponding database. The cache address is the location or identifier used to store and access cached data, including but not limited to memory address, disk address, and network address. The cache length is the number or capacity of data items that can be stored in the cache. The way to determine the cache length includes, but is not limited to, depending on the specific caching system and application requirements.
[0115] If the corresponding record is retrieved within the preset timeout period, output the length of the retrieved data and a success message; otherwise, output a timeout message.
[0116] Please see Figure 2 , Figure 2 This paper presents an overall flowchart of another communication method based on a message middleware general interface provided in an embodiment of this application.
[0117] like Figure 2 As shown, at the start of the process, information about the first object is first obtained, including but not limited to identity information, address information, topic information, task type, and middleware type. Next, it needs to determine whether the middleware type is a network type. If the result is yes, the first object is registered, and its heartbeat signal is obtained at preset time intervals. The registration process and heartbeat signal acquisition process can be found in the above embodiments. If the result is no, the first object calls the interface corresponding to the middleware type and task type to perform corresponding subscription and publishing operations, such as calling the subscription interface A1 of type A middleware to subscribe. When the first object decides to stop communicating, it is considered to have exited subscription (subscriber identity) or exited publishing (publisher identity). Then, for the first object that has exited subscription and publishing, it is again determined whether the corresponding middleware type is a network type. If the result is yes, the first object is unregistered, and the acquisition of its heartbeat signal is stopped. The unregistration process and the cessation of heartbeat signal acquisition process can be found in the above embodiments. If the result is no, the process ends.
[0118] Please see Figure 3 , Figure 3 This paper illustrates a block diagram of a communication system based on a message middleware general interface, as provided in an embodiment of this application.
[0119] like Figure 3As shown, the communication system based on the message middleware general interface mainly consists of four parts: instance factory, unified interface layer, middleware heterogeneous encapsulation layer and management center. Among them, the middleware heterogeneous encapsulation layer is composed of multiple heterogeneous message middleware, and the network type message middleware includes two functional modules: shared memory and network communication.
[0120] Specifically, the instance factory can be understood as the part that creates objects. It is mainly used to create instance objects of corresponding message middleware according to various middleware types and transmit the relevant information of the object (including but not limited to identity information and address information) to the terminal.
[0121] The unified interface layer corresponds to a unified unit and mainly consists of abstract interfaces for multiple conventional message middleware, such as abstract interfaces for creating topics, subscribing to topics, and publishing topics. Different abstract interfaces define the communication rules between objects corresponding to different task types to achieve data transmission and function calls between objects.
[0122] The middleware heterogeneous encapsulation layer corresponds to middleware heterogeneous units and mainly consists of abstract interfaces of multiple regular message middleware. This layer is derived from the unified interface layer, meaning that each specific interface in the middleware heterogeneous encapsulation layer corresponds to an abstract interface in the unified interface layer. For example, when there is a subscription interface a1 for middleware of type A in the middleware heterogeneous encapsulation layer, there must be an abstract interface a in the unified interface layer for implementing the subscription topic function.
[0123] It's worth noting that this layer can achieve heterogeneity not only in middleware interfaces but also in operating systems. Heterogeneous middleware interfaces refer to integrating various message middleware with different interfaces, including but not limited to middleware for various network types, as well as middleware for RS485, CAN bus, etc., and providing a unified encapsulated interface for developers to call externally, while allowing developers to freely choose different middleware interfaces internally. Here, considering communication methods such as RS485 and CAN bus, it is applicable to fields such as automotive control and industrial automation. Heterogeneous operating systems define a unified encapsulation of different operating systems on top of the physical runtime environment, such as integrating the different system calls provided by Linux and Windows operating systems to achieve simultaneous support for both operating systems. The integration process of system calls can be referenced from the example of the sleep function: Windows sleep function implementation requires calling the Sleep interface, while Linux sleep function implementation requires calling the usleep interface. Not only are the names of the two interfaces different, but the parameter magnitudes of the interfaces are also different. The former is milliseconds, while the latter is microseconds. If both systems need to be supported at the same time, the system type can be determined first, and then the corresponding implemented specific interface can be called according to the system type. For example, when it is necessary to implement sleep for 100 milliseconds, the Windows system identifier can be checked first. If it exists, Sleep(100) is executed; otherwise, usleep(100000) is executed.
[0124] Furthermore, when the middleware type is network type, the middleware includes at least two corresponding implementation modules for communication methods: a shared memory module and a network communication module. The shared memory module is used to implement communication between two processes on a single machine, while the network communication module is used to implement communication between two processes on different processors (multiple machines).
[0125] Here, the unified interface layer and the middleware heterogeneous encapsulation layer can work together to implement a common interface for message middleware.
[0126] The management center corresponds to a preset management database and is responsible for managing all subscribers and publishers that communicate based on network middleware. It is mainly used to determine whether there are any external subscribers (i.e. subscribers with inconsistent IP address information) and whether the communication method needs to be changed when the number of subscribers or publishers corresponding to a certain topic changes, and to notify the publishers that need to change the communication method.
[0127] Please see Figure 4 , Figure 4 A schematic diagram illustrating the working principle of a management center provided in an embodiment of this application is shown.
[0128] like Figure 4As shown, the management center includes at least two topics and the identity information of the objects corresponding to those topics. The management center can dynamically record the address information (IP addresses) of publishers and subscribers of all network types in real time, and use this information to determine the communication method that each publisher should use, and then notify the corresponding publisher.
[0129] Specifically, in the diagram, publisher 1, subscriber 1, and subscriber 2 of topic 1 are all on processor 1, meaning they share the same IP address. However, publisher 2 is on processor 2 and has a different IP address from the two subscribers. Therefore, publisher 1 can communicate with the two subscribers via shared memory in a single-machine manner, while publisher 2 can communicate with the two subscribers via network communication in a multi-machine manner. Similarly, publisher 3 of topic 2 has subscriber 4 with different IP addresses, and publisher 4 has subscriber 3 with different IP addresses. Therefore, both publisher 3 and publisher 4 use network communication to achieve multi-machine communication.
[0130] Understandably, the existence of the management center allows this application to be compatible with both the efficiency of single-machine communication and the needs of multi-machine communication.
[0131] It is worth noting that all objects corresponding to network middleware (whether publishers or subscribers) must be registered through the management center. This involves sending identity information, topic information, and address information to the management center and generating a corresponding unique identifier (ID). Only by storing all of these identifiers in the management center can the above-mentioned effects be achieved.
[0132] Please see Figure 5 , Figure 5 This illustration shows a schematic diagram of a communication device based on a message middleware general interface provided in an embodiment of this application.
[0133] like Figure 5 As shown, the communication device based on the message middleware general interface may include at least a first processing module 501, a second processing module 502, a third processing module 503, and a fourth processing module 504, wherein:
[0134] The first processing module 501 is used to receive task information of the first object and determine the first function corresponding to the task type in the task information based on the unified unit in the preset first function library; wherein, the first function library includes at least two task types and a first function corresponding to each task type;
[0135] The second processing module 502 is used to determine, based on the middleware heterogeneous unit, a second function corresponding to the middleware type in the task information from the second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type;
[0136] The third processing module 503 is used to obtain the communication method of the first object based on a preset management database when the middleware type is identified as network type.
[0137] The fourth processing module 504 is used to determine the type of the first interface based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface.
[0138] In some possible embodiments, after receiving the task information of the first object and before determining the first function corresponding to the task type in the task information based on the unified unit in a preset first function library, the process includes:
[0139] The first processing module 501 is specifically used for:
[0140] When the middleware type in the task information is identified as network type, the registration information of the first object is sent to the preset management database so that the preset management database can perform registration processing on the first object;
[0141] When a registration success message is received from the preset management database, the heartbeat signal of the first object is obtained at preset time intervals.
[0142] In some possible embodiments, after acquiring the heartbeat signal of the first object at preset time intervals, the process includes:
[0143] The first processing module 501 is specifically used for:
[0144] If the heartbeat signal of the first object is not obtained within at least two time intervals, the unregistration information of the first object is sent to the preset management database, so that the preset management database can perform unregistration processing on the first object based on the unregistration information.
[0145] In some possible embodiments, the communication method of the first object is obtained based on a preset management database, including:
[0146] The third processing module 503 is specifically used for:
[0147] Based on the topic information in the task information, the target topic library corresponding to the topic information is determined in the preset management database;
[0148] Based on the identity information in the task information, the address information of the second object is determined in the target topic library; wherein, the preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information, the target topic library includes at least two types of identity information and address information corresponding to each type of identity information, and the identity information in the task information is inconsistent with the identity information of the second object;
[0149] When the address information in the task information is found to be consistent with the address information of the second object, the shared memory method will be used as the communication method of the first object.
[0150] When the address information in the task information is found to be inconsistent with the address information of the second object, the network communication method is used as the communication method of the first object.
[0151] In some possible embodiments, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the process includes:
[0152] The fourth processing module 504 is specifically used for:
[0153] When it is identified that the middleware type is not a network type, the type of the second interface is determined based on the preset communication method and the second function, and the first object calls the second interface according to the type of the second interface.
[0154] In some possible embodiments, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0155] The fourth processing module 504 is specifically used for:
[0156] When the middleware type is identified as network type, the first subscription data is obtained based on the second function and the preset first subscription method;
[0157] When it is detected that the first subscription data is not empty, send the first subscription data and subscription success information to the first object;
[0158] When the first subscription data is detected to be empty, the second subscription data is obtained based on the second function and the preset second subscription method;
[0159] When it is detected that the second subscription data is not empty, send the second subscription data and subscription success information to the first object;
[0160] When the second subscription data is detected to be empty, a subscription failure message is sent to the first object.
[0161] In some possible embodiments, after determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes:
[0162] The fourth processing module 504 is specifically used for:
[0163] When the middleware type is identified as network type, the first publishing interface is called based on the second function and the preset first publishing method;
[0164] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0165] If no release status code is received within the preset release time, the second release interface is called based on the second function and the preset second release method;
[0166] When a publication status code is received within the preset publication time, a publication success message is sent to the first object;
[0167] If a publication status code is not received within the preset publication time, a publication failure message is sent to the first object.
[0168] Please see Figure 6 , Figure 6 This illustration shows a schematic diagram of another communication device based on a message middleware general interface provided in an embodiment of this application.
[0169] like Figure 6 As shown, the communication device 600 based on the message middleware general interface may include at least one processor 601, at least one network interface 604, user interface 603, memory 605, and at least one communication bus 602.
[0170] The communication bus 602 can be used to realize the connection and communication of the above components.
[0171] The user interface 603 may include buttons, and the optional user interface may also include a standard wired interface or a wireless interface.
[0172] The network interface 604 may include, but is not limited to, Bluetooth modules, NFC modules, Wi-Fi modules, etc.
[0173] The processor 601 may include one or more processing cores. The processor 601 connects to various parts of the communication device 600 based on the message middleware general interface using various interfaces and lines. It executes various functions and processes data of the communication device 600 by running or executing instructions, programs, code sets, or instruction sets stored in memory 605, and by calling data stored in memory 605. Optionally, the processor 601 may be implemented using at least one hardware form of DSP, FPGA, or PLA. The processor 601 may integrate one or more of the following: CPU, GPU, and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 601 and may be implemented as a separate chip.
[0174] The memory 605 may include RAM or ROM. Optionally, the memory 605 may include a non-transitory computer-readable medium. The memory 605 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 605 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 605 may also be at least one storage device located remotely from the aforementioned processor 601. Figure 3 As shown, the memory 605, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a communication application based on a message middleware general interface.
[0175] Specifically, the processor 601 can be used to call a communication application based on a message middleware general interface stored in the memory 605, and specifically perform the following operations:
[0176] The system receives task information from a first object and determines a first function corresponding to the task type in the task information from a preset first function library based on a unified unit; wherein, the first function library includes at least two task types and a first function corresponding to each task type;
[0177] Based on the middleware heterogeneous unit, a second function corresponding to the middleware type in the task information is determined in the second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type;
[0178] When the middleware type is identified as network type, the communication method of the first object is obtained based on the preset management database;
[0179] The type of the first interface is determined based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface.
[0180] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), or any type of medium or device suitable for storing instructions and / or data.
[0181] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0182] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0183] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.
[0184] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0185] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0186] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0187] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0188] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A communication method based on a general interface for message middleware, characterized in that, The method is applied to a general message middleware interface, which includes a unified unit and a heterogeneous middleware unit. The method includes: The system receives task information from a first object and determines, based on the unified unit, a first function corresponding to the task type in the task information from a preset first function library; wherein, the first function library includes at least two task types and a first function corresponding to each task type; Based on the middleware heterogeneous unit, a second function corresponding to the middleware type in the task information is determined in the second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type; When the middleware type is identified as a network type, the communication method of the first object is obtained based on a preset management database; The type of the first interface is determined based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface; After receiving the task information of the first object, and before determining the first function corresponding to the task type in the task information based on the unified unit in a preset first function library, the process includes: When the middleware type in the task information is identified as network type, the registration information of the first object is sent to a preset management database so that the preset management database can perform registration processing on the first object. When the registration success information of the preset management database is received, the heartbeat signal of the first object is obtained at preset time intervals; After acquiring the heartbeat signal of the first object at preset time intervals, the process includes: If the heartbeat signal of the first object is not obtained within at least two time intervals, the unregistration information of the first object is sent to the preset management database, so that the preset management database can perform unregistration processing on the first object according to the unregistration information; The method of obtaining the communication method of the first object based on a preset management database includes: Based on the topic information in the task information, a target topic library corresponding to the topic information is determined in a preset management database; Based on the identity information in the task information, the address information of the second object is determined in the target topic library; The preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information. The target topic library includes at least two types of identity information and address information corresponding to each type of identity information. The identity information in the task information is inconsistent with the identity information of the second object. When the address information in the task information is found to be consistent with the address information of the second object, the shared memory method will be used as the communication method of the first object. When it is found that the address information in the task information is inconsistent with the address information of the second object, the network communication method is used as the communication method of the first object.
2. The method according to claim 1, characterized in that, After determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the process includes: When it is identified that the middleware type is not a network type, the type of the second interface is determined based on the preset communication method and the second function, and the first object calls the second interface according to the type of the second interface.
3. The method according to claim 1, characterized in that, After determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes: When the middleware type is identified as a network type, the first subscription data is obtained based on the second function and the preset first subscription method; When it is detected that the first subscription data is not empty, the first subscription data and subscription success information are sent to the first object; When the first subscription data is detected to be empty, the second subscription data is obtained based on the second function and the preset second subscription method; When it is detected that the second subscription data is not empty, the second subscription data and the subscription success information are sent to the first object; When the second subscription data is detected to be empty, a subscription failure message is sent to the first object.
4. The method according to claim 1, characterized in that, After determining the second function corresponding to the middleware type in the task information from the second function library corresponding to the first function based on the middleware heterogeneous unit, the method further includes: When the middleware type is identified as a network type, the first publishing interface is called based on the second function and the preset first publishing method; When a publication status code is received within the preset publication time, a publication success message is sent to the first object; If the release status code is not received within the preset release time, the second release interface is called based on the second function and the preset second release method; When the publication status code is received within the preset publication time, the publication success message is sent to the first object; If the publication status code is not received within the preset publication time, a publication failure message is sent to the first object.
5. A communication device based on a message middleware universal interface, characterized in that, The device is applied to a message middleware general interface, which includes a unified unit and a middleware heterogeneous unit. The device includes: A first processing module is configured to receive task information of a first object and determine, based on the unified unit, a first function corresponding to the task type in the task information from a preset first function library; wherein, the first function library includes at least two task types and a first function corresponding to each task type; The second processing module is used to determine, based on the middleware heterogeneous unit, a second function corresponding to the middleware type in the task information from a second function library corresponding to the first function; wherein, the second function library includes at least two middleware types and a second function corresponding to each middleware type; The third processing module is used to obtain the communication method of the first object based on a preset management database when the middleware type is identified as a network type. The fourth processing module is used to determine the type of the first interface based on the communication method and the second function, and the first object calls the first interface according to the type of the first interface; After receiving the task information of the first object, and before determining the first function corresponding to the task type in the task information based on the unified unit in a preset first function library, the process includes: When the middleware type in the task information is identified as network type, the registration information of the first object is sent to a preset management database so that the preset management database can perform registration processing on the first object. When the registration success information of the preset management database is received, the heartbeat signal of the first object is obtained at preset time intervals; After acquiring the heartbeat signal of the first object at preset time intervals, the process includes: If the heartbeat signal of the first object is not obtained within at least two time intervals, the unregistration information of the first object is sent to the preset management database, so that the preset management database can perform unregistration processing on the first object according to the unregistration information; The method of obtaining the communication method of the first object based on a preset management database includes: Based on the topic information in the task information, a target topic library corresponding to the topic information is determined in a preset management database; Based on the identity information in the task information, the address information of the second object is determined in the target topic library; The preset management database includes at least two types of topic information and a target topic library corresponding to each type of topic information. The target topic library includes at least two types of identity information and address information corresponding to each type of identity information. The identity information in the task information is inconsistent with the identity information of the second object. When the address information in the task information is found to be consistent with the address information of the second object, the shared memory method will be used as the communication method of the first object. When it is found that the address information in the task information is inconsistent with the address information of the second object, the network communication method is used as the communication method of the first object.
6. A communication device based on a message middleware universal interface, characterized in that, Including the processor and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code stored in the memory to perform the steps of the method as described in any one of claims 1-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer-readable storage medium stores instructions that, when executed on a computer or processor, cause the computer or processor to perform the steps of the method as described in any one of claims 1-4.