CN117176782A - Data interaction method, device and system - Google Patents

Data interaction method, device and system Download PDF

Info

Publication number
CN117176782A
CN117176782A CN202311184573.XA CN202311184573A CN117176782A CN 117176782 A CN117176782 A CN 117176782A CN 202311184573 A CN202311184573 A CN 202311184573A CN 117176782 A CN117176782 A CN 117176782A
Authority
CN
China
Prior art keywords
connection object
connection
data
internet
message server
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
CN202311184573.XA
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.)
Shenzhen Jiuniuyimao Intelligent Internet Of Things Technology Co ltd
Original Assignee
Shenzhen Jiuniuyimao Intelligent Internet Of Things 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 Shenzhen Jiuniuyimao Intelligent Internet Of Things Technology Co ltd filed Critical Shenzhen Jiuniuyimao Intelligent Internet Of Things Technology Co ltd
Priority to CN202311184573.XA priority Critical patent/CN117176782A/en
Publication of CN117176782A publication Critical patent/CN117176782A/en
Pending legal-status Critical Current

Links

Abstract

The application discloses a data interaction method, a device and a system, wherein after first equipment data sent by an equipment layer are received, a target group is determined based on equipment identification carried by the first equipment data, a first connection object is searched in a first connection pool, when the first connection object is searched, the first equipment data is sent to a message server through the first connection object, the message server forwards the first equipment data to a target application, the first connection object is newly built and cached in the first connection pool, and when the first equipment data is transmitted to the message server each time, the first equipment data can be transmitted by the Internet of things platform through the first connection object, so that the operation of frequently establishing connection of the Internet of things platform is greatly reduced, the probability of breakdown of the Internet of things platform is reduced under the scene of data concurrency, and the stability of the Internet of things platform is facilitated to be maintained.

Description

