CN117793187A - Inter-process communication method of MQTT communication proxy - Google Patents

Inter-process communication method of MQTT communication proxy Download PDF

Info

Publication number
CN117793187A
CN117793187A CN202311834313.2A CN202311834313A CN117793187A CN 117793187 A CN117793187 A CN 117793187A CN 202311834313 A CN202311834313 A CN 202311834313A CN 117793187 A CN117793187 A CN 117793187A
Authority
CN
China
Prior art keywords
mqtt
proxy
inter
communication
business
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311834313.2A
Other languages
Chinese (zh)
Inventor
鲍建
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Magna Wuhan Technology Co ltd
Original Assignee
Magna Wuhan Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Magna Wuhan Technology Co ltd filed Critical Magna Wuhan Technology Co ltd
Priority to CN202311834313.2A priority Critical patent/CN117793187A/en
Publication of CN117793187A publication Critical patent/CN117793187A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The application relates to the technical field of network communication, in particular to an inter-process communication method of an MQTT communication proxy, which comprises the following steps: the agent process integrated MQTT client communicates with the MQTT server according to an MQTT protocol; the agent process and a plurality of business processes integrate an inter-process communication library of a release subscription model so as to carry out inter-process communication; the proxy process and the business process are all operated in the MQTT client; the proxy process subscribes to a fixed proxy theme and publishes inter-process communication information to the business process by using the fixed business theme; the business process subscribes to a fixed business theme and publishes inter-process communication information to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication. The scheme adopts a fixed theme, and even if a business process is newly added, the proxy process is not directly influenced.

Description

