Message exchange method and device based on MQTT, protocol gateway and medium

By introducing a message format registration center into the protocol gateway, the message format adaptation problem when the three-dimensional digital twin simulation system interacts with the peripheral system is solved, efficient and convenient communication is achieved, system design is simplified and stability is improved.

CN119155273APending Publication Date: 2024-12-17SHANGHAI MINGCAI DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410812846.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-22
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

When interacting with peripheral systems, a 3D digital twin simulation system needs to be hard-coded to achieve message format adaptation, resulting in bloated logic and inability to cover all peripheral systems in time, resulting in poor communication.

Method used

The message format registration center is introduced in the protocol gateway, query the corresponding message format definition information through the topic, and convert the MQTT request message using the conversion action collection to realize flexible communication between the three-dimensional simulation system and the peripheral system.

Benefits of technology

Efficient and convenient communication between three-dimensional simulation systems and peripheral systems can be achieved without additional coding, which improves communication efficiency and stability and simplifies system design.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119155273A_ABST
    Figure CN119155273A_ABST
Patent Text Reader

Abstract

The invention relates to a message exchange method and device based on MQTT, a protocol gateway and a medium, which are applied to the field of message transmission, and the method comprises the following steps: obtaining an MQTT request message sent by a first device; querying first message format definition information from a message format registration center according to the first theme; if the message format registration center has the first message format definition information, performing format conversion on the MQTT request message by using a conversion action set in the first message format definition information; and sending the converted first message to a target device corresponding to the first theme. The message format registration center is added in the protocol gateway, so that the protocol gateway reads the corresponding message format definition information from the message format registration center according to the subject of the request when the message communication is carried out between the three-dimensional simulation system and the peripheral system, and converts the request message; and communication with a peripheral communication system is performed efficiently and conveniently without writing extra codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of message transmission, and in particular to a message exchange method, device, protocol gateway and medium based on MQTT. Background Art

[0002] The 3D digital twin simulation system plays a vital role in modern industry, smart cities and other fields. It provides accurate data support for decision makers by simulating the operation of the physical world in real time. However, when the 3D digital twin simulation system interacts with many peripheral systems from different manufacturers (such as IoT devices, MQTT servers, IoT platforms, etc.), it often encounters various challenges. These peripheral systems usually use their own unique encoding formats and communication protocols, which requires the 3D digital twin simulation system to have strong message format adaptation capabilities.

[0003] In order to achieve correct communication between the 3D digital twin simulation system and these peripheral systems, developers need to perform a lot of hard coding work in the 3D simulation platform, including building the message format splicing logic of the uplink data to ensure that the data sent can be correctly recognized by the target system; at the same time, it is also necessary to implement the message parsing logic of the downlink data to extract valuable information from the received data. Although this hard coding method can solve the communication problem, it generates a lot of message processing work, and this hard coding method causes the implementation logic of the 3D digital twin simulation scene to be too bloated. With the increase of peripheral systems, there will be a 3D simulation system scene that does not cover all the adaptation logic of the currently supported peripheral systems in a timely manner, resulting in it being able to communicate effectively only with the already adapted peripheral scenes, and those that are not adapted cannot communicate.

[0004] Therefore, providing an efficient and convenient message exchange method between a simulation system and a peripheral system is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention

[0005] The purpose of this application is to provide a message exchange method, device, protocol gateway and medium based on MQTT, which can efficiently and conveniently realize message exchange between a simulation system and a peripheral system.

[0006] In a first aspect, a message exchange method based on MQTT is provided, which is performed by a protocol gateway, and the method includes: Obtain an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; According to the first subject, query first message format definition information from a message format registration center, wherein the message format registration center stores a mapping relationship between subjects and message format definition information, and the message format definition information includes a subject and a collection of conversion actions; If the message format registration center has the first message format definition information, convert the format of the MQTT request message using the conversion action set in the first message format definition information to obtain a converted first message; The converted first message is sent to a destination device corresponding to the first topic.

[0007] Through the above technical scheme, a message format registration center is added to the protocol gateway to facilitate message communication between the three-dimensional simulation system and the peripheral system. The protocol gateway can read the corresponding message format definition information from the message format registration center according to the subject of the request, and use the conversion action collection in the message format definition information to convert the format of the MQTT request message, obtain the converted first message, and send it to the destination device, thereby realizing flexible communication of messages between the three-dimensional simulation system and the periphery, and can communicate with the peripheral communication system efficiently and conveniently without writing additional code.

[0008] In a possible implementation, querying first message format definition information from a message format registration center according to the first topic includes: determining whether the first device is a peripheral system; If the first device is a peripheral system, the first topic is adjusted to a topic corresponding to the first device, and first message format definition information corresponding to the adjusted first topic is searched from a message format registration center according to the adjusted first topic; If the first device is not a peripheral system, first message format definition information corresponding to the first topic is queried from a message format registration center according to the first topic.