Data interaction method, device and system
Technical Field
The application belongs to the technical field of application of the Internet of things, and particularly relates to a data interaction method, device and system.
Background
In the current application development of the internet of things, in order to simplify development steps and improve development efficiency, an internet of things platform is generally abstracted, the internet of things platform and the equipment at the bottom layer are used for data communication, and an application layer is directly interacted with the internet of things platform, so that the application layer can be free from directly interacting with the equipment, and various complex communication protocols and data interaction protocols are shielded by the internet of things platform.
For a scene with a large number of devices, the internet of things platform can realize data interaction through the message server in consideration of a large number of concurrent devices. For example, when the internet of things platform receives a large amount of device data, the internet of things platform can send the device data to the message server, the message server forwards the device data to the message queue for storage, and the application layer reads the device data from the message queue, so that when the device data amount is relatively large, the application layer can avoid system breakdown caused by processing a large amount of device data in a short time. However, in this scenario, the internet of things platform needs to be frequently connected to the message server, resulting in poor stability of the internet of things platform.
Disclosure of Invention
The application provides a data interaction method, device and system, which are used for solving the problem of poor platform stability of the existing internet of things platform in a scene of large equipment data concurrency.
In a first aspect, an embodiment of the present application provides a data interaction method, including:
receiving first device data sent by a device layer; wherein, the first device data carries a device identifier;
determining a target group based on the device identification; the target group comprises at least one target application;
If a first connection object is found in a first connection pool, sending the first device data to a message server through the first connection object so as to forward the first device data to the target application by the message server; the first connection pool is a connection pool which is pre-established and used for storing a first connection object; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server.
Through newly establishing and caching the first connection object in the first connection pool, the connection multiplexing mechanism based on the connection pool can transmit the first device data through the first connection object when the internet of things platform transmits the first device data to the message server each time, so that the operation of frequently establishing connection of the internet of things platform is greatly reduced, the probability of breakdown of the internet of things platform is reduced under the scene of data concurrency, and the stability of the internet of things platform is maintained.
In one possible implementation manner, after the determining the target group based on the device identifier, the method further includes:
determining a target group connection object according to the target group;
correspondingly, the first connection object comprises a target group connection object; if a first connection object is found in the first connection pool, sending the first device data to a message server through the first connection object, including:
If the target group connection object is found in the first connection pool, sending the first device data to the message server through the target group connection object; the target group connection object is used for representing one data transmission channel between the internet of things platform and the message server, and corresponds to the target group.
In one possible implementation manner, if a first connection object is found in the first connection pool, sending the first device data to a message server through the first connection object includes:
if the connection state of the first connection object is connection, acquiring the first connection object, and sending the first device data to the message server through the first connection object;
and if the connection state of the first connection object is disconnected, reestablishing the first connection object so as to send the first device data to the message server through the reestablished first connection object.
In one possible implementation, the method further includes:
and after the first device data is sent to the message server, releasing the resources of the first connection object, and returning the first connection object to the first connection pool.
In one possible implementation, the method further includes:
if the first connection object cannot be found in the first connection pool, a data transmission channel between the Internet of things platform and the message server is established so as to newly add the first connection object in the first connection pool, and the first device data is sent to the message server through the first connection object.
In one possible implementation manner, after the first device data sent by the receiving device layer, the method further includes:
determining at least one routing key to which the device identification matches;
generating routing key information based on the at least one routing key, adding the routing key information to the first device data, and then packaging the first device data into a first message;
correspondingly, the sending the first message to the message server through the first connection object includes:
and sending the first message to the message server through the first connection object.
In one possible implementation manner, the sending the first message to the message server through the first connection object includes:
and sending the first message to the message server through the first connection object, so that the message server stores the first message into a target message queue corresponding to each routing key respectively based on the routing key information carried by the first message.
In one possible implementation, the method further includes:
receiving a device control instruction sent by an application layer; wherein, the equipment control instruction carries an equipment identifier;
determining a target theme and target equipment based on the equipment identifier, and sending the equipment control instruction to the target theme;
and pulling the equipment control instruction from the target theme, and sending the equipment control instruction to the target equipment.
In a second aspect, an embodiment of the present application provides a data interaction device, where the data interaction device is applied to an internet of things platform, and the data interaction device includes:
the receiving module is used for receiving the first device data sent by the device layer; wherein, the first device data carries a device identifier;
a determining module, configured to determine a target group based on the device identifier; the target group comprises at least one target application;
the sending module is used for sending the first equipment data to a message server through the first connection object if the first connection object is found in the first connection pool so as to forward the first equipment data to the target application through the message server; the first connection pool is a connection pool which is pre-established and used for storing a first connection object; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server.
In a third aspect, an embodiment of the present application provides a data interaction system, including an application layer, an internet of things platform, a device layer, and a message server; the Internet of things platform is connected with the equipment layer and the application layer;
the device layer is used for sending first device data to the Internet of things platform;
the internet of things platform is used for receiving first equipment data sent by the equipment layer; the first device data carries a device identifier; and further configured to determine a target group based on the device identification; if a first connection object is found in the first connection pool, the first equipment data is sent to a message server through the first connection object; the target group comprises at least one target application; the first connection pool is a connection pool which is pre-established and used for storing first connection objects; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server;
the message server is configured to receive the first device data and send the first device data to a target application in the application layer.
It will be appreciated that the advantages of the second and third aspects may be found in the relevant description of the first aspect and are not described in detail herein.
Drawings
Fig. 1 is a schematic structural diagram of an application scenario of a data interaction system provided by an embodiment of the present application;
FIG. 2 is a schematic flow chart of a data interaction method according to an embodiment of the present application;
FIG. 3 is a schematic flow chart of S130 a-131 a in the data interaction method according to the embodiment of the application;
FIG. 4 is a schematic view of a group partition scenario according to an embodiment of the present application;
fig. 5 is a schematic diagram of a specific flow of S13 in the data interaction method provided in the embodiment of the present application;
FIG. 6 is a schematic flow chart of S120 a-120 b in the data interaction method according to the embodiment of the application;
fig. 7 is a block diagram of a data interaction device according to an embodiment of the present application.
Detailed Description
In order to make the technical problems, technical schemes and beneficial effects to be solved more clear, the application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
In order to facilitate an understanding of embodiments of the present application, several concepts are briefly described below.
Message: refers to data communicated between two clients or two applications.
Message middleware: a middleware for responsible for the delivery, storage and distribution of messages that is deployed with message servers, including but not limited to RabbitMQ, kafka, rocketMQ, etc.
Message queue telemetry transport (Message Queuing Telemetry Transport, MQTT): is a client-server based message publish/subscribe transport protocol.
Virtual Host (Virtual Host): in the present application, a virtual host refers to a plurality of virtual servers divided by a single message server, and each virtual host is isolated from each other.
And (3) connecting a pool: in the application, the connection pool is a cache pool which can be used for creating and storing connection objects, and the connection objects in the connection pool can be reused, namely, when one thread acquires the connection objects from the connection pool and the thread performs tasks, the connection objects are returned to the connection pool, and then the connection objects can be used for other subsequent threads.
In the current application development of the internet of things, in order to simplify the development steps and improve the development efficiency, an internet of things platform is generally abstracted, the internet of things platform communicates data with the equipment at the bottom layer, and the application layer directly interacts with the internet of things platform. Therefore, the application layer can avoid directly interacting with the equipment, and various complex communication protocols and data interaction protocols are shielded by the Internet of things platform.
For a scene with a large number of devices, the internet of things platform can realize data interaction through the message server in consideration of a large number of concurrent devices. For example, when the internet of things platform receives a large amount of device data, the internet of things platform can send the device data to the message server, the message server forwards the device data to the message queue for storage, and the application layer reads the device data from the message queue. Thus, when the device data amount is relatively large, the application layer can avoid system breakdown caused by processing a large amount of device data in a short time. However, in this scenario, each time the internet of things platform sends a piece of data to the message server, a new connection needs to be established with the message server, and in this scenario, the concurrency of data is relatively large, and the internet of things platform needs to frequently establish a connection with the message server, so that the stability of the internet of things platform is poor.
In order to solve the above problems, the embodiments of the present application provide a data interaction method, device and system.
Referring to fig. 1, fig. 1 is a schematic diagram illustrating an application scenario of a data interaction system of the present embodiment. The system may include: the system comprises an Internet of things platform 1, an application layer 3 and a device layer 2. Wherein at least one application 31 may be deployed in the application layer 3. The application 31 may include, but is not limited to, an application program running on an intelligent terminal such as a mobile phone or a tablet computer, and an application terminal device having computing capability and processing capability. The device layer may be deployed with a plurality of devices 21, and the devices 21 may include a variety of different types of sensors, e.g., temperature sensors, humidity sensors. The internet of things platform 1 can perform two-way communication with the application layer 3 and the equipment layer 2.
As shown in fig. 1, the application layer 3 and the internet of things platform 1 support the HTTP protocol. The internet of things platform 1 may record device basic information, which may be information entered in advance by a person. When the application 31 in the application layer 3 needs to acquire data with low requirements on real-time performance, such as equipment basic information, the application layer 3 can send an equipment basic information acquisition request through an HTTP protocol, and the internet of things platform 1 returns the equipment basic information to the application layer 3 through the HTTP protocol after receiving the equipment basic information acquisition request.
For the device control instruction sent to the device layer 2 by the application layer 3, the internet of things platform 1 can be implemented based on the MQTT publish/subscribe mode. In the MQTT publish/subscribe mode, the sender of the message is referred to as the publisher, the receiver of the message is referred to as the subscriber, and the container in which the server hosts the message is referred to as the topic. In the processing process of the message, the publisher publishes the message, the message carries topic information, the server stores the message into a corresponding topic based on the topic information, and the subscriber can acquire the message from the topic.
The internet of things platform 1 may provide a subscription service, and a subscriber may register subscription topic information with the internet of things platform 1. Specifically, as shown in fig. 1, a platform server 11 is deployed in the internet of things platform, and the platform server 11 may receive an application topic subscription request sent by a device in the device layer 2, where the application topic subscription request may be used to indicate an application topic subscribed by each device. Therefore, the internet of things platform 1 can record and store the application topics subscribed by each device in the device layer 2.
The internet of things platform 1 may receive, through the HTTP protocol, a device control instruction sent by the application layer 3, where the device control instruction carries a device identifier, for example, a device ID. After receiving the device control instruction, the platform server 11 in the internet of things platform 1 can convert the device control instruction into an instruction data format that can be identified by the device, determine the target device according to the device identifier, and determine the application theme subscribed by the target device according to the application theme subscribed by each device. Wherein each device uniquely corresponds to a device identifier.
After determining the application theme corresponding to the device identifier and the target device, the internet of things platform 1 may send the converted device control instruction to the corresponding application theme, so that the target device may obtain the converted device control instruction from the corresponding application theme. Therefore, the internet of things platform 1 realizes the transmission task of the equipment control instruction.
For data with high timeliness requirements such as the real-time state of the equipment and the heartbeat of the equipment and large concurrency, the data interaction between the application and the equipment can be realized based on a caching mechanism of the message server. Referring to fig. 1, the system may further include a message server 4, where the message server 4 is connected to the internet of things platform 1 and the application layer 3. The message server 4 may be, for example, a RabbitMQ server.
The caching mechanism of the message server is embodied in: the message server may store data sent upstream, especially in scenarios where the data concurrency is high. If the business capability of the downstream equipment is insufficient to process a large amount of data in a short time, the large amount of data sent by the upstream can be cached through a caching mechanism of the message server, so that the downstream equipment can disperse the cached large amount of data to process for a long time according to the business processing capability, and the stability of the system can be improved. For example, in fig. 1, the device layer 2 includes a large number of devices 21, and if the application 31 in the application layer 3 needs to obtain the first device data of the device layer 2, the first device data may include data with relatively high timeliness requirements, such as a real-time status of the device, and a relatively large concurrency amount. When the first device data in the device layer 2 is transmitted to the internet of things platform 1, the internet of things platform 1 may send the first device data to the message server 4 for caching (generally, the device data is cached in the message queue), and the application layer 3 obtains the real-time status data from the message queue.
The platform server 11 in the internet of things platform 1 may also respond to a device topic subscription request executed by the internet of things platform 1, where the device topic subscription request may be used to instruct the internet of things platform 1 to subscribe to a device topic, and the device topic may be used to store first device data published by each device in the device layer 2. In this way, when the platform server 11 receives the first device data sent by the device in the device layer, the device theme information carried by the device may be parsed, and the first device data may be stored in the device theme, so that the internet of things platform obtains the first device data from the device theme.
The plurality of applications in the application layer 3 may be divided into a plurality of groups. The internet of things platform 1 may store a correspondence between the device identifier and the group identifier, where the correspondence may be pre-established and stored in a storage module of the internet of things platform 1 according to an actual situation. Therefore, when the internet of things platform 1 receives the first device data, a target group can be determined according to the device identifier carried by the first device data, where the target group is one of multiple groups, and the target group may include at least one target application.
After acquiring the first device data and determining the target group, the internet of things platform 1 may send the first device data to the message server 4.
The internet of things platform 1 may pre-establish a first connection pool, where the first connection pool may be a connection pool for storing a plurality of first connection objects, and each first connection object in the first connection pool may be reused. The first connection object may be used to represent a data transmission channel between the internet of things platform 1 and the message server 4.
Every time the internet of things platform 1 sends a piece of first device data to the message server 4, a first connection object is obtained from the first connection pool, if the first connection object is obtained, the internet of things platform 1 can transfer the first device data to the consumption server 4 by calling the first connection object, and the message server 4 forwards the first device data to the target application. Therefore, the internet of things platform 1 does not need to create new connection every time a message is released, so that consumption of internet of things platform resources can be reduced, stability of the internet of things platform 1 can be improved, meanwhile, probability that the message server 4 frequently responds to connection creation operation in a short time can be reduced, and probability that the message server 4 collapses can be reduced.
The data interaction method according to the embodiment of the application is described in detail below.
Referring to fig. 2, fig. 2 is a flow chart of a data interaction method according to an embodiment of the application. The data interaction method of the embodiment is executed by an internet of things platform, and comprises the following steps of S11 to S13:
s11: and receiving the first device data sent by the device layer.
The first device data carries a device identifier. Illustratively, the device identification may include, but is not limited to, a device name, a device ID, and a device MAC address.
In one embodiment, the internet of things platform may receive, by way of HTTP, first device data sent by a device in a device layer. The first device data can be data with high real-time requirements such as the real-time state of the device, and the internet of things platform can simultaneously receive the first device data sent by one or more different devices and analyze the device identification information carried by each first device data.
In another embodiment, the internet of things platform may receive first device data sent by a device in a device layer based on an MQTT protocol. When the internet of things platform receives first equipment data sent by an application layer based on an MQTT protocol, the internet of things platform stores the first equipment data into an equipment theme corresponding to the equipment identifier.
S12: a target group is determined based on the device identification.
The target group may include one or more target applications.
In some embodiments, corresponding to the HTTP protocol transmission manner described above, the internet of things platform may determine the target group based on a pre-established correspondence between the device identifier and the group identifier. The corresponding relation can be established in advance for the application in the application layer according to the actual situation and stored in the Internet of things platform.
S13: if the first connection object is found in the first connection pool, the first device data is sent to the message server through the first connection object, so that the message server forwards the first device data to the target application.
The first connection pool may be a connection pool which is pre-established and is used for storing the first connection objects. The first connection object may be used to represent a data transmission channel between the internet of things platform and the message server.
In some embodiments, the internet of things platform may initiate a connection request to the message server when the first device data is received in the historical time, for example, when the first device data is received last time by the internet of things platform, so as to newly establish the first connection object in the first connection pool. Therefore, when the internet of things platform currently receives the first device data, the first connection object can be found in the first connection pool.
In this embodiment, after receiving the first device data sent by the device layer, the internet of things platform determines a target group based on the device identifier carried by the first device data, so as to determine a target application for receiving the first device data, and searches for a first connection object in the first connection pool. When the first connection object is found, the first device data is sent to the message server through the first connection object, so that the message server forwards the first device data to the target application. Through newly establishing and caching the first connection object in the first connection pool, the internet of things platform can repeatedly call the first connection object to transmit the first device data when transmitting the first device data to the message server each time, so that the operation of frequently establishing connection of the internet of things platform is greatly reduced, the probability of breakdown of the internet of things platform can be reduced under the scene of high data concurrency, the stability of the internet of things platform is maintained, and the probability of breakdown of the message server can be reduced.
In one embodiment, the method may further include S14:
s14: if the first connection object cannot be found in the first connection pool, a data transmission channel between the Internet of things platform and the message server is established so as to newly add the first connection object in the first connection pool, and the first device data is sent to the message server through the first connection object.
In this embodiment, if the internet of things platform does not find the first connection object in the first connection pool, it is indicated that there is no data transmission channel between the internet of things platform and the message server in the first connection pool, and at this time, the internet of things platform may initiate a connection request to the message server to establish the data transmission channel between the internet of things platform and the message server.
According to the embodiment, the first connection object is newly built in the first connection pool, and the first device data can still be transmitted through the first connection object when the Internet of things platform transmits the first device data through other subsequent threads based on the connection multiplexing mechanism of the connection pool, so that the operation of frequently building connection of the Internet of things platform is greatly reduced, and the stability of the Internet of things platform is improved.
In one embodiment, referring to fig. 3, fig. 3 is a schematic flow chart of steps S130a to S131a provided in the embodiment of the present application. After S12, S130a to S130b may be further included:
s130a: and determining a target group connection object according to the target group.
Wherein applications in the application layer are divided into different groups. For example, multiple applications managed by the same enterprise are divided into a group.
The internet of things platform can provide a group registration function, and can register each group and manage information of each group through the internet of things platform, wherein the information of the group can comprise a group ID, all applications contained in the group and the like. Therefore, after the target application is determined, the internet of things platform can determine the group corresponding to the target application.
In some embodiments, the internet of things platform may find the group connection object corresponding to the target group identifier after determining the group as the target group based on the pre-established object relationship between the group identifier and the group connection object, to obtain the target group connection object. Illustratively, the group identification may be a group ID.
Correspondingly, the first connection object in S13 may include a target group connection object, and S13 may include S131a:
s131a: if the target group connection object is found in the first connection pool, the first device data is sent to the message server through the target group connection object, so that the message server transmits the first device data to the target application.
The target group connection object may be used to represent a data transmission channel between the internet of things platform and the message server, and corresponds to the target group.
The first connection pool established by the internet of things platform can comprise a plurality of group connection objects, and after the internet of things platform determines the target group, the internet of things platform selects a target group connection object corresponding to the target group from the plurality of group connection objects and sends the first device data to the message server.
For example, assuming that the device identifier carried by the first device data is device id=1, the internet of things platform may determine, based on the correspondence between the device identifier and the group identifier, that the group corresponding to the first device data is a group with group id=1. The first connection pool established by the internet of things platform comprises a plurality of group connection objects, and after the internet of things platform determines that the group corresponding to the first device data is the group with the group ID=1. Assuming that the group with group id=1 corresponds to the 1 st group docking object, the 1 st group connection object is selected to send the first device data to the message server.
In some embodimentsThe first device data may carry routing key information that may be used to indicate a message queue in which the first device data is stored. Each group in the application layer may correspond uniquely to one application server, each application server establishing a long connection with a message server. Each application server may subscribe to each message queue to listen for messages in the subscribed message queues. When each application server monitors that the subscribed message queue has a message (for example, new first device data is stored in the message queue), the first device data is acquired from the message queue subscribed by each application server through the long connection corresponding to each application server and then forwarded to all applications corresponding to each application server
Since multiple applications in the application layer may belong to different groups, multiple devices in the device layer may also interface with applications in different groups. In order to meet the data isolation requirement and the safety transmission requirement, in the embodiment, the internet of things platform determines a target group according to the first device data, selects a corresponding target group connection object according to the target group to transmit the first device data to the message server, and transmits the first device data to the target application by the message server, so that the purposes of data isolation and safety transmission are achieved.
In one scenario, as shown in fig. 4, fig. 4 shows a schematic view of a scenario of group partitioning. In this scenario, the message servers to which the internet of things platform is connected may include, but are not limited to, a RabbitMQ server, a Kafka service, and a RocketMQ server. Taking a message server as a rabitmq server as an example, the rabitmq server may be deployed with a plurality of virtual hosts, each of which is equivalent to a virtual and less-performing rabitmq server. The internet of things platform may correspond each group to each tenant and one group to one tenant in response to a plurality of group operations divided by the application layer. Illustratively, as shown in fig. 4, group 1 corresponds to tenant 1 and group n corresponds to tenant n. The internet of things platform can allocate RabbitMQ sub-accounts and virtual hosts for each tenant. Each RabbitMQ sub-account is positioned on the RabbitMQ server, only the RabbitMQ sub-account is needed to be added when the tenant is newly added, and each tenant does not need to be distributed with one RabbitMQ server, so that the deployment cost of the server can be reduced.
Therefore, after the internet of things platform determines the target group according to the device identifier carried by the first device data, the internet of things platform can determine the target tenant and the target group connection object according to the target group, and send the first device data to the virtual host corresponding to the target tenant in the message server through the target group connection object. Applications in each tenant can only access data on the virtual host corresponding to each tenant, so that logical isolation of the data is formed.
Illustratively, taking the rabitmq server as an example, the process of establishing and acquiring the group connection objects may include: firstly, a connection pool interface is declared, and a tenant ID parameter is transmitted into the connection pool interface to create a connection object so that each group connection object can be created based on the tenant ID, and simultaneously, a concurrency dictionary is adopted to store each group connection object, wherein the concurrency dictionary is a thread safety set of key/value pairs which can be accessed by a plurality of threads at the same time, and is supported to be used in a multithreading concurrency scene. When each group connection object is acquired, the group connection object corresponding to each tenant may be acquired based on the tenant ID.
In one embodiment, referring to fig. 5, fig. 5 is a specific flowchart of S13 in the data interaction method provided in this embodiment. The step S13 may include steps S131 to S132:
S131: if the connection state of the first connection object is connection, the first connection object is acquired, and the first device data is sent to the message server through the first connection object.
In this embodiment, for a scenario in which the first connection object includes a plurality of group connection objects, the internet of things platform may only determine a connection state of the target group connection object, that is, after determining the target group, the internet of things platform searches for the target group connection object in the first connection pool. If the target group connection object is found in the first connection pool and the connection state of the target group connection object is connection, acquiring the resource of the target group connection object from the target group connection object, and calling the target group connection object to transmit the first device data to the message server.
S132: if the connection state of the first connection object is disconnected, reestablishing the first connection object so as to send the first device data to the message server through the reestablished first connection object.
In this embodiment, if the connection state of the first connection object is disconnected, it is indicated that the first connection object has been established before, but after the task is executed by other threads, the first connection object is closed, or the network environment is relatively bad, so that a data transmission channel between the internet of things platform and the message server is forcibly closed. For example, assume that when the internet of things platform sends the first device data corresponding to the device 1, a first connection object is constructed in the first connection pool, and the first device data corresponding to the device 1 is transmitted to the message server through the first connection object. After the first device corresponding to the device 1 is sent to the message server, the internet of things platform closes the connection between the internet of things platform and the message server, or the data transmission channel between the internet of things platform and the message server is disconnected due to the influence of the network environment disfigurement. When the internet of things platform searches the first connection object in the first connection pool when sending the first device data corresponding to the device 2, at this time, the connection state of the first connection object needs to be judged, if the connection state of the first connection object is disconnected, the internet of things platform can initiate a connection request to the message server to reestablish the first connection object, and after the first connection object is established, the first connection object is put into the first connection pool to be cached, so that subsequent use is facilitated.
For a scenario that the first connection object includes a plurality of group connection objects, the internet of things platform can only judge the connection state of the target group connection object, that is, after the internet of things platform determines the target group, the internet of things platform searches the first connection pool for the target group connection object, and judges whether to reconnect the data transmission channel corresponding to the target group connection object according to the connection state of the target group connection object.
In this embodiment, after the internet of things platform finds the first connection object in the first connection pool, the internet of things platform determines the connection state of the first connection object, and invokes the first connection object to transmit the first device data to the message server when the connection state of the first connection object is connection, thereby improving the success rate of the first device data transmission.
In one implementation, the foregoing embodiment may further include S15:
s15: after the first device data is sent to the message server, the resources of the first connection object are released and the first connection object is returned to the first connection pool.
In this embodiment, after the internet of things platform sends the first device data to the message server, the internet of things platform does not close a data transmission channel between the internet of things platform and the message server, but returns the first connection object to the first connection pool so as to be convenient for reuse.
According to the embodiment, after the first device data is sent to the message server, the internet of things platform releases the resources of the first connection object and returns the first connection object to the first connection pool, so that the first connection object can be used for realizing data transmission when other subsequent threads send the first device data, and multiplexing of connection is realized. Therefore, the Internet of things platform does not need to establish new connection with the message server every time when one piece of first equipment data is released, so that the resource consumption of the Internet of things platform and the message server is greatly reduced, and the stability of the Internet of things platform can be improved under the scene of large data concurrency.
In one embodiment, referring to fig. 6, fig. 6 is a schematic flow chart of S120a to S120b in the data interaction method provided in this embodiment. The above embodiment may further include S120a to S120b:
s120a: at least one routing key to which the device identification matches is determined.
Wherein the routing key is a key information for message routing. In a message server, the message server can determine which message queue to pass a message to by matching the routing key of the message so that the message recipient retrieves the message from the message queue. In this embodiment, the message queue is a queue established for storing messages for an application layer, and different applications may be bound with different message queues, for example, application 1 may bind a routing key to be a consumption queue with device id=1. In this embodiment, the platform of the internet of things includes a platform server, and the platform server in the platform of the internet of things may receive a device topic subscription request sent by each application in the application layer, where the device topic subscription request is used to indicate a device topic subscribed by each application. Thus, the internet of things platform can record and store the device topics subscribed by each application in the application layer. The internet of things platform can determine at least one routing key matched with the device identifier according to the device theme subscribed by each application and the corresponding relation between the pre-established device theme and the routing key.
For example, assume that multiple applications in the application layer belong to multiple different enterprises, and applications belonging to the same enterprise are divided into the same group. Applications in each group may subscribe to one or more device topics, which the applications subscribe to may include, but are not limited to, device topics of multiple dimensions, such as group ID, device model, and device ID.
Assume that an application in group 1 subscribes to a device topic of group ID 1, while also subscribing to a device topic of device type temperature sensor type. And the target application corresponding to the device 1 belongs to the device with the group ID of 1 and also belongs to the device with the temperature sensor type, the internet of things platform can determine that the routing key matched with the device 1 comprises the routing key with the group ID of 1 and the routing key with the device type of the temperature sensor type.
As shown in table 1 below, which gives one example of the mapping relationship of device topics to routing keys:
TABLE 1
Device theme type Device theme Routing key
Group by group Group ID Data_flow/tenant/pub/{tenantId}
By device type Device type ID Data_flow/model/pub/{model Id}
Press device Device ID Data_flow/device/pub/{deviceId}
S120b: and generating routing key information based on at least one routing key, adding the routing key information to the first device data, and packaging the first device data into a first message.
The internet of things platform can organize the first device data added with the routing key information according to a certain format, and encode the first device data by using a specific encoding mode to form a first message so as to be convenient for transmission in a network.
Correspondingly, the step S13 may include:
and sending the first message to the message server through the first connection object.
In the implementation, the internet of things application platform may send the first message to the message server through the first connection object, so that the message server stores the first message into the target message queues corresponding to the routing keys respectively based on the routing key information carried by the first message.
In the embodiment of the invention, the first message carries the routing key information, and the routing key information can be bound with a plurality of message queues. Meanwhile, the application in the application layer can bind the corresponding message queue according to the subscribed device theme. For example, if application 1 subscribes to a device topic with device ID 1 and a device topic with group ID 1, application 1 binds a message queue with device ID 1 and a consume queue with group ID 1. After the internet of things platform sends the first message to the message server, the message server stores the first device into a message queue with the device ID of 1 and a consumption queue with the group ID of 1 respectively, and when the application 1 acquires the first device data, the application 1 can acquire the first device data from the message queue with the device ID of 1 and the consumption queue with the group ID of 1.
In this embodiment, the internet of things platform determines at least one routing key matched with the device identifier based on the device identifier and in combination with subscription subject information configured by the application layer, and distributes the first device data to a message queue corresponding to each routing key for storage. Therefore, the application subscribed to the device theme corresponding to each routing key can acquire the first device data from the message queue corresponding to each routing key, so that the distribution of the messages can be carried out in combination with the actual situation, and the efficiency of message transmission is improved.
In one embodiment, the method may further comprise:
and receiving a device control instruction sent by an application layer. The device control instruction carries a device identifier. Illustratively, the device identification may include, but is not limited to, a device ID and a device MAC address.
And determining a target theme and target equipment based on the application identification, and sending equipment control instructions to the target theme.
And pulling the device control instruction from the target theme and sending the device control instruction to the target device.
For the device control instruction sent to the device layer by the application layer, the internet of things platform can be realized based on the MQTT publish/subscribe mode. Specifically, the internet of things platform may receive an application topic subscription request sent by a device in a device layer, where the application topic subscription request is used to indicate topics related to applications subscribed by each device, where the topics related to applications subscribed by the device may be divided according to a group ID and an application ID. The internet of things platform can determine a target theme and target equipment according to application identifiers based on the application theme subscribed by each equipment, and forward the equipment control instruction to the target equipment.
For example, assuming that a device with a device ID of 1 subscribes to a topic with an application ID of 1, the internet of things platform may determine that the target topic is a topic with an application ID of 1, store a device control instruction to the topic with an application ID of 1, and pull the device control instruction from the topic with an application ID of 1 to send to the device with a device ID of 1.
In the embodiment, the internet of things platform realizes the forwarding of the equipment control instruction based on the MQTT release/subscription mode, and because the internet of things platform realizes the data forwarding between the internet of things platform and the equipment layer based on the MQTT protocol, compared with the HTTP protocol, the occupied network overhead is smaller.
Referring to fig. 7, fig. 7 is a block diagram of a data interaction device 7 according to an embodiment of the present application. The data interaction device 7 is applied to an internet of things platform, and the data interaction device 7 comprises a receiving module 71, a determining module 72 and a sending module 73.
The receiving module 71 is configured to receive the first device data sent by the device layer. The first device data carries a device identifier.
The determining module 72 is configured to determine a target group based on the device identification; the target group comprises at least one target application.
The sending module 73 is configured to send the first device data to the message server through the first connection object if the first connection object is found in the first connection pool, so that the message server forwards the first device data to the target application. The first connection pool is a connection pool which is pre-established and used for storing the first connection objects; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server.
In an embodiment, the apparatus may further include a target group determining module, configured to determine a group corresponding to the target application, obtain a target group, generate target group identification information, and add the target group identification information to the first device data, and package the first device data into a first message.
Correspondingly, the sending module is specifically configured to: and if the target group connection object is found in the first connection pool, sending the first message to the message server through the target group connection object. The target group connection object is used for representing one connection established between the Internet of things platform and the message server, and the type of data allowed to be transmitted by the target group connection object is data carrying target group identification information.
In one embodiment, the transmitting module may include a first connection unit and a second connection unit. Wherein the first connection unit may be for: if the connection state of the first connection object is connection, the first connection object is acquired, and the first device data is sent to the message server through the first connection object.
The second connection unit may be configured to reestablish the first connection object if the connection state of the first connection object is disconnected, so as to send the first device data to the message server through the reestablished first connection object.
In one embodiment, the apparatus may further include a return module configured to release the resource of the first connection object after the first device data is sent to the message server, and return the first connection object to the first connection pool.
In one embodiment, the sending module may further be configured to: if the first connection object cannot be found in the first connection pool, a data transmission channel between the Internet of things platform and the message server is established so as to newly add the first connection object in the first connection pool, and the first device data is sent to the message server through the first connection object.
In one embodiment, the foregoing apparatus may further include a matching module, where the matching module is configured to determine at least one routing key to which the device identifier is matched after receiving the first device data sent by the device layer, generate routing key information based on the at least one routing key, and add the routing key information to the first device data, and encapsulate the first message.
The sending module may further include a sending unit, corresponding to the matching module, configured to send the first message to the message server through a first connection object.
In one embodiment, the transmitting unit may be configured to: and sending the first message to the message server through the first connection object, so that the message server stores the first message into a target message queue corresponding to each routing key respectively based on the routing key information carried by the first message.
In one embodiment, the apparatus may further include an instruction sending module, where the instruction sending module may be configured to:
and receiving a device control instruction sent by an application layer. The device control instruction carries an application identifier. The application identification may be, for example, an application ID.
And determining a target theme and target equipment based on the application identification, and sending equipment control instructions to the target theme.
And pulling the device control instruction from the target theme and sending the device control instruction to the target device.
It should be noted that, because the content of information interaction and execution process between the above devices is based on the same concept as the method embodiment of the present application, specific functions and technical effects thereof may be referred to in the method embodiment section, and will not be described herein.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, the specific names of the functional units and modules are only for distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The embodiment of the application also provides a data interaction system, and the structural block diagram of the data interaction system can be seen in fig. 1. The data interaction system comprises an application layer 3, an Internet of things platform 1, a device layer 2 and a message server 4. The Internet of things platform 1 is connected with the equipment layer 2 and the application layer 3.
The application layer 3 may include a plurality of applications 31, and the device layer 2 may include a plurality of devices 21.
In the data interaction system, a device layer 2 sends first device data to an internet of things platform 1, and the internet of things platform 1 receives the first device data sent by the device layer, wherein the first device data carries a device identifier. The internet of things platform 1 may determine the target group based on the device identification. The target group comprises at least one target application.
After determining the target group, the internet of things platform 1 searches for a first connection object in the first connection pool. If the first connection object is found in the first connection pool, the first device data is sent to the message server 4 via the first connection object. The first connection pool may be a connection pool which is pre-established and used for storing a first connection object, and the first connection object may be used for representing a data transmission channel between the internet of things platform 1 and the message server 4.
After receiving the first device data, the message server 4 sends the first device data to an application server corresponding to the target group in the application layer 3, so that the application server corresponding to the target group forwards the first device data to all target applications. The target application processes the first device data after receiving the first device number.
In an embodiment, the internet of things platform 1 may further determine the target group connection object based on the target group after determining the target group.
In this way, after the internet of things platform 1 obtains the first device data, the target group connection object can be found in the first connection pool, and if the target group connection object is found in the first connection pool, the first message is sent to the message server 4 through the target group connection object. If the target group connection object is not found in the first connection pool, the internet of things platform 1 may initiate a target group connection request to the message server 4 to create a new target group connection object and store the target group connection object in the first connection pool, so that the first message can be transmitted to the message server 4 through the current group connection object. The target group connection object may be used to represent a data transmission channel established by the internet of things platform 1 and the message server 4, where the target group connection object corresponds to the target group.
After receiving the first device data, the message server 4 may store the first device data in a corresponding message queue according to routing key information carried by the first device data, where the routing key information is used to indicate the message queue in which the first device data is to be stored. The application server corresponding to each target group may subscribe to a corresponding message queue according to the actual situation, for example, the message queue subscribed to by the application server 1 may be a message queue with message routing key information of device id=1. Each application server may establish a long connection with the message server and obtain the first device data from the message queue subscribed by each application server when it is monitored that the message queue subscribed by each application server has the first device data.
In an embodiment, after the internet of things platform 1 acquires the first device data, the at least one routing key matched with the device identifier may be further determined based on the device identifier carried by the first device data. After determining the at least one routing key, the internet of things platform 1 may generate routing key information based on the at least one routing key, and add the routing key information to the first device data to package the first message. The internet of things platform 1 may send the first message to the message server 4 through the first connection object, so that the message server 4 stores the first message into the target message queues corresponding to the routing keys respectively based on the routing key information carried by the first message. Thus, an application in the application layer 3 that binds the target message queue may read the first message from the target message queue.
In one embodiment, in the system described above, the internet of things platform 1 may receive an application topic subscription request sent by a device 21 in the device layer 2, where the application topic subscription request is used to indicate topics related to applications subscribed by each device.
The internet of things platform 1 receives a device control instruction sent by the application layer 3, where the device control instruction may carry a device identifier. The internet of things platform 1 can determine a target theme and target equipment according to application identifiers based on application themes subscribed by the equipment, and send equipment control instructions to the target theme for storage. The internet of things platform can pull the device control instruction from the target theme and send the device control instruction to the target device.
The above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (10)

