Detailed Description
The communication architecture of the embodiment of the invention comprises a plurality of clients, an access platform consisting of a load balancing server, an MQTT server and a plurality of business devices, and a service system. The connection relationship of a specific communication architecture is shown in fig. 2.
In implementation, a client accesses an access platform through a domain name; specifically, before the client establishes connection with the access platform, the client acquires the IP address of the access platform through the domain name server. The IP address returned by the domain name server to the client points to the address of the load balancing server in the access platform, and the load balancing server forwards the request of the client to the MQTT server. The business equipment realizes bidirectional butt joint with the MQTT server and the business system; the business device and the service system communicate with each other through http (hypertext transfer protocol).
Specifically, when the client accesses the access platform, the client communicates with the access platform by calling the SDK interface. As shown in fig. 3, it is assumed that the client includes a smart television, a smart refrigerator, a smart washing machine, a smart lamp, a smart switch, and the like, where the smart television, the smart refrigerator, and the smart washing machine call the SDK to access the access platform through an Application Programming Interface (API), and the smart lamp and the smart switch call the SDK to access the access platform through a smart gateway and then through the API; and the interface of the SDK is communicated with the access platform based on the MQTT.
An alternative communication architecture, as shown in fig. 4, includes a first device, a server, a business system, and at least two second devices interfacing with the business system. In the communication architecture, a first device serves as a data publishing device, and a second device serves as a data subscribing device; the service system is used for collecting required data, in order to facilitate the service system to collect the required data, at least two second devices are deployed for the service system, and the second devices subscribe the data required by the service system to the server. For example, if the service system needs to collect the operating temperature of the device, at least two second devices subscribe to the server for data whose topic (topic) is "temperature".
The first equipment issues data to the server, and the issued uplink data carries the theme of the issued data; after receiving data published by first equipment, a server judges whether second equipment subscribing the data of the theme exists according to the theme of the data published by the first equipment; for example, when the topic of the data issued by the first device is "temperature", the server pushes the received data with the topic of "temperature" to the second device, and the second device sends the received data with the topic of "temperature" to the docked service system. However, based on the current MQTT protocol, since at least two second devices subscribe to the data with the topic of "temperature", the server will push the data with the topic of "temperature" published by the first device to all the second devices, and each second device will send the received data with the topic of "temperature" to the service system, so that the service system receives a plurality of same data.
Based on the above problem, the embodiment of the present invention provides a solution, in which a field of a subject is modified, and in implementation, a queue identifier may be added to the field of the subject;
wherein the queue identification indicates that the data representing the topic is subscribed to by the business system through a plurality of second devices.
An alternative embodiment is to add a "queue" identifier to the topic field.
For example, when the business system needs to collect data, the business system subscribes the data to the server through a plurality of second devices; specifically, a plurality of second devices send subscription messages to the server, the subscription messages carry topics of subscription data, and queue identifiers are added to the topics;
when the first device issues the uplink data to the server, the first device also needs to carry a theme of the uplink data, and a queue identifier is also added to the theme of the uplink data;
the server pushes the data published by the first device to the second device when determining that the theme of the data published by the first device is the same as the theme of the data subscribed by the second device;
it should be noted here that, when the topic of the data subscribed by the second device includes the queue identifier, the server determines that the topic of the data published by the first device is the same as the topic of the data subscribed by the second device only when the topic of the data published by the first device also includes the queue identifier.
As shown in fig. 5, a data transmission method according to an embodiment of the present invention includes:
step 501, a server receives data issued by first equipment;
step 502, when the topic of the data published by the first device contains a queue identifier, the server selects a target second device in an available state from a plurality of second devices subscribing the topic data; wherein the queue identification is for data representing the topic subscribed to by a business system through a plurality of second devices;
step 503, the server sends the data issued by the first device to the target second device, so that the target second device sends the data to the docked service system.
It should be noted that, the server receives data issued by different first devices, and stores the data issued by the first devices according to topics respectively; for example, the server receives data with topic of topic1 sent by device a and data with topic of topic2 sent by device B.
The server in the embodiment of the invention is a server supporting MQTT, which can be called as an agent or a Broker; the second device is a business device which is in butt joint with the business system.
In addition, an embodiment of the present invention further provides an optional manner for the second device to subscribe to data from the server:
the server receives subscription information sent by the service system through a plurality of second devices; determining topics of data subscribed by the plurality of second devices according to the subscription message; wherein the topics of the data subscribed by the plurality of second devices are the same.
Configuring the theme of the data to be subscribed of the second equipment according to the type of the data to be acquired by the service system;
for example, if the business system needs to collect the remaining power of the device, the topic of the data that the second device needs to subscribe to the server is configured as "remaining power".
It should be noted that, in the embodiment of the present invention, a technician configures a theme of data to be subscribed for the second device according to the type of data collected by the service system.
Because the embodiment of the invention deploys the plurality of second devices for the service system, the plurality of second devices deployed for the service system all need to subscribe data to the service, and topic of the data subscribed to the server by the plurality of second devices is the same, compared with the case of deploying one second device for the service system, the problem that the data published by the first device cannot be sent to the service system due to failure of the deployed second device can be avoided.
In an optional embodiment, when the plurality of second devices subscribe to the server, a queue identifier is added to a topic of the subscription data.
A data publishing process for a first device:
the first equipment sends data to the server;
after receiving data sent by a first device, a server detects states of a plurality of second devices subscribing the theme data, determines second devices in available states in the plurality of second devices, and generates a list consisting of the second devices in available states;
that is, the topic of the data subscribed by the second device included in the list is the same as the topic of the data published by the first device;
it should be noted here that the server can determine the status of each second device through the service registration discovery procedure, and therefore, the server can determine the second devices in the available status.
When the theme contains the queue identification, the server selects a target second device from the list, and the server sends the data issued by the first device to the target second device;
and when the theme does not contain the queue identification, the server sends the data issued by the first equipment to each second equipment in the list.
It should be noted that, when the service system subscribes to data of a certain theme through the plurality of second devices, whether the theme subscribed by the plurality of second devices carries the queue identifier is pre-configured according to the type of the service system and the user requirement; and the type of the subject of the data issued by the first device, whether the subject of the data carries a queue identifier, which is also determined according to the pre-configuration in the first device.
The method for data transmission according to the embodiment of the present invention is described below with reference to a specific embodiment.
Assume that three second devices, device 1, device 2, and device 3, are deployed for the service system.
Fig. 6 shows an overall flowchart of a data transmission method implemented by the present invention.
601, the second device sends subscription messages to the server respectively, wherein the topic of the data to be subscribed contained in the subscription messages is topic 1;
that is, the device 1, the device 2, and the device 3 each transmit a subscription message to the server.
In step 602, the server stores the topic of the data subscribed by each second device as topic 1.
Step 603, the first device issues data to the server, and the topic of the data is topic 1.
Step 604, the server acquires the second device in the available state with the subscribed data topic of topic1, and generates a list consisting of the second device in the available state;
the list generated by the server contains: device 1, device 2, device 3;
step 605, the server determines whether the topic1 includes a queue identifier, if yes, step 606 is executed, and if not, step 609 is executed;
step 606, the server selects a target second device from the list;
assume that the selected target second device is device 1.
Step 607, the server pushes the data issued by the first device to the device 1.
Step 608, the device 1 sends the received data to the service system.
Step 609, the server pushes the data issued by the first equipment to each second equipment;
that is, the server pushes data issued by the first device to the device 1, the device 2, and the device 3.
And step 610, each second device sends the received data to the service system.
Based on the same inventive concept, the embodiment of the present invention further provides a server, and as the principle of solving the problem of the server is similar to the method for data transmission in the embodiment of the present invention, the implementation of the server may refer to the implementation of the method, and repeated details are not repeated.
It should be noted that the server available protocol provided by the embodiment of the present invention includes: ac-mqtt, ac-mqtt-business, mqtt SDK, and the like.
As shown in fig. 7, a server according to an embodiment of the present invention includes a processing unit 701, a storage unit 702, and a transceiver unit 703;
wherein the storage unit 702 stores program code which, when executed by the processing unit 701, causes the processing unit 701 to perform the following:
receiving data issued by the first device through the transceiver 703;
when the topic of the data published by the first device contains a queue identifier, selecting a target second device in an available state from a plurality of second devices subscribed to the topic data; wherein the queue identification is for data representing the topic subscribed to by a business system through a plurality of second devices;
the data issued by the first device is sent to the target second device through the transceiver 703, so that the target second device sends the data to a docked service system.
Optionally, the processing unit 701 is further configured to:
before receiving data published by first equipment, receiving subscription information sent by the service system through a plurality of second equipment; determining the topic of the data subscribed by each second device according to the subscription message; wherein the topics of the data subscribed by the plurality of second devices are the same.
Optionally, the processing unit 701 is specifically configured to:
detecting states of a plurality of second devices subscribing to data of the topic; determining a second device in an available state in the plurality of second devices, and generating a first list consisting of the second devices in the available state; selecting a target second device from the first list.
Optionally, the processing unit 701 is further configured to:
when the topic of the data published by the first device does not contain a queue identifier, determining a second list consisting of second devices subscribing to the topic data;
and sending the data issued by the first device to each second device in the second list, so that each second device sends the received data to the docked service system.
Optionally, the server is a server supporting MQTT;
the first device and the second device are MQTT-supporting devices.
As shown in fig. 8, a data transmission apparatus according to an embodiment of the present invention includes:
a receiving module 801, configured to receive data issued by a first device;
an obtaining module 802, configured to, when a topic of data published by the first device includes a queue identifier, select a target second device in an available state from multiple second devices subscribing to the topic data; wherein the queue identification is for data representing the topic subscribed to by a business system through a plurality of second devices;
a sending module 803, configured to send the data issued by the first device to the target second device, so that the target second device sends the data to a docked service system.
Optionally, the receiving module 801 is further configured to:
before receiving data published by first equipment, receiving subscription information sent by the service system through a plurality of second equipment; determining the topic of the data subscribed by each second device according to the subscription message; wherein the topics of the data subscribed by the plurality of second devices are the same.
Optionally, the obtaining module 802 is specifically configured to:
detecting states of a plurality of second devices subscribing to data of the topic; determining a second device in an available state in the plurality of second devices, and generating a first list consisting of the second devices in the available state; selecting a target second device from the first list.
Optionally, when the topic of the data issued by the first device does not include a queue identifier, the obtaining module 802 is further configured to: determining a second list consisting of second devices subscribed to the topic data;
the sending module 803 is further configured to: and sending the data issued by the first device to each second device in the second list, so that each second device sends the received data to the docked service system.
An embodiment of the present invention further provides a computer-readable medium, on which a computer program is stored, where the computer program is executed by a processor to implement the steps of any one of the methods described above.
The present application is described above with reference to block diagrams and/or flowchart illustrations of methods, apparatus (systems) and/or computer program products according to embodiments of the application. It will be understood that one block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, and/or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer and/or other programmable data processing apparatus, create means for implementing the functions/acts specified in the block diagrams and/or flowchart block or blocks.
Accordingly, the subject application may also be embodied in hardware and/or in software (including firmware, resident software, micro-code, etc.). Furthermore, the present application may take the form of a computer program product on a computer-usable or computer-readable storage medium having computer-usable or computer-readable program code embodied in the medium for use by or in connection with an instruction execution system. In the context of this application, a computer-usable or computer-readable medium may be any medium that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.