[0009] Through the above technical solution, the subject in the message format definition information set in the message format registration center corresponds to the peripheral system. Therefore, if the first device is a peripheral system, the subject needs to be adjusted so that the corresponding first message format definition information can be queried from the message format registration center.

[0010] In a possible implementation, when the conversion action set in the message format definition information includes an uplink conversion action set and a downlink conversion action set, The method of converting the format of the MQTT request message by using the conversion action set in the first message format definition information to obtain the converted first message includes: If the first device is a peripheral system, format conversion is performed on the MQTT request message using the downlink conversion action set in the first message format definition information to obtain a converted first message; If the first device is not a peripheral system, the format of the MQTT request message is converted using the uplink conversion action set in the first message format definition information to obtain a converted first message.

[0011] Through the above technical solution, since the subject in the message format definition information corresponds to the peripheral system, there are two situations: the peripheral system sends a message to the three-dimensional simulation system and the three-dimensional simulation system sends a message to the peripheral system. According to the type of the first device, the corresponding conversion action set can be selected to realize the format conversion of the message.

[0012] In a possible implementation manner, sending the converted first message to a destination device corresponding to the first topic includes: Determine a field type of a target field in the converted first message; the target field is any field in the converted first message; If the field type of the target field is a required field, determining whether the target field is successfully converted; When all required fields in the converted first message are converted successfully, the converted first message is sent to a destination device corresponding to the first topic.

[0013] Through the above technical solution, it is determined whether the data type of each field is a required field type; and the conversion of the required fields is checked. Only after all the required fields are converted successfully, the converted first message is sent to the destination device, ensuring that the destination device can receive a complete and accurate message, thereby improving communication efficiency and stability.

[0014] In a possible implementation manner, after sending the converted first message to a destination device corresponding to the first topic, the method further includes: Obtaining an MQTT feedback message sent by a destination device, wherein the MQTT feedback message includes a second topic and a second message body; querying second message format definition information from a message format registration center according to the second topic; If the message format registration center has the second message format definition information, convert the format of the MQTT feedback message using the second message format definition information to obtain a converted second message; The converted second message is sent to the first device.

[0015] Through the above technical solution, when receiving an MQTT feedback message, the second message format definition information is queried from the message format registration center based on the second topic of the MQTT feedback message, and format conversion and data sending are performed, thereby realizing two-way communication with the first device, so that requests and messages from the first device can be responded to and processed in a timely manner.

[0016] In a possible implementation manner, sending the converted first message to a destination device corresponding to the first topic includes: Determine the target message queue; The converted first message is written into a target message queue, so as to send the converted first message to a destination device corresponding to the first topic through the target message queue.

[0017] Through the above technical solution, by determining the target message queue, the system can accurately select a message queue that best meets the sending requirements, and write the converted first message into the target message queue, which can ensure that the message is processed in an orderly manner during the sending process.

[0018] In a possible implementation, determining the target message queue includes: Predicting the sending completion time corresponding to each of the current multiple message queues; selecting a target message queue with the earliest sending completion time from the multiple message queues according to the sending completion time corresponding to each of the multiple message queues; or, Determine the peripheral system in the destination device and the first device, and determine the target message queue corresponding to the peripheral system in the destination device and the first device according to a preset association relationship, wherein the preset association relationship is a correspondence relationship between multiple peripheral systems and multiple message queues.

[0019] Through the above technical solution, by predicting the corresponding sending completion time of each of the current multiple message queues and selecting the target message queue with the earliest sending completion time, this method fully considers the current state of each message queue and can dynamically select the optimal sending path to ensure the timely transmission of the message. When it is necessary to send a message, the corresponding target message queue can be directly determined based on the peripheral system information in the destination device and the first device. This method simplifies the message sending process, reduces the system's calculation amount, and improves the sending efficiency.

[0020] In a second aspect, a message exchange device based on MQTT is provided, comprising: An acquisition module, used to acquire an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; A query module, used to query first message format definition information from a message format registration center according to the first subject, wherein the message format registration center stores a mapping relationship between subjects and message format definition information, and the message format definition information includes a subject and a set of conversion actions; A conversion module is used to convert the format of the MQTT request message using the conversion action set in the first message format definition information if the message format registration center has the first message format definition information, so as to obtain the converted first message; a sending module is used to send the converted first message to the destination device corresponding to the first topic.

[0021] In a third aspect, a protocol gateway is provided, including: one or more processors; Memory; One or more applications, wherein the one or more applications are stored in a memory and configured to be executed by one or more processors, and the one or more programs are configured to: execute the steps of the method shown in any possible implementation of the first aspect.

[0022] In a fourth aspect, a computer-readable storage medium is provided, wherein the storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, at least one program, a code set or an instruction set is loaded and executed by a processor to implement the method steps shown in any possible implementation method of the first aspect.

[0023] In a fifth aspect, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the steps shown in any possible implementation manner in the first aspect are implemented.

[0024] In summary, the present application includes at least one of the following beneficial technical effects: 1. A message format registration center is added to the protocol gateway to facilitate message communication between the 3D simulation system and the peripheral system. The protocol gateway can read the corresponding message format definition information from the message format registration center according to the subject of the request, and use the conversion action collection in the message format definition information to convert the format of the MQTT request message, obtain the converted first message, and send it to the destination device, thus realizing flexible communication of messages between the 3D simulation system and the peripheral system, and can communicate with the peripheral communication system efficiently and conveniently without writing additional code; 2. Determine whether the data type of each field is a required field type; and verify the conversion of required fields. Only after all required fields are converted successfully, the converted first message is sent to the destination device, ensuring that the destination device can receive a complete and accurate message, thereby improving communication efficiency and stability. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 A schematic diagram of an application scenario of a message exchange method based on MQTT is provided for an embodiment of the present application; Figure 2 It is a flow chart of a message exchange method based on MQTT provided in an embodiment of the present application; Figure 3 A schematic diagram of a process of sending a message from a three-dimensional simulation system to a peripheral system provided in an embodiment of the present application; Figure 4 A schematic diagram of a process of receiving a message from a peripheral system by a three-dimensional simulation system provided in an embodiment of the present application; Figure 5 It is a structural diagram of a protocol gateway provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following is combined with Figure 1 To Attachment Figure 5 This application is described in further detail.

[0027] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, a person skilled in the art may make non-creative modifications to the present embodiment as needed, but such modifications are protected by the patent law as long as they are within the scope of the present application.

[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0029] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.

[0030] In order for the 3D digital twin simulation system to communicate correctly with these peripheral systems, developers need to perform a lot of hard coding work in the 3D simulation platform, including building the message format splicing logic of the uplink data to ensure that the data sent can be correctly recognized by the target system; at the same time, it is also necessary to implement the message parsing logic of the downlink data to extract valuable information from the received data.

[0031] By hard-coding and adapting messages to peripheral systems, the 3D simulation system scene communicates with the peripheral systems that have adapted the message format. If there is no peripheral system that has adapted the message format in the 3D scene, correct communication cannot be performed. As the number of peripheral systems increases, there will be a 3D simulation system scene that cannot timely cover the adaptation logic of all currently supported peripheral systems, resulting in it being able to communicate effectively only with the adapted peripheral scenes, and being unable to communicate with the ones that have not been adapted.

[0032] If universalization is required, the historical assets of the historical 3D simulation scenes must be maintained and upgraded, which will consume a lot of R&D and testing resources and is a heavyweight implementation method. In this implementation method, the conversion action between the 3D simulation system and the target peripheral system is a static binding relationship, which cannot be modified by the outside world.

[0033] Based on this, an embodiment of the present application provides an efficient and convenient message exchange method between a simulation system and a peripheral system.

[0034] For ease of understanding, refer to Figure 1 , Figure 1 An application scenario schematic diagram of a message exchange method based on MQTT (Message Queuing Telemetry Transport) is provided for an embodiment of the present application, including a specific system, a protocol gateway and a peripheral system. In the embodiment of the present application, the specific system takes a three-dimensional simulation system as an example, and the specific system is only a three-dimensional simulation system as an example. In actual applications, the number of specific systems can be multiple.

[0035] In the embodiment of the present application, the communication between the three-dimensional system and the gateway protocol gateway, and the communication between the protocol gateway and the peripheral system are all carried out through the MQTT protocol, and secondary encapsulation can be performed based on the MQTT protocol. Since the three-dimensional simulation system realizes the simulation of hardware, industrial data collection can be simulated in a non-physical state. In this application scenario, each hardware model component in the three-dimensional scene represents the hardware device in the real world, and the function of device data collection can be realized by pushing the device data in the three-dimensional simulation system to the IOT platform system, MQTT gateway, or MQTT server. In some application scenarios, the three-dimensional simulation scene needs to work with the MQTT hardware device to realize the comprehensive application of industry, such as the MQTT hardware device is running a certain specific algorithm, which is an industrial standard algorithm. At this time, the three-dimensional scene and the device need to communicate and work together, and the device communication at this time is also completed through the MQTT protocol. The peripheral system includes but is not limited to: IOT (Internet of Things) platform system, MQTT server, MQTT gateway device and MQTT hardware device.