1. A method of data interaction, comprising:
receiving first device data sent by a device layer; wherein, the first device data carries a device identifier;
determining a target group based on the device identification; the target group comprises at least one target application;
if a first connection object is found in a first connection pool, sending the first device data to a message server through the first connection object so as to forward the first device data to the target application by the message server; the first connection pool is a connection pool which is pre-established and used for storing a first connection object; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server.
2. The data interaction method of claim 1, further comprising, after said determining a target group based on said device identification:
determining a target group connection object according to the target group;
correspondingly, the first connection object comprises a target group connection object; if a first connection object is found in the first connection pool, sending the first device data to a message server through the first connection object, including:
If the target group connection object is found in the first connection pool, sending the first device data to the message server through the target group connection object; the target group connection object is used for representing one data transmission channel between the internet of things platform and the message server, and corresponds to the target group.
3. The data interaction method of claim 1, wherein if a first connection object is found in the first connection pool, sending the first device data to a message server through the first connection object comprises:
if the connection state of the first connection object is connection, acquiring the first connection object, and sending the first device data to the message server through the first connection object;
and if the connection state of the first connection object is disconnected, reestablishing the first connection object so as to send the first device data to the message server through the reestablished first connection object.
4. The data interaction method of claim 1, wherein the method further comprises:
And after the first device data is sent to the message server, releasing the resources of the first connection object, and returning the first connection object to the first connection pool.
5. The data interaction method of claim 1, wherein the method further comprises:
if the first connection object cannot be found in the first connection pool, a data transmission channel between the Internet of things platform and the message server is established so as to newly add the first connection object in the first connection pool, and the first device data is sent to the message server through the first connection object.
6. The data interaction method of claim 1, further comprising, after the receiving the first device data sent by the device layer:
determining at least one routing key to which the device identification matches;
generating routing key information based on the at least one routing key, adding the routing key information to the first device data, and then packaging the first device data into a first message;
correspondingly, the sending the first message to the message server through the first connection object includes:
and sending the first message to the message server through the first connection object.
7. The data interaction method of claim 6, wherein the sending the first message to the message server through the first connection object comprises:
and sending the first message to the message server through the first connection object, so that the message server stores the first message into a target message queue corresponding to each routing key respectively based on the routing key information carried by the first message.
8. The data interaction method of claim 1, wherein the method further comprises:
receiving a device control instruction sent by an application layer; wherein, the equipment control instruction carries an equipment identifier;
determining a target theme and target equipment based on the equipment identifier, and sending the equipment control instruction to the target theme;
and pulling the equipment control instruction from the target theme, and sending the equipment control instruction to the target equipment.
9. A data interaction device, comprising:
the receiving module is used for receiving the first device data sent by the device layer; wherein, the first device data carries a device identifier;
A determining module, configured to determine a target group based on the device identifier; the target group comprises at least one target application;
the sending module is used for sending the first equipment data to a message server through the first connection object if the first connection object is found in the first connection pool so as to forward the first equipment data to the target application through the message server; the first connection pool is a connection pool which is pre-established and used for storing a first connection object; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server.
10. The data interaction system is characterized by comprising an application layer, an Internet of things platform, a device layer and a message server; the Internet of things platform is connected with the equipment layer and the application layer;
the device layer is used for sending first device data to the Internet of things platform;
the internet of things platform is used for receiving first equipment data sent by the equipment layer; the first device data carries a device identifier; and further configured to determine a target group based on the device identification; if a first connection object is found in the first connection pool, the first equipment data is sent to a message server through the first connection object; the target group comprises at least one target application; the first connection pool is a connection pool which is pre-established and used for storing first connection objects; the first connection object is used for representing a data transmission channel between the internet of things platform and the message server;
The message server is configured to receive the first device data and send the first device data to a target application in the application layer.
CN202311184573.XA 2023-09-14 2023-09-14 Data interaction method, device and system Pending CN117176782A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311184573.XA CN117176782A (en) 2023-09-14 2023-09-14 Data interaction method, device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311184573.XA CN117176782A (en) 2023-09-14 2023-09-14 Data interaction method, device and system