Inter-process communication method of MQTT communication proxy
Technical Field
The application relates to the technical field of network communication, in particular to an inter-process communication method of an MQTT communication proxy.
Background
MQTT (message queue telemetry transport) is a publish/subscribe paradigm-based message protocol under the ISO standard (ISO/IEC PRF 20922), which is a client-server based message publish/subscribe transport protocol, each message consisting of a topic and a payload.
At present, the MQTT is widely applied to the vehicle-mounted field, in the vehicle-mounted field, each vehicle is equivalent to a client, a target vehicle can be in communication connection with a server through a transmission network (such as a wireless communication network), the tasks of subscribing the theme and publishing the message are realized based on the MQTT, and the message matched with the subscribing theme is received; that is, clients on a plurality of different devices can be connected to the same server by respective client identifiers at the same time, and the clients can subscribe to the topic and publish messages and receive messages matched with the subscribed topic and issued by the server. In an embedded system adopting a multi-process architecture, proxy processes and business processes are all operated in clients on an automobile, and in order to enable a plurality of business processes to send and receive messages through one MQTT client, one proxy process is required to be set to be responsible for the connection between the MQTT client and an MQTT server, and other business processes and the proxy processes indirectly send and receive MQTT communication messages in an inter-process communication mode.
However, in the above scheme, since each service process may be associated with a different communication theme, the proxy process needs to continuously increase processing on a new theme, which directly affects the processing efficiency of the proxy process.
Disclosure of Invention
In view of this, the embodiment of the application provides an inter-process communication method of an MQTT communication proxy, which adopts a fixed theme and does not directly affect the proxy process even if a service process is newly added.
In a first aspect, the present application provides an inter-process communication method of an MQTT communication proxy, where the method includes:
the agent process integrated MQTT client communicates with the MQTT server according to an MQTT protocol; the proxy process and a plurality of business processes integrate an inter-process communication library of the publishing and subscribing model so as to perform inter-process communication; the proxy process and the service process are both operated in the MQTT client;
the proxy process subscribes to a fixed proxy theme and publishes inter-process communication information to the business process by using the fixed business theme;
the business process subscribes to a fixed business theme and issues an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
According to the technical means, the proxy process subscribes to the fixed proxy theme, the business process subscribes to the fixed business theme, and the proxy process is not directly affected even if the business process is newly added by adopting the fixed theme; and the inter-process communication between the proxy process and the service process belongs to one-to-many communication, so that the proxy process can keep the connection with the MQTT server as long as the service process needs to send and receive the MQTT communication message, and the stability of communication connection is ensured.
With reference to the first aspect, in one implementation manner, the inter-process communication message includes a message header and a message body;
the message header comprises a message function identifier and a publisher identifier; the message body is arranged by one or more integer data and character string data according to the different message function identifiers.
According to the technical means, the inter-process communication message defines a plurality of messages in a structured data format, and the release of the inter-process communication message realizes the indirect transmission and reception of the MQTT communication message through the proxy process.
With reference to the first aspect, in one implementation manner, the proxy process and the service process both store connection state information of the MQTT;
the proxy process periodically issues inter-process communication information of the connection state;
after receiving the connection state issued by the proxy process, the business process issues an inter-process communication message of an MQTT connection request or an MQTT disconnection request when the connection state of the proxy process is inconsistent with the connection state stored by the business process;
after receiving the MQTT connection request or the MQTT disconnection request, the proxy process sets or clears the bit identification of the business process corresponding to the information of the information publisher according to the information of the information publisher;
the proxy process initiates an MQTT connection request at all service processes, or initiates communication connection with the MQTT server after exceeding a first preset time;
and when no business process initiates an MQTT connection request, the proxy process disconnects the MQTT server.
According to the technical means, the agent process and the service process can reestablish inter-process communication under the conditions of different starting sequences or restarting after process breakdown and the like; and the proxy process sends periodic connection state notification to the service process, so that the connection state can be re-established after the two processes die and restart, and the proxy process initiates connection with the MQTT server after the service process is ready, thereby avoiding the condition that the offline message received when the connection is successful is not processed by people.
With reference to the first aspect, in one implementation manner, in an MQTT connected state, the service process issues an inter-process communication message of an MQTT issue request;
after receiving the MQTT release request, the proxy process sends the MQTT release request to the MQTT server, acquires a release TOKEN TOKEN and sends an inter-process communication message of the MQTT release confirmation;
after receiving the MQTT release confirmation, the business process waits for the inter-process communication message released by the MQTT according to the release TOKEN;
after receiving the published message of the MQTT published by the MQTT server, the proxy process obtains the published TOKEN and distributes the published inter-process communication message of the MQTT;
after receiving the inter-process communication message issued by the MQTT, the business process confirms that the issuing is completed according to the issued TOKEN;
and if the business process does not receive the MQTT release confirmation and the communication message released by the MQTT in the second preset time, the release is considered to be failed.
According to the technical means, in the application, if a plurality of business processes are respectively publishing the messages, the proxy process can respectively confirm the publishing condition of the messages by a mechanism of publishing confirmation, published messages and message TOKEN, so that the message publishing accuracy and efficiency are improved.
With reference to the first aspect, in one implementation manner, the proxy process and the service process both store MQTT subscription request tables, and the proxy process further stores MQTT subscribed topic tables; and before the proxy process starts the MQTT connection for the first time or restarts the MQTT connection, the MQTT subscribed topic table and the MQTT subscription request table in the proxy process are emptied.
With reference to the first aspect, in one implementation manner, when the MQTT connection state of the service process changes, the service process issues an inter-process communication message of the MQTT subscription request;
after receiving the MQTT subscription request, the proxy process adds the subscription topic of the MQTT subscription request to the MQTT subscription request table if the subscription topic of the MQTT subscription request to be subscribed is not in the MQTT subscribed topic table;
and the proxy process sequentially takes out the subscription topics of the MQTT subscription request table, sends a subscription request to an MQTT server, and adds the subscription topics to the MQTT subscribed topic table after successful subscription.
In combination with the first aspect, in one implementation manner, after the subscription of the MQTT subscription request issued by the service process is successful, when the MQTT server receives the new information of the subscription topic, an MQTT received message is issued;
after receiving the message received by the MQTT published by the MQTT server, the proxy process publishes the received inter-process communication message of the MQTT;
after receiving the inter-process communication message received by the MQTT, the business process matches the MQTT subscription request table stored by the business process according to the subscription theme, and confirms that the MQTT message is received.
According to the technical means, in the application, when a plurality of business processes subscribe to topics respectively, the proxy process can ensure that the same topics cannot be subscribed repeatedly through the subscription request table and the subscribed topic table; the method and the device are constructed on the basis of subscribing and publishing inter-process communication models, and the number of business processes can be increased as required without influencing the proxy process; in addition, in the application, the proxy process needs to combine and process the MQTT topic subscription request sent by the service process, and only one subscription request can be initiated for a specific MQTT topic within the connection period with the MQTT server.
In a second aspect, the present application provides an inter-process communication system of an MQTT communication proxy, for performing an inter-process communication method of an MQTT communication proxy as set forth above;
the system comprises an MQTT client and an MQTT server; the MQTT client is internally operated with an agent process and a plurality of business processes;
the proxy process is used for integrating the MQTT client and the MQTT server to communicate according to the MQTT protocol; the proxy process and the business process also integrate an inter-process communication library of the publishing and subscribing model so as to carry out inter-process communication;
the proxy process is also used for subscribing a fixed proxy theme and publishing an inter-process communication message to the business process by using the fixed business theme;
the business process is also used for subscribing a fixed business theme and publishing an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
In a third aspect, the present application provides a computer device comprising a processor and a memory having at least one instruction stored therein, the at least one instruction being loaded and executed by the processor to implement an inter-process communication method of an MQTT communication proxy as described above.
In a fourth aspect, the present application provides a computer readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement an inter-process communication method of an MQTT communication proxy as described above.
The technical scheme that this application provided can include following beneficial effect:
in the scheme, the proxy process subscribes to the fixed proxy theme, the business process subscribes to the fixed business theme, and the number of the business processes can be increased as required by adopting the fixed theme without influencing the proxy process;
the inter-process communication of the proxy process and the service process belongs to one-to-many communication, and as long as the service process needs to send and receive the MQTT communication message, the proxy process can keep the connection with the MQTT server, so that the stability of communication connection is ensured;
based on the inter-process communication information of the connection state, the proxy process and the service process can reestablish inter-process communication under the conditions of different starting sequences or restarting after the process crashes and the like; and the proxy process sends periodic connection state notification to the service process, so that the connection state can be re-established after the two processes die and restart, and the proxy process initiates connection with the MQTT server after the service process is ready, thereby avoiding the condition that the offline message received when the connection is successful is not processed by people. In addition, if the plurality of business processes are respectively publishing the messages, the proxy process can respectively confirm the publishing condition of the messages by a mechanism of publishing confirmation, published messages and message TOKEN, so that the message publishing accuracy and efficiency are improved;
when a plurality of business processes subscribe topics respectively, the proxy process can ensure that the same topic is not subscribed repeatedly through the subscription request table and the subscribed topic table; and, the proxy process can combine and process the MQTT topic subscription request sent by the service process based on the subscribed topic table, and only initiates a subscription request for a specific MQTT topic within the connection period with the MQTT server.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of an interprocess communication system of an MQTT communication proxy shown according to an exemplary embodiment.
FIG. 2 is a method flow diagram illustrating a method of interprocess communication for an MQTT communication proxy according to an exemplary embodiment.
FIG. 3 is a method flow diagram illustrating a method of interprocess communication for an MQTT communication proxy according to an exemplary embodiment.
Fig. 4 shows a block diagram of a computer device according to an exemplary embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made apparent and fully in view of the accompanying drawings, in which some, but not all embodiments of the invention are shown. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
FIG. 1 is a schematic diagram of an interprocess communication system of an MQTT communication proxy shown according to an exemplary embodiment. The system is used for executing an inter-process communication method of the MQTT communication proxy as follows;
as shown in fig. 1, the system includes an MQTT client 120 and an MQTT server 110; the MQTT client 120 has a proxy process and a plurality of business processes running therein;
the proxy process is used for integrating the MQTT client 120 and the MQTT server 110 to communicate according to the MQTT protocol; the proxy process and the business process also integrate an inter-process communication library of the publishing and subscribing model so as to carry out inter-process communication;
the proxy process is also used for subscribing a fixed proxy theme and publishing an inter-process communication message to the business process by using the fixed business theme;
the business process is also used for subscribing a fixed business theme and publishing an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
Further, in the vehicle-mounted field, the MQTT client 120 in the embodiment of the present application may be a vehicle-mounted client, where the MQTT client 120 and the MQTT server 110 implement subscription of a theme and release of a message through an MQTT transmission protocol, and the MQTT is a transmission protocol based on message release and subscription of a client-server, where each message is composed of a theme and a load, and in an actual application scenario, the number of the MQTT clients 120 is greater, and the MQTT client 120 as a vehicle-mounted client may subscribe to the MQTT server 110 for the theme and release the message based on the MQTT transmission protocol, and receive the message released by the MQTT server 110 and matched with the subscribed theme.
Further, in an embedded system adopting a multi-process architecture, in order for the multiple business processes to send and receive messages through one MQTT client 120, a proxy process needs to be set to be responsible for the connection between the MQTT client 120 and the MQTT server 110, and other business processes and the proxy process send and receive MQTT communication messages indirectly through an inter-process communication mode.
Further, the proxy process acts as a data transfer station that receives messages from publishers and forwards those messages to subscribers. Meanwhile, the MQTT proxy is also responsible for processing connection requests of subscribers and publishers and requests of subscribing and unsubscribing topics, that is, the MQTT proxy provides a communication bridge for service processes, and the service processes can realize data exchange and sharing through the bridge.
Furthermore, the communication protocol layer between the proxy process and the service process needs to package the topic and the load of the MQTT message so as to realize the topic subscription, the message sending and the message receiving actions, that is, the topic subscription and the message publishing are realized between the proxy process and the service process through the MQTT transmission protocol.
Further, since each MQTT client 120 runs multiple service processes, inter-process communication between the proxy process and the service processes belongs to one-to-many communication, and as long as there is a service process that needs to send and receive MQTT communication messages, the proxy process needs to maintain connection with the MQTT server.
Furthermore, when the proxy process and the business process realize inter-process communication, the inter-process communication method is constructed on the basis of an inter-process communication model of a release and subscription mechanism; the proxy process and the business process are one-to-many relationships; the proxy process subscribes to the fixed proxy theme and publishes the inter-process communication message by the fixed business theme; the business process subscribes to the fixed business theme and publishes the inter-process communication message by the fixed proxy theme; and the interprocess communication message defines a plurality of messages in a structured data format.
In summary, the proxy process subscribes to the fixed proxy topic, the service process subscribes to the fixed service topic, and the number of service processes can be increased as required without affecting the proxy process by adopting the fixed topic;
the inter-process communication of the proxy process and the service process belongs to one-to-many communication, and as long as the service process needs to send and receive the MQTT communication message, the proxy process can keep the connection with the MQTT server, so that the stability of communication connection is ensured;
based on the inter-process communication information of the connection state, the proxy process and the service process can reestablish inter-process communication under the conditions of different starting sequences or restarting after the process crashes and the like; and the proxy process sends periodic connection state notification to the service process, so that the connection state can be re-established after the two processes die and restart, and the proxy process initiates connection with the MQTT server after the service process is ready, thereby avoiding the condition that the offline message received when the connection is successful is not processed by people. In addition, if the plurality of business processes are respectively publishing the message, the proxy process can respectively confirm the publishing condition of the message by a mechanism of publishing confirmation, published message and message TOKEN, thereby improving the accuracy and efficiency of message publishing.
FIG. 2 is a method flow diagram illustrating a method of interprocess communication for an MQTT communication proxy according to an exemplary embodiment. As shown in fig. 2, the method may include the steps of:
step S201, the proxy process integration MQTT client communicates with the MQTT server according to an MQTT protocol; the agent process and a plurality of business processes integrate an inter-process communication library of a release subscription model so as to carry out inter-process communication; the proxy process and the business process are both running in the MQTT client.
In one possible implementation, since each MQTT client runs multiple service processes, in order for each of the multiple service processes to send and receive messages through one MQTT client, a proxy process needs to be set to be responsible for the connection between the MQTT client and the MQTT server, and other service processes and the proxy process send and receive MQTT communication messages indirectly through an inter-process communication manner.
Step S202, the proxy process subscribes to a fixed proxy theme and publishes inter-process communication information to the business process according to the fixed business theme.
In one possible implementation, a proxy process subscribing to a fixed proxy topic refers to the proxy process receiving a message through a particular subscription topic; the proxy process is a bridge connecting publishers and subscribers, after subscribing the topic, the proxy process receives all messages published to the topic, and forwards the messages to all subscribers subscribing to the topic, namely the business process, according to the topic.
Step S203, the business process subscribes to a fixed business theme, and issues an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
In one possible implementation, the business process subscribes to a fixed business theme, which refers to a message received and processed by the business process through subscribing to a specific business theme, and in practical application, the business process is generally implemented by a business processing system or business processing software, while the business theme can be regarded as a message category or a business field of interest to the business process, and by subscribing to the fixed business theme, the business process can receive and process a specific type of message in real time, thereby implementing real-time response and processing for the specific business field.
In summary, the proxy process subscribes to the fixed proxy topic, the service process subscribes to the fixed service topic, and the number of service processes can be increased as required without affecting the proxy process by adopting the fixed topic;
the inter-process communication of the proxy process and the service process belongs to one-to-many communication, and as long as the service process needs to send and receive the MQTT communication message, the proxy process can keep the connection with the MQTT server, so that the stability of communication connection is ensured;
based on the inter-process communication information of the connection state, the proxy process and the service process can reestablish inter-process communication under the conditions of different starting sequences or restarting after the process crashes and the like; and the proxy process sends periodic connection state notification to the service process, so that the connection state can be re-established after the two processes die and restart, and the proxy process initiates connection with the MQTT server after the service process is ready, thereby avoiding the condition that the offline message received when the connection is successful is not processed by people. In addition, if the plurality of business processes are respectively publishing the message, the proxy process can respectively confirm the publishing condition of the message by a mechanism of publishing confirmation, published message and message TOKEN, thereby improving the accuracy and efficiency of message publishing.
FIG. 3 is a method flow diagram illustrating a method of interprocess communication for an MQTT communication proxy according to an exemplary embodiment. As shown in fig. 3, the method may include the steps of:
step S301, the proxy process integration MQTT client communicates with the MQTT server according to an MQTT protocol; the agent process and a plurality of business processes integrate an inter-process communication library of a release subscription model so as to carry out inter-process communication; the proxy process and the business process are both running in the MQTT client.
In one possible implementation, the interprocess communication message includes a message header and a message body;
the message header comprises a message function identifier and a publisher identifier; the message body is arranged in a fixed order by one or more integer data and character string data according to the difference of the message function identifiers.
Further, the message function identifier and the publisher identifier are both enumeration amounts, and the message function identifier sequentially identifies each message type with an ordinal number starting with 0;
the publisher identity identifies the proxy process with 0 and the ordinal number starting with 1 identifies the respective business process.
Further, the message function identifier sequentially identifies various message types with an ordinal number of 0, including functions such as "connect", "disconnect", "subscribe", "publish success", "receive", "connect status" and "publish acknowledge". The message body is different according to the function identification of each message, and is arranged by one or more integer data and character string data according to a fixed sequence.
Step S302, the proxy process subscribes to a fixed proxy theme and publishes inter-process communication information to the business process according to the fixed business theme.
Step S303, the business process subscribes to a fixed business theme, and issues an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
Furthermore, the inter-process communication between the proxy process and the service process belongs to one-to-many communication, and the proxy process can keep the connection with the MQTT server as long as the service process needs to send and receive the MQTT communication message. Based on the inter-process communication model of the publish and subscribe mechanism, the number of business processes can be increased as required without affecting the proxy process.
Step S304, the proxy process and the business process store the connection state information of the MQTT; the proxy process periodically issues inter-process communication messages of the connection state.
In one possible embodiment, the connection state information includes three states of connection disconnection, connected and connected, and the initial state is connection disconnection. The periodic release can be once per second, and the proxy process notifies the periodic connection state of the service process, so that the connection state can be re-established after the processes die and restart;
step S305, after receiving the connection state issued by the proxy process, the service process issues an inter-process communication message of an MQTT connection request or an MQTT disconnection request when the connection state of the proxy process is inconsistent with the connection state stored by the service process.
Step S306, after receiving the MQTT connection request or the MQTT disconnection request, the proxy process sets or clears the bit identification of the business process corresponding to the information of the information publisher according to the information of the information publisher.
In step S307, the proxy process initiates an MQTT connection request at all service processes, or initiates a communication connection with the MQTT server after a first preset time is exceeded.
Further, the first preset time may be set according to an actual application scenario.
And step S308, when no business process initiates an MQTT connection request, the proxy process disconnects the MQTT server.
Further, first, the proxy process issues an inter-process communication message of the connection state once per second; after receiving the communication message of the connection state, the business process issues an inter-process communication message of an MQTT connection request or an MQTT disconnection request when the communication message is found to be inconsistent with the connection state stored by the business process; then, after receiving the communication messages of the MQTT connection request and the MQTT disconnection request, the proxy process sets or clears the bit identification of the service process according to the information of the message publisher; the proxy process initiates a connection request after all service processes or after the preset time is exceeded, initiates connection with the MQTT server; finally, when no business process has an MQTT connection request, the proxy process is disconnected with the MQTT server, and the proxy process and the business process are synchronously completed, so that the proxy process realizes the connection with the MQTT server, based on the conditions that the proxy process and the business process are started in different sequences or restarted after the process crashes, inter-process communication can be reestablished, and after the business process is ready, the proxy process initiates the connection with the MQTT server, thereby avoiding the condition that the offline message received when the connection is just successful is not processed by people.
In one possible implementation, the service process issues an inter-process communication message of the MQTT issue request in the MQTT-connected state;
after receiving the MQTT release request, the proxy process sends the MQTT release request to the MQTT server, acquires a release TOKEN TOKEN and sends an inter-process communication message of the MQTT release confirmation;
after receiving the MQTT release confirmation, the business process waits for the inter-process communication message released by the MQTT according to the release TOKEN;
after receiving the published message of the MQTT published by the MQTT server, the proxy process obtains the published TOKEN and distributes the published inter-process communication message of the MQTT;
after receiving the inter-process communication message issued by the MQTT, the business process confirms that the issuing is completed according to the issued TOKEN;
and if the business process does not receive the MQTT release confirmation and the communication message released by the MQTT in the second preset time, the release is considered to be failed.
Further, when the service process issues the MQTT issue request, firstly, the service process issues an inter-process communication message of the MQTT issue request in a state that the MQTT is connected, and then waits for the MQTT to issue a confirmed process communication message; after receiving the communication message of the MQTT release request, the proxy process sends a release request to the MQTT server to obtain a release TOKEN, and then releases the process communication message of the MQTT release confirmation; then, after receiving the communication message of the MQTT issue confirmation, the business process waits for the process communication message issued by the MQTT according to the issue TOKEN; after receiving the published message of the MQTT published by the MQTT server, the proxy process obtains a published TOKEN and publishes the inter-process communication message of the published MQTT; and finally, after receiving the inter-process communication message issued by the MQTT, the business process confirms that the issuing is completed according to the issued TOKEN. And if the business process does not receive the MQTT release confirmation and the communication message released by the MQTT within the specified time limit, the release is considered to be failed. In the communication process of issuing the MQTT issue request, when a plurality of business processes issue messages respectively, the proxy process enables the business processes to confirm the issue condition of the messages respectively through the mechanism of issuing confirmation, issued messages and message TOKEN.
In a possible implementation manner, the proxy process and the service process both store MQTT subscription request tables, and the proxy process also stores MQTT subscribed topic tables;
before the proxy process starts the MQTT connection for the first time or restarts the MQTT connection, the MQTT subscribed topic table and the MQTT subscription request table in the proxy process are emptied.
In one possible implementation, the business process issues an inter-process communication message of the MQTT subscription request when the MQTT connection state changes;
after receiving the MQTT subscription request, the proxy process adds the subscription topic of the MQTT subscription request to the MQTT subscription request table if the subscription topic of the MQTT subscription request to be subscribed is not in the MQTT subscribed topic table;
the proxy process sequentially takes out the subscription topics of the MQTT subscription request table, sends a subscription request to the MQTT server, and adds the subscription topics to the MQTT subscribed topic table after successful subscription.
Further, the proxy process empties the MQTT subscribed topic table and the MQTT subscription request table before starting or restarting the MQTT connection for the first time; when the business process needs to publish the MQTT subscription request and the MQTT connection state is changed, the business process publishes an inter-process communication message of the MQTT subscription request; secondly, after receiving the communication message of the MQTT subscription request, the proxy process adds the topic to be subscribed to the MQTT subscription request table if the topic to be subscribed is not in the MQTT subscribed topic table; after the proxy process is successfully connected with the MQTT server, the subscription topics of the MQTT subscription request list are sequentially taken out, subscription requests are sent to the MQTT server, and after the subscription is successful, the subscription topics are added to the MQTT subscribed topic list. In the communication of publishing the MQTT subscription request, the proxy process merges and processes the MQTT topic subscription request sent by the service process, and only initiates a subscription request for a specific MQTT topic within the connection period with the MQTT server; that is, when a plurality of business processes subscribe to the topics respectively, the proxy process can ensure that the same topic is not subscribed repeatedly through the subscription request table and the subscribed topic table.
In a possible implementation manner, after the subscription of the MQTT subscription request issued by the service process is successful, when the MQTT server receives new information of the subscription theme, the MQTT has issued a received message;
after receiving the MQTT received message issued by the MQTT server, the proxy process issues an inter-process communication message received by the MQTT;
after receiving the inter-process communication message received by the MQTT, the business process matches the MQTT subscription request table stored by the business process according to the subscription theme, and confirms that the MQTT message is received.
Further, after the subscription of the MQTT subscription request issued by the service process is successful, when the MQTT server receives the new information of the subscription subject, the MQTT received information is issued; after receiving the MQTT received message issued by the MQTT server, the proxy process issues an inter-process communication message received by the MQTT; and after receiving the inter-process communication message received by the MQTT, the business process matches the MQTT subscription request table according to the subscription theme and confirms that the MQTT message is received.
In summary, the proxy process subscribes to the fixed proxy topic, the service process subscribes to the fixed service topic, and the number of service processes can be increased as required without affecting the proxy process by adopting the fixed topic;
the inter-process communication of the proxy process and the service process belongs to one-to-many communication, and as long as the service process needs to send and receive the MQTT communication message, the proxy process can keep the connection with the MQTT server, so that the stability of communication connection is ensured;
based on the inter-process communication information of the connection state, the proxy process and the service process can reestablish inter-process communication under the conditions of different starting sequences or restarting after the process crashes and the like; and the proxy process sends periodic connection state notification to the service process, so that the connection state can be re-established after the two processes die and restart, and the proxy process initiates connection with the MQTT server after the service process is ready, thereby avoiding the condition that the offline message received when the connection is successful is not processed by people. In addition, if the plurality of business processes are respectively publishing the messages, the proxy process can respectively confirm the publishing condition of the messages by a mechanism of publishing confirmation, published messages and message TOKEN, so that the message publishing accuracy and efficiency are improved;
when a plurality of business processes subscribe topics respectively, the proxy process can ensure that the same topic is not subscribed repeatedly through the subscription request table and the subscribed topic table; and, the proxy process can combine and process the MQTT topic subscription request sent by the service process based on the subscribed topic table, and only initiates a subscription request for a specific MQTT topic within the connection period with the MQTT server.
Referring to fig. 4, a schematic diagram of a computer device according to an exemplary embodiment of the present application is provided, where the computer device includes a memory and a processor, and the memory is configured to store a computer program, and when the computer program is executed by the processor, implement an inter-process communication method of an MQTT communication proxy.
The processor may be a central processing unit (Central Processing Unit, CPU). The processor may also be any other general purpose processor, digital signal processor (Digital Signal Processor, DSP), application specific integrated circuit (Application Specific Integrated Circuit, ASIC), field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof.
The memory, as a non-transitory computer readable storage medium, may be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules corresponding to the methods in embodiments of the present application. The processor executes various functional applications of the processor and data processing, i.e., implements the methods of the method embodiments described above, by running non-transitory software programs, instructions, and modules stored in memory.
The memory may include a memory program area and a memory data area, wherein the memory program area may store an operating system, at least one application program required for a function; the storage data area may store data created by the processor, etc. In addition, the memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some implementations, the memory optionally includes memory remotely located relative to the processor, the remote memory being connectable to the processor through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
In an exemplary embodiment, a computer readable storage medium is also provided for storing at least one computer program that is loaded and executed by a processor to implement all or part of the steps of the above method. For example, the computer readable storage medium may be Read-Only Memory (ROM), random-access Memory (Random Access Memory, RAM), compact disc Read-Only Memory (CD-ROM), magnetic tape, floppy disk, optical data storage device, and the like.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the application pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It is to be understood that the present application is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (10)

1. An inter-process communication method of an MQTT communication proxy, the method comprising:
the agent process integrated MQTT client communicates with the MQTT server according to an MQTT protocol; the proxy process and a plurality of business processes integrate an inter-process communication library of the publishing and subscribing model so as to perform inter-process communication; the proxy process and the service process are both operated in the MQTT client;
the proxy process subscribes to a fixed proxy theme and publishes inter-process communication information to the business process by using the fixed business theme;
the business process subscribes to a fixed business theme and issues an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
2. The method of claim 1, wherein the inter-process communication message comprises a message header and a message body;
the message header comprises a message function identifier and a publisher identifier; the message body is arranged by one or more integer data and character string data according to the different message function identifiers.
3. The method of claim 1, wherein the proxy process and the business process each store connection state information of MQTT; the method further comprises the steps of:
the proxy process periodically issues inter-process communication information of the connection state;
after receiving the connection state issued by the proxy process, the business process issues an inter-process communication message of an MQTT connection request or an MQTT disconnection request when the connection state of the proxy process is inconsistent with the connection state stored by the business process;
after receiving the MQTT connection request or the MQTT disconnection request, the proxy process sets or clears the bit identification of the business process corresponding to the information of the information publisher according to the information of the information publisher;
the proxy process initiates an MQTT connection request at all service processes, or initiates communication connection with the MQTT server after exceeding a first preset time;
and when no business process initiates an MQTT connection request, the proxy process disconnects the MQTT server.
4. A method according to claim 3, characterized in that the method further comprises:
the business process issues an inter-process communication message of an MQTT issue request in an MQTT connected state;
after receiving the MQTT release request, the proxy process sends the MQTT release request to the MQTT server, acquires a release TOKEN TOKEN and sends an inter-process communication message of the MQTT release confirmation;
after receiving the MQTT release confirmation, the business process waits for the inter-process communication message released by the MQTT according to the release TOKEN;
after receiving the published message of the MQTT published by the MQTT server, the proxy process obtains the published TOKEN and distributes the published inter-process communication message of the MQTT;
after receiving the inter-process communication message issued by the MQTT, the business process confirms that the issuing is completed according to the issued TOKEN;
and if the business process does not receive the MQTT release confirmation and the communication message released by the MQTT in the second preset time, the release is considered to be failed.
5. A method according to any one of claims 1 to 3, wherein the proxy process and the service process each store an MQTT subscription request table, and the proxy process further stores an MQTT subscribed topic table; the method further comprises the steps of:
and before the proxy process starts the MQTT connection for the first time or restarts the MQTT connection, the MQTT subscribed topic table and the MQTT subscription request table in the proxy process are emptied.
6. The method of claim 5, wherein the method further comprises:
when the MQTT connection state is changed, the business process issues an inter-process communication message of an MQTT subscription request;
after receiving the MQTT subscription request, the proxy process adds the subscription topic of the MQTT subscription request to the MQTT subscription request table if the subscription topic of the MQTT subscription request to be subscribed is not in the MQTT subscribed topic table;
and the proxy process sequentially takes out the subscription topics of the MQTT subscription request table, sends a subscription request to an MQTT server, and adds the subscription topics to the MQTT subscribed topic table after successful subscription.
7. The method of claim 6, wherein after successful subscription of the MQTT subscription request issued by the business process, the method further comprises:
when the MQTT server receives the new information of the subscription theme, the MQTT server publishes the received information;
after receiving the message received by the MQTT published by the MQTT server, the proxy process publishes the received inter-process communication message of the MQTT;
after receiving the inter-process communication message received by the MQTT, the business process matches the MQTT subscription request table stored by the business process according to the subscription theme, and confirms that the MQTT message is received.
8. An inter-process communication system of an MQTT communication proxy, wherein the system is adapted to perform an inter-process communication method of an MQTT communication proxy as set forth in any one of claims 1 to 7;
the system comprises an MQTT client and an MQTT server; the MQTT client is internally operated with an agent process and a plurality of business processes;
the proxy process is used for integrating the MQTT client and the MQTT server to communicate according to the MQTT protocol; the proxy process and the business process also integrate an inter-process communication library of the publishing and subscribing model so as to carry out inter-process communication;
the proxy process is also used for subscribing a fixed proxy theme and publishing an inter-process communication message to the business process by using the fixed business theme;
the business process is also used for subscribing a fixed business theme and publishing an inter-process communication message to the proxy process by using the fixed proxy theme; the proxy process and the business process are one-to-many inter-process communication.
9. A computer device comprising a processor and a memory having stored therein at least one instruction that is loaded and executed by the processor to implement an inter-process communication method of an MQTT communication proxy according to any one of claims 1 to 7.
10. A computer readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement an inter-process communication method of an MQTT communication proxy according to any one of claims 1 to 7.
CN202311834313.2A 2023-12-27 2023-12-27 Inter-process communication method of MQTT communication proxy Pending CN117793187A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311834313.2A CN117793187A (en) 2023-12-27 2023-12-27 Inter-process communication method of MQTT communication proxy

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311834313.2A CN117793187A (en) 2023-12-27 2023-12-27 Inter-process communication method of MQTT communication proxy

Publications (1)

Publication Number Publication Date
CN117793187A true CN117793187A (en) 2024-03-29

Family

ID=90394279

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311834313.2A Pending CN117793187A (en) 2023-12-27 2023-12-27 Inter-process communication method of MQTT communication proxy

Country Status (1)

Country Link
CN (1) CN117793187A (en)

Similar Documents

Publication Publication Date Title
WO2019205907A1 (en) Intelligent device communication platform based on mqtt message protocol
CN106230896A (en) A kind of information push method, Apparatus and system
CN108712485B (en) Resource subscription method and device for Internet of things equipment
US8954504B2 (en) Managing a message subscription in a publish/subscribe messaging system
CN109769023B (en) Data transmission method, related server and storage medium
CN111083193A (en) Long connection message sending method, server and storage medium
CN110808948B (en) Remote procedure calling method, device and system
US8355401B2 (en) Controlling access to a destination in a data processing network
CN112118315A (en) Data processing system, method, device, electronic equipment and storage medium
CN110535811B (en) Remote memory management method and system, server, client and storage medium
CN114338063B (en) Message queue system, service processing method and computer readable storage medium
CN112565214A (en) Data transmission method, system and medium based on WebSocket
WO2020149965A1 (en) Mesh network
CN113412478B (en) Message transmitting/receiving method, communication device, and program
CN117793187A (en) Inter-process communication method of MQTT communication proxy
CN116800787A (en) Vehicle-mounted communication method and system based on Ethernet communication protocol
US8135025B2 (en) Asynchronous communication in an unstable network
CN112637121B (en) Data port updating method and device, electronic equipment and readable storage medium
CN109379443B (en) Method for realizing distributed message queue facing to Internet of things
CN112995095A (en) Data processing method, device and computer readable storage medium
CN116361038B (en) Acceleration computing management method, system, equipment and storage medium
CN111565209B (en) Client instant messaging method, device, equipment and medium
WO2024052981A1 (en) Processing device, processing method, and program
US20220060567A1 (en) Remote Procedure Call Between Entities in a Service Bus Communication System
CN116260859B (en) Data configuration system

Legal Events

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