[0036] The core concept of the embodiment of the present application is to add a message format registration center middleware to the protocol gateway so that when exchanging messages between the three-dimensional simulation system and the periphery, the protocol gateway takes out the message format definition with the subject as the unique identifier from the message format registration center according to the subject of the request, and uses the message format definition to parse and convert the message body of the request, and delivers the parsed and converted message to the target application system. The embodiment of the present application realizes flexible communication of messages between the three-dimensional simulation system and the periphery by providing a design and implementing a message format registration center; by configuring the message format in the message format registration center, it is possible to communicate with any peripheral communication system based on the MQTT protocol without writing additional code, greatly improving the flexibility of the system and the ability to connect to the ecosystem.

[0037] Specifically, the present application embodiment provides a message exchange method based on MQTT, such as Figure 2 As shown, the method provided in the embodiment of the present application can be executed by a protocol gateway, and the method includes: S101. Obtain an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; The first device may be a peripheral system or a three-dimensional simulation system.

[0038] The message of MQTT protocol communication consists of message subject and message request body, see Table 1 for details.

[0039] The first theme is expressed in the form of a unique identifier corresponding to the destination device, which can be set by the user according to actual conditions, and is limited in the embodiments of the present application.

[0040] Table 1 S102, querying first message format definition information from a message format registration center according to the first topic; The message format registration center stores the mapping relationship between topics and message format definition information. The message format definition information includes topics and a collection of conversion actions. The message format registration center is a key-value storage system similar to Key-Value, where the key is the message subject and the value is the message format definition. The message definition registration of the message format registration center is realized by the administrator saving the message format definition to the persistent storage medium through the configuration interface, and can be updated and modified according to needs, such as adding the mapping relationship corresponding to the peripheral system and deleting the mapping relationship corresponding to a peripheral system.

[0041] The present embodiment of the application does not limit the topic setting rules and the setting rules of the conversion action collection in the message format definition information of the message format registration center, as long as the purpose of the present embodiment of the application can be achieved. The conversion action collection includes multiple regular expressions or custom scripts.

[0042] If the first message format definition information can be found, S103 is executed; otherwise, prompt information is generated and sent to the first device for prompting.

[0043] S103: If the message format registration center has the first message format definition information, convert the format of the MQTT request message using the conversion action set in the first message format definition information to obtain a converted first message; The requested message body is format converted according to the order in the conversion action collection in the first message format definition message to obtain a converted message body, and the first subject and the converted message body are combined to obtain a converted first message.

[0044] S104: Send the converted first message to a destination device corresponding to the first topic.

[0045] It can be seen that in the embodiment of the present application, a message format registration center is added to the protocol gateway to facilitate message communication between the three-dimensional simulation system and the peripheral system. The protocol gateway can read the corresponding message format definition information from the message format registration center according to the subject of the request, and use the conversion action collection in the message format definition information to convert the format of the MQTT request message, obtain the converted first message, and send it to the destination device, thereby realizing flexible communication of messages between the three-dimensional simulation system and the periphery, and can communicate with the peripheral communication system efficiently and conveniently without writing additional code.

[0046] Furthermore, in order to ensure the reliability of the message, it can also be determined that the converted first message can also be verified to be legal, and it can be sent to the destination device only after the verification is passed. Specifically, the converted first message is sent to the destination device corresponding to the first topic, including: determining the field type of the target field in the converted first message; the target field is any field in the converted first message; if the field type of the target field is a required field, determining whether the target field is converted successfully; when all required fields in the converted first message are converted successfully, sending the converted first message to the destination device corresponding to the first topic.

[0047] It should be noted that the data type of each field and whether it is a required field type will be identified in the message format definition; if it is a required field type but the conversion is unsuccessful, the verification result is illegal, and the illegal request processing operation is performed, and the request processing ends. Since the message body is converted according to the regular expression or custom script in the conversion action collection during conversion, each conversion rule has a unique input and output. The output of the conversion performed according to the input is either successful or failed. The output exists in two forms: empty and valid data. Therefore, when verifying whether the conversion is successful, you only need to determine whether the conversion result corresponding to the field is empty. If it is empty, it means that the conversion failed.

[0048] It can be seen that in the embodiment of the present application, it is determined whether the data type of each field is a required field type; and the conversion of the required fields is checked. Only after all the required fields are converted successfully, the converted first message is sent to the destination device, ensuring that the destination device can receive a complete and accurate message, thereby improving communication efficiency and stability.

[0049] There may be many forms for the format defined by the message format. An embodiment of the present application provides a format defined by the message format, as shown in Table 2.

[0050] Table 2 The message topic corresponds to the topic of the peripheral system. The specific conversion logic is set in the conversion action list. The conversion rule is responsible for converting the request topic sent by the peripheral system into the topic of the three-dimensional simulation system, and determining that the current operation is a downlink operation, and selecting the downlink conversion action collection to convert the message body.

[0051] Specifically, querying the first message format definition information from the message format registration center according to the first topic includes: determining whether the first device is a peripheral system; If the first device is a peripheral system, the first topic is adjusted to a topic corresponding to the first device, and first message format definition information corresponding to the adjusted first topic is queried from a message format registration center according to the adjusted first topic; If the first device is not a peripheral system, first message format definition information corresponding to the first topic is queried from a message format registration center according to the first topic.

[0052] Accordingly, when the conversion action set in the message format definition information includes an uplink conversion action set and a downlink conversion action set, The MQTT request message is format converted using the conversion action set in the first message format definition information to obtain a converted first message, including: If the first device is a peripheral system, the MQTT request message is format converted using the downlink conversion action set in the first message format definition information to obtain a converted first message; If the first device is not a peripheral system, the MQTT request message is format-converted using the uplink conversion action set in the first message format definition information to obtain a converted first message.

[0053] It should be noted that, after the first device sends the request, the destination device will respond to the request. Specifically, a possible implementation of the embodiment of the present application, after sending the converted first message to the destination device corresponding to the first topic, further includes: Obtaining an MQTT feedback message sent by a destination device, where the MQTT feedback message includes a second topic and a second message body; Query the second message format definition information from the message format registration center according to the second topic; If the message format registration center has the second message format definition information, the second message format definition information is used to perform format conversion on the MQTT feedback message to obtain a converted second message; The converted second message is sent to the first device.

[0054] For the message format definition shown in Table 2, in an embodiment of the present application, the second message subject corresponds to the first device, and when the first device is not a peripheral system, it is necessary to convert the subject, and select a collection of downlink conversion actions for format conversion; when the first device is a peripheral system, it is not necessary to convert the subject, and directly select the second message format definition information corresponding to the second subject from the message format registration center. At this time, the second message format definition information is the same as the first message format definition information, and the collection of uplink conversion actions is selected for format conversion.

[0055] The embodiment of the present application provides another message format definition format, as shown in Table 3.

[0056] Table 3 Among them, the message topic is the topic corresponding to the destination device, and the message format registration center is provided with a corresponding service for each device. Therefore, after obtaining the MQTT request message sent by the first device, the service corresponding to the first device is read, and the message format definitions of all devices that the first device can send are maintained in the service, so as to determine the message format definition corresponding to the message topic from the service. For example, the service of the three-dimensional simulation system includes: the message format definition information corresponding to the IOT platform system, the message format definition information corresponding to the MQTT server, the message format definition information corresponding to the MQTT gateway device, and the message format definition information corresponding to the MQTT hardware device; the service of the IOT platform system includes: the message format definition information corresponding to the service of the three-dimensional simulation system; the service of the MQTT server includes: the message format definition information corresponding to the service of the three-dimensional simulation system; the service of the MQTT gateway device includes: the message format definition information corresponding to the service of the three-dimensional simulation system; the service of the MQTT hardware device includes: the message format definition information corresponding to the service of the three-dimensional simulation system.

[0057] Alternatively, distinguish the message topics when the IOT platform system, MQTT server, MQTT gateway device and MQTT hardware device send messages to the three-dimensional simulation system, for example, the first topic of the MQTT request message sent by the IOT platform system is the three-dimensional simulation system identifier-1, the first topic of the MQTT request message sent by the MQTT server is the three-dimensional simulation system identifier-2, the first topic of the MQTT request message sent by the MQTT gateway device is the three-dimensional simulation system identifier-3, and the first topic of the MQTT request message sent by the MQTT hardware device is the three-dimensional simulation system identifier-4.

[0058] Of course, there may be other forms, which are not limited by the embodiments of the present application, as long as they can achieve the purpose of the embodiments of the present application.

[0059] It should be noted that, after the first device sends the request, the destination device will respond to the request. Specifically, a possible implementation of the embodiment of the present application, after sending the converted first message to the destination device corresponding to the first topic, further includes: Obtaining an MQTT feedback message sent by a destination device, where the MQTT feedback message includes a second topic and a second message body; Query the second message format definition information from the message format registration center according to the second topic; If the message format registration center has the second message format definition information, the second message format definition information is used to perform format conversion on the MQTT feedback message to obtain a converted second message; The converted second message is sent to the first device.

[0060] It should be noted that if different peripheral systems correspond to different services, the second topic corresponds to the first device. Although the second topic is the same, the destination device is different, the selected service is also different, and the second message format definition information is also different. If the three-dimensional simulation system identifier is marked and distinguished, the second topic is different, and the second message format definition information is also different.

[0061] Based on any of the above embodiments, the present application embodiment provides a process for a three-dimensional simulation system to send a message to a peripheral system, specifically referring to Figure 3 , Figure 3 A schematic diagram of a process of sending a message from a three-dimensional simulation system to a peripheral system provided in an embodiment of the present application: 1.1 The 3D simulation system sends an MQTT request message to the protocol gateway. Each message consists of: subject + message body; 1.2 After the protocol gateway receives the request message from the 3D simulation system, it parses the message and queries the message format definition information from the message format registration center according to the subject of the request; if the message format definition does not exist, it is determined to be an illegal request and the request processing ends; if the message format definition exists, the message body of the request is verified according to the message format definition (the data type of each field is identified in the message format definition, and whether the field type is required. If it is a required field, the conversion is successful, and the verification is successful). If the verification is illegal, the request processing ends; if the verification result is legal, the next processing process is entered; 1.3 The protocol gateway sends the processed message to the target peripheral system; 1.4 The target peripheral system returns the processing result to the protocol gateway (since the MQTT protocol is a communication protocol based on the publish / subscribe mode, the result return process is asynchronous); 1.5 The protocol gateway returns the processing results of the peripheral system to the 3D simulation system (since the MQTT protocol is a communication protocol based on the publish / subscribe model, the result return process is asynchronous).

[0062] The processing results may be different depending on the request sent and the destination device.

[0063] Take sending telemetry data as an example: the possible format of peripheral system A is: request topic: request telemetry topic; request body: device id + telemetry data set. The message format of peripheral system B may be: request topic: request telemetry topic\device id\; request body: telemetry data set. If the 3D simulation system makes an RPC request to the IOT platform system, the request body and the return message are completely defined by the specific IOT platform system. There are roughly three elements: request topic, request message body, and returned result message. These three parts are determined by the platform and business logic, that is, they all change according to the platform and business logic.

[0064] Specific reference Figure 4 , Figure 4 A schematic diagram of a process of receiving a message from a peripheral system by a three-dimensional simulation system provided in an embodiment of the present application: 2.1 The peripheral system sends an MQTT request message to the protocol gateway. Each message consists of: topic + message body; 2.2 After receiving the request message from the peripheral system, the protocol gateway queries the message format definition information from the message format registration center according to the subject of the request; if the message format definition exists, the message body of the request is verified according to the message format definition. If the verification result is illegal, the request processing ends; if the verification result is legal, the next processing process is entered; 2.3 The protocol gateway sends the processed message to the 3D simulation system; 2.4 The 3D simulation system returns the processing results to the protocol gateway (since the MQTT protocol is a communication protocol based on the publish / subscribe mode, the result return process is asynchronous); 2.5 The protocol gateway returns the processing results of the 3D simulation system to the peripheral system (since the MQTT protocol is a communication protocol based on the publish / subscribe model, the result return process is asynchronous).

[0065] In a possible implementation of the embodiment of the present application, S104 sends the converted first message to a destination device corresponding to the first topic, including: S1041-S1042 (not shown in the drawings), wherein: S1041, determining a target message queue; Multiple queues are pre-set for message processing to achieve load balancing and ensure that messages can be sent quickly and efficiently.

[0066] A message queue is a temporary storage area for storing messages to be sent. It is usually used to establish a buffer between the sender and the receiver to achieve asynchronous sending and receiving of messages.

[0067] When executing the step of sending the converted first message to the destination device corresponding to the first topic, a target message queue needs to be determined first. This step is to find or create a suitable message queue so that the converted first message can be written into it later. Once the target message queue is determined, the converted first message will be written into the queue. Subsequently, the target message queue will be responsible for delivering the message from the sender to the receiver, that is, the destination device corresponding to the first topic. This method of message delivery through message queues can ensure reliable transmission and sequential processing of messages, while also improving the scalability and fault tolerance of the system.

[0068] In one achievable manner, the sending completion time corresponding to each of the current multiple message queues is predicted; according to the sending completion time corresponding to each of the multiple message queues, a target message queue with the earliest sending completion time is selected from the multiple message queues; Specifically, the sending completion time refers to the time point when all messages currently in the message queue are expected to be successfully sent and arrive at the receiving end.

[0069] In some embodiments, the prediction and selection process can be implemented in a variety of ways: Optionally, the current status information of each message queue is collected, including queue length, message size, type, etc., as well as real-time network status information, such as bandwidth, delay, packet loss rate, etc.; this information is used to predict the sending completion time of each queue using the machine model. The training process of the machine model includes collecting and storing the historical sending data of each queue, such as queue length, message size, type, network status information and message sending time, and inputting the historical sending data into the machine model (such as a regression model) for training to obtain a trained machine model.

[0070] Optionally, the system can also predict the sending completion time based on simple rules or heuristic methods. For example, the sending completion time can be estimated based on the queue length and the average message sending rate.

[0071] It is understandable that other methods may be used to implement the prediction and selection process, such as using more complex prediction models or algorithms, or formulating selection strategies based on specific business logic and rules, which are not limited here.

[0072] It can be seen that in the embodiment of the present application, by predicting the sending completion time corresponding to each of the current multiple message queues and selecting the target message queue with the earliest sending completion time, this method fully considers the current status of each message queue, and can dynamically select the optimal sending path to ensure the timely transmission of messages.

[0073] In another achievable manner, the peripheral systems in the destination device and the first device are determined, and the target message queues corresponding to the peripheral systems in the destination device and the first device are determined according to a preset association relationship, wherein the preset association relationship is a correspondence between multiple peripheral systems and multiple message queues.

[0074] Specifically, the preset association relationship refers to the correspondence between multiple peripheral systems and multiple message queues that are defined in advance. This association relationship is established based on the device. Through this association relationship, it is possible to know which message queue should be used to store and send these messages when a peripheral system needs to send a message. After determining the target message queue, the message to be sent can be placed in the queue and wait for subsequent sending processing. In this way, the system can ensure that the message can be accurately sent to the peripheral system of the target device while ensuring the orderliness and reliability of the message. It can be seen that in an embodiment of the present application, when a message needs to be sent, the corresponding target message queue can be directly determined based on the peripheral system information in the destination device and the first device. This method simplifies the message sending process, reduces the system's calculation amount, and improves the sending efficiency.

[0075] S1042: Write the converted first message into a target message queue, so as to send the converted first message to a destination device corresponding to the first topic through the target message queue.

[0076] It can be seen that in the embodiment of the present application, by determining the target message queue, the system can accurately select a message queue that best meets the sending requirements, and write the converted first message into the target message queue, which can ensure that the message is processed in an orderly manner during the sending process.

[0077] Furthermore, when a new legitimate peripheral system joins, it is necessary to call the registration interface of the registration center to register the device and update the message format registration center. Moreover, after the new device is successfully registered, it will periodically send heartbeat information to the registration center to indicate that the device is online.

[0078] Furthermore, when there is sensitive data in the MQTT request message or the MQTT feedback message, it can be automatically encrypted and sent, and the sensitivity strength of the sensitive data can be set, with different encryption levels set for different strengths.

[0079] Furthermore, when a conversion fails, such as a temporary network outage or service restart, the operation is simply retried with a fixed interval between each retry, or the interval between each retry increases according to an exponential function, or the interval between each retry is random.

[0080] In the above embodiment, a method is introduced from the perspective of method flow, and the following embodiment introduces a device from the perspective of a module or unit. For details, please refer to the following embodiment.

[0081] The embodiment of the present application provides a message exchange device based on MQTT, including: An acquisition module, used to acquire an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; A query module, used to query first message format definition information from a message format registration center according to the first subject, wherein the message format registration center stores a mapping relationship between subjects and message format definition information, and the message format definition information includes a subject and a set of conversion actions; A conversion module, configured to convert the format of the MQTT request message using the conversion action set in the first message format definition information if the message format registration center has the first message format definition information, so as to obtain a converted first message; The sending module is used to send the converted first message to a destination device corresponding to the first topic.

[0082] In an achievable embodiment, the query module queries the first message format definition information from the message format registration center according to the first topic, for: determining whether the first device is a peripheral system; If the first device is a peripheral system, the first topic is adjusted to a topic corresponding to the first device, and first message format definition information corresponding to the adjusted first topic is queried from a message format registration center according to the adjusted first topic; If the first device is not a peripheral system, first message format definition information corresponding to the first topic is queried from a message format registration center according to the first topic.

[0083] In an implementable embodiment, when the conversion action collection in the message format definition information includes an uplink conversion action collection and a downlink conversion action collection, the conversion module uses the conversion action collection in the first message format definition information to perform format conversion on the MQTT request message to obtain a converted first message, which is used to: If the first device is a peripheral system, the MQTT request message is format converted using the downlink conversion action set in the first message format definition information to obtain a converted first message; If the first device is not a peripheral system, the MQTT request message is format-converted using the uplink conversion action set in the first message format definition information to obtain a converted first message.

[0084] In an achievable embodiment, the sending module sends the converted first message to a destination device corresponding to the first topic, and is used to: Determine the field type of a target field in the converted first message; the target field is any field in the converted first message; If the field type of the target field is a required field, determine whether the target field is converted successfully; When all required fields in the converted first message are converted successfully, the converted first message is sent to a destination device corresponding to the first topic.

[0085] In an achievable embodiment, it further includes: A feedback module, used to obtain an MQTT feedback message sent by a destination device, where the MQTT feedback message includes a second topic and a second message body; Query the second message format definition information from the message format registration center according to the second topic; If the message format registration center has the second message format definition information, the second message format definition information is used to perform format conversion on the MQTT feedback message to obtain a converted second message; The converted second message is sent to the first device.

[0086] In an achievable embodiment, the sending module sends the converted first message to a destination device corresponding to the first topic, and is used to: Determine the target message queue; The converted first message is written into a target message queue, so as to send the converted first message to a destination device corresponding to the first topic through the target message queue.

[0087] In an achievable embodiment, the sending module determines the target message queue, and is used to: Predicting the sending completion time corresponding to each of the current multiple message queues; selecting a target message queue with the earliest sending completion time from the multiple message queues according to the sending completion time corresponding to each of the multiple message queues; or, Determine the peripheral system in the destination device and the first device, and determine the target message queue corresponding to the peripheral system in the destination device and the first device according to a preset association relationship, wherein the preset association relationship is a correspondence relationship between multiple peripheral systems and multiple message queues.

[0088] A device provided in an embodiment of the present application is applicable to the above method embodiment, which will not be described in detail here.

[0089] In the embodiment of the present application, a protocol gateway is provided, such as Figure 5 As shown, Figure 5 The protocol gateway 300 shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the protocol gateway 300 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the protocol gateway 300 does not constitute a limitation on the embodiments of the present application.

[0090] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0091] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0092] The memory 303 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.

[0093] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.

[0094] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment.

[0095] An embodiment of the present application provides a computer program product, including a computer program, which implements the corresponding contents of the aforementioned method embodiment when executed by a processor.

[0096] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0097] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A message exchange method based on MQTT, characterized in that: Executed by a protocol gateway, the method includes: Obtain an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; According to the first subject, query first message format definition information from a message format registration center, wherein the message format registration center stores a mapping relationship between subjects and message format definition information, and the message format definition information includes a subject and a collection of conversion actions; If the message format registration center has the first message format definition information, convert the format of the MQTT request message using the conversion action set in the first message format definition information to obtain a converted first message; The converted first message is sent to a destination device corresponding to the first topic.

2. The method according to claim 1, characterized in that The querying first message format definition information from a message format registration center according to the first topic includes: determining whether the first device is a peripheral system; If the first device is a peripheral system, the first topic is adjusted to a topic corresponding to the first device, and first message format definition information corresponding to the adjusted first topic is searched from a message format registration center according to the adjusted first topic; If the first device is not a peripheral system, first message format definition information corresponding to the first topic is queried from a message format registration center according to the first topic.

3. The method according to claim 2, characterized in that When the conversion action set in the message format definition information includes an uplink conversion action set and a downlink conversion action set, The method of converting the format of the MQTT request message by using the conversion action set in the first message format definition information to obtain the converted first message includes: If the first device is a peripheral system, format conversion is performed on the MQTT request message using the downlink conversion action set in the first message format definition information to obtain a converted first message; If the first device is not a peripheral system, the format of the MQTT request message is converted using the uplink conversion action set in the first message format definition information to obtain a converted first message.

4. The method according to claim 1, characterized in that: The sending the converted first message to a destination device corresponding to the first topic includes: Determine a field type of a target field in the converted first message; the target field is any field in the converted first message; If the field type of the target field is a required field, determining whether the target field is successfully converted; When all required fields in the converted first message are converted successfully, the converted first message is sent to a destination device corresponding to the first topic.

5. The method according to claim 1, characterized in that After sending the converted first message to the destination device corresponding to the first topic, the method further includes: Obtaining an MQTT feedback message sent by a destination device, wherein the MQTT feedback message includes a second topic and a second message body; querying second message format definition information from a message format registration center according to the second topic; If the message format registration center has the second message format definition information, the second message format definition information is used to perform format conversion on the MQTT feedback message to obtain a converted second message; The converted second message is sent to the first device.

6. The method according to claim 1, characterized in that The sending the converted first message to a destination device corresponding to the first topic includes: Determine the target message queue; The converted first message is written into a target message queue, so as to send the converted first message to a destination device corresponding to the first topic through the target message queue.

7. The method according to claim 6, characterized in that The determining of the target message queue comprises: Predicting the sending completion time corresponding to each of the current multiple message queues; selecting a target message queue with the earliest sending completion time from the multiple message queues according to the sending completion time corresponding to each of the multiple message queues; or, Determine the peripheral system in the destination device and the first device, and determine the target message queue corresponding to the peripheral system in the destination device and the first device according to a preset association relationship, wherein the preset association relationship is a correspondence relationship between multiple peripheral systems and multiple message queues.

8. A message exchange device based on MQTT, characterized in that: include: An acquisition module, used to acquire an MQTT request message sent by a first device, where the MQTT request message includes a first topic and a first message body, where the first topic is used to indicate a destination device; A query module, used to query first message format definition information from a message format registration center according to the first subject, wherein the message format registration center stores a mapping relationship between subjects and message format definition information, and the message format definition information includes a subject and a set of conversion actions; A conversion module, configured to convert the format of the MQTT request message using the conversion action set in the first message format definition information to obtain a converted first message if the message format registration center has the first message format definition information; A sending module is used to send the converted first message to a destination device corresponding to the first topic.

9. A protocol gateway, characterized in that: It includes: one or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to: perform the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the steps of the method described in any one of claims 1 to 7.