Publications (1)

Publication Number Publication Date
CN117176782A true CN117176782A (en) 2023-12-05

Family

ID=88931601

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311184573.XA Pending CN117176782A (en) 2023-09-14 2023-09-14 Data interaction method, device and system

Country Status (1)

Country Link
CN (1) CN117176782A (en)

Similar Documents

Publication Publication Date Title
CN106230896B (en) A kind of information push method, apparatus and system
US11411897B2 (en) Communication method and communication apparatus for message queue telemetry transport
US10367852B2 (en) Multiplexed demand signaled distributed messaging
CN109756559B (en) Construction and use method for distributed data distribution service of embedded airborne system
US8447881B2 (en) Load balancing for services
CN103312528B (en) A kind of heartbeat message sending method and user terminal
CN107528891B (en) Websocket-based automatic clustering method and system
US20030126196A1 (en) System for optimizing the invocation of computer-based services deployed in a distributed computing environment
CN111212085B (en) Method for synchronously calling Internet of things platform, internet of things system and network equipment
CN100558109C (en) The load balancing implementation method and the system of dialogue-based initiation protocol
US8606908B2 (en) Wake-up server
WO2023221452A1 (en) Packet processing system and method, device, and storage medium
CN106970843B (en) Remote calling method and device
CN110635932A (en) OpenStack control plane-based virtual network performance optimization method
CN108259605B (en) Data calling system and method based on multiple data centers
WO2024032094A1 (en) Instant messaging system and method
CN116800787A (en) Vehicle-mounted communication method and system based on Ethernet communication protocol
CN116405547A (en) Message pushing method and device, processor, electronic equipment and storage medium
CN117176782A (en) Data interaction method, device and system
CN113992740B (en) Middleware based on autonomous control and data transmission method
CN114024968B (en) Message sending method and device based on intermediate equipment and electronic equipment
CN114500341A (en) Terminal real-time control method and control server under wide area network
CN111294383B (en) Internet of things service management system
CN110474781B (en) Method and device for forwarding multicast data
CN111541667A (en) Method, equipment and storage medium for intersystem message communication

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication