Data query method, data query link system, electronic equipment and storage medium
By establishing a long WebSocket link between the front-end and the back-end, active data push in the back-end is realized and data query link is optimized, which solves the problems of low data query efficiency and device performance in the existing technology, improves real-time data query efficiency and reduces the performance pressure when playing back data query.
Patent Information
- Application Number
- CN202510169195.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-17
- Publication Date
- 2025-03-14
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, data query efficiency is low and depends on device performance, resulting in delays in real-time data display, which puts huge pressure on the database and server when replaying data query.
By establishing a long WebSocket link between the front-end and the back-end, active data push in the back-end is realized, data query link is optimized, real-time data query efficiency is improved, and data is pushed in batches when replaying data query to reduce performance pressure.
It solves the problems of low efficiency of real-time data query and relying on server performance, improves real-time data query efficiency, and significantly reduces the performance pressure on database, server and front-end devices when replaying data query.
Smart Images

Figure CN119621738A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of Internet of Things, and in particular to a data query method, a data query link system, an electronic device and a storage medium. Background Art
[0002] With the development of technologies such as the Internet of Things, industrial control, and smart homes, a large number of devices and sensors need to collect and transmit data in real time. These data usually need to be displayed in real time to monitor the operating status of the device or related indicator information. At the same time, these data need to be stored and processed for later data analysis or data playback. At present, device data is generally collected through edge devices, and then messages are forwarded through the Internet of Things general message protocol. The backend stores the data through message queues.
[0003] In the prior art, when querying real-time data, the front end usually uses polling to request the back end interface, and the back end then queries the time series data through polling and returns the data to the front end for data display. When querying playback data, the front end passes the time interval to be queried to the back end, and the back end constructs query parameters based on the time interval and returns the query results to the front end at one time.
[0004] However, when using existing technical solutions for real-time data query, there is a certain delay in data display. When playing back data query, if the query time span is large, the amount of queried data will also be large, which will cause huge pressure on the services on the data link. In addition, the efficiency of data query in the existing technology depends on the performance of the client and the server. Summary of the invention
[0005] The purpose of this application is to provide a data query method, a data query link system, an electronic device and a storage medium to address the deficiencies in the above-mentioned prior art, so as to solve the problem that data query efficiency in the prior art is low and depends on device performance.
[0006] To achieve the above objectives, the technical solutions adopted in this application are as follows: In a first aspect, the present application provides a data query method, which is applied to a data query link system, wherein the data query link system includes: a target application deployed at the front end, a data query service, a data subscription service, a message queue, and a time series database deployed at the back end, wherein the data subscription service is connected to the message queue and the time series database, and the data query service is connected to the time series database. The method includes: The data subscription service receives the real-time data in the message queue, pre-processes the real-time data to obtain processed data, sends the processed data to the data query service, and stores the processed data in the time series database; The target application establishes WebSocket communication with the data query service, and sends a data query request to the data query service, wherein the request type of the data query request includes: a real-time data query request or a playback data query request; If the data query request is a real-time data query request, the data query service determines whether the processed data is the data requested by the data query request, and if so, pushes the processed data to the target application; If the data query request is a playback data query request, the data query service determines the target data requested by the data query request from the time series database according to the data query request, and pushes the target data to the target application.
[0007] Optionally, the data subscription service receives the real-time data in the message queue, pre-processes the real-time data to obtain processed data, and pushes the processed data to the data query service and the time series database, including: The data subscription service subscribes to the message queue; The data subscription service monitors the message queue. If the data in the message queue is updated, the data subscription service obtains the newly added real-time data from the message queue and pre-processes the real-time data to obtain the processed data. The data subscription service stores the processed data in the time series database, and sends the processed data to the data query service.
[0008] Optionally, after the target application establishes WebSocket communication with the data query service and sends a data query request to the data query service, the process further includes: The data query service parses the data query request, obtains subscription information of the data query request, and stores the subscription information of the data query request in a memory cache.
[0009] Optionally, when the data query request is a real-time data query request, the data query request includes: subscription information, and the subscription information includes: a device identifier and a data identifier of the data to be queried; The data query service determines whether the processed data is data corresponding to the data query request, and if so, pushes the processed data to the target application, including: The data query service matches the processed data with the subscription information in the memory cache. If the device identifier of the processed data is the same as the device identifier in the subscription information, and the data identifier of the processed data matches the data identifier indicated by the subscription information, the processed data is pushed to the target application.
[0010] Optionally, when the data query request is a playback data query request, the data query request includes: subscription information, a request time interval, and the request time interval is used to indicate the start time and end time of the data to be queried; The data query service determines target data corresponding to the data query request from the time series database according to the data query request, and pushes the target data to the target application, including: The data query service generates a data query statement according to the subscription information and the request time interval in the data query request; The data query service executes the data query statement to query the target data from the time series database and saves the target data in the memory; The data query service reads the target data from the memory and sends the target data to the target application according to a preset data sending strategy.
[0011] Optionally, the data query service reads the target data from the memory and sends the target data to the target application according to a preset data sending strategy, including: The data query service determines the data sending frequency according to the request time interval; The data query service determines the target data to be sent corresponding to the current time, reads the target data to be sent from the memory according to the data sending frequency, and sends the target data to be sent to the target application.
[0012] Optionally, the data query service determines the target data to be sent corresponding to the current time, reads the target data to be sent from the memory according to the data sending frequency, and sends the target data to be sent to the target application, including: The data query service determines the first target data to be sent corresponding to the current time, reads the first target data to be sent from the memory, and sends the first target data to be sent to the target application; The data query service stops for a preset time period under the instruction of the data sending frequency; The data query service determines second target data to be sent corresponding to a target time, reads the second target data to be sent from a memory and sends the second target data to the target application, wherein the target time is the time after the data query service stops for a preset period of time.
[0013] In the second aspect, the present application provides a data query link system, which includes: a target application deployed on the front end, a data query service, a data subscription service, a message queue and a time series database deployed on the back end, the data subscription service is connected to the message queue and the time series database, the data query service is connected to the time series database, and the system is used to execute the steps of the data query method described in the first aspect.
[0014] In the third aspect, an embodiment of the present application also provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to perform the steps of the data query method as described in any one of the first aspects.
[0015] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data query method as described in any one of the first aspects are executed.
[0016] The beneficial effects of this application are: by establishing a WebSocket long link between the front-end device and the back-end service, it is ensured that the back-end service can respond to the request of the front-end device in a timely manner. By actively pushing data through the back-end, the data query link is shortened, the problem of low efficiency and dependence on server performance of real-time data query is solved, and the efficiency of real-time data query is improved. When replaying data query, the data query service queries the target data from the database and pushes the target data to the front-end device in batches, thereby greatly reducing the pressure on the database, server and front-end device performance when the data playback time span is large.
[0017] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A schematic diagram of the architecture of a data query system provided by an embodiment of the present application is shown; Figure 2 A schematic diagram of the architecture of a data query link system provided by an embodiment of the present application is shown; Figure 3 A flow chart of a data query method provided by an embodiment of the present application is shown; Figure 4 A flowchart of querying real-time data provided by an embodiment of the present application is shown; Figure 5 An overall flow chart of querying real-time data provided by an embodiment of the present application is shown; Figure 6 A flowchart of querying playback data provided by an embodiment of the present application is shown; Figure 7 A flow chart showing a data query service sending playback data provided by an embodiment of the present application is shown; Figure 8 A flowchart of sending playback data by another data query service provided by an embodiment of the present application is shown; Fig. 9 An overall flow chart of querying playback data provided by an embodiment of the present application is shown; Fig.10 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0020] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0021] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0022] In the fields of industrial control, Internet of Things, and smart home, after devices and sensors collect data in real time, they usually transmit the data to front-end devices for real-time display to monitor the operating status of the equipment and related indicator information. At the same time, in order to trace problems during the operation of the equipment, the data of the equipment also needs to be stored and processed for subsequent data analysis and data playback.
[0023] The data link for data collection and data playback in the prior art is as follows Figure 1 As shown, it includes edge acquisition devices and sensors, back-end servers, and front-end display devices. After the acquisition device acquires real-time data, it can forward messages through the IoT general message protocol (Message Queuing Telemetry Transport, MQTT), and the back-end server stores the data by connecting to MQTT. When displaying data, the user initiates a data query request at the front end, and the front-end device requests the back-end interface by polling. The back-end then constructs relevant query parameters through the polling interval, queries the time series data, and returns it to the front end for data display.
[0024] However, since the existing technology uses polling to query real-time data, there will be a certain delay in data display. Figure 1 After the front-end device initiates a data query request to the back-end server through polling, the back-end server needs to construct query parameters based on the data query request, and obtain the corresponding data from the data storage server based on the query parameters, and then process the data, and send the processed data to the front-end device for data display. It can be seen that when performing real-time data query, if you want to reduce latency based on existing technologies, you need to shorten the request interval, which requires improving the performance of the front-end device and the back-end server. In addition, this method needs to ensure that the time of the back-end server is consistent with that of the data storage server, otherwise once the time construction of the query parameters deviates, it will cause inaccurate data query problems.
[0025] When replaying data, continue to refer to Figure 1 The front-end device transmits the time interval of the data to be queried to the back-end server. The back-end server constructs query parameters based on the time interval, obtains all data from the data storage server based on the query parameters, and returns the query results to the front-end device at one time.
[0026] During this process, the back-end server obtains the data query results based on the start time and end time provided by the front-end device, and returns the data query results to the front-end device at one time. Once the time interval of the data spans a large amount, the amount of data in the data query result will also be large, which will cause tremendous pressure on the services on the entire data link. If the server performance is poor or there is a limit on the network bandwidth, the playback data query may fail.
[0027] Based on this, this application proposes a data query method, which establishes a WebSocket long link between the front-end device and the back-end service, thereby ensuring that the back-end service can respond to the request of the front-end device in a timely manner. By actively pushing data through the back-end, the problem of low efficiency of real-time data query and dependence on server performance is solved. When replaying data query, part of the data is pushed to the front-end device each time according to the setting parameters of the front-end device query data for data display, thereby solving the problem of high performance pressure on the database, server and front-end device when the data playback time span is large.
[0028] Figure 2 This is a schematic diagram of the architecture of a data query link system given in this application, refer to Figure 2 The system includes: a target application deployed on the front-end device, a data query service, a data subscription service, a message queue, and a time series database deployed on the back-end. Among them, the back-end data query service, data subscription service, message queue, and time series database can be deployed on the same server or on different servers. After the edge devices and sensors collect real-time data, the real-time data can be stored in the message queue. The data subscription service is connected to the message queue and can subscribe to real-time data from the message queue. The data subscription service is also connected to the time series database, and the data query service is connected to the time series database and the data subscription service.
[0029] In one possible implementation, the front-end device can be connected to a large screen. The user initiates a data query request to the back-end server through the front-end device, and after obtaining the data query result returned by the back-end server, the data query result can be displayed on the large screen connected to the front-end device.
[0030] It should be noted that this application only uses time series data as an example to illustrate the process of real-time data query and playback data query. In some application scenarios, the data to be queried may be relational data or media data, such as the device operation trajectory collected by the device, image data collected by the device, etc. At this time, the time series database can be replaced with a relational database or a database that can store media data. The specific implementation method shall be based on the actual needs of the application scenario, and this application does not limit the type of database.
[0031] Next, combine Figure 3 The data query method of the present application is described, and the method can be applied to Figure 2 In the data query link system shown in FIG. Figure 3 , the method comprising: S301. The data subscription service receives real-time data in the message queue, pre-processes the real-time data to obtain processed data, sends the processed data to the data query service, and stores the processed data in the time series database.
[0032] Among them, the message queue can be connected to the data acquisition device and the sensor at the edge. After the data acquisition device and the sensor acquire the real-time data, the real-time data and the device identifier of the device to which the real-time data belongs can be stored in the message queue.
[0033] The message queue can include multiple topics, each of which is used to store the collected data of different devices. For example, the collected data of devices of the same device type are stored in the same topic of the message queue, or the collected data of devices of the same deployment scenario are stored in the same topic of the message queue according to the deployment scenario of the device, or the same data type of different devices are stored in the same topic of the message queue. The message queue can be middleware such as Kafka and RabbitMQ to ensure high throughput and reliability of data.
[0034] Optionally, the data subscription service can subscribe to a specified topic in the message queue and receive real-time data from the message queue included in the subscribed topic. The real-time data exists in the form of messages in the message queue. After receiving the message, the data subscription service parses the message to obtain the real-time data, and obtains the processed data after filtering and preprocessing the real-time data.
[0035] The data subscription service and the data query service can communicate through the Hypertext Transfer Protocol (HTTP) interface. The data subscription service can push the processed data to the data query service through the HTTP interface, and at the same time store the processed data in the time series database according to the timestamp of the processed data.
[0036] Optionally, the time series database may be InfluxDB, in which the processed data of each device and each sensor are arranged in sequence according to timestamps.
[0037] S302: The target application establishes WebSocket communication with the data query service, and sends a data query request to the data query service. The request type of the data query request includes: a real-time data query request or a playback data query request.
[0038] Optionally, the target application is deployed on a front-end device and provides an accessible interface through a browser of the front-end device. The user can select the data to be viewed on the browser of the front-end device, and the browser generates a data query request based on the user's instruction and sends the data query request to the data query service.
[0039] Optionally, the types of data query requests include real-time data query requests and playback data query requests. The real-time data query request is used to query real-time data, and the playback data query request is used to query historical data and play back the historical data according to user instructions.
[0040] The real-time data query request includes: the device identifier and the requested data identifier. The device identifier is used to indicate the device to which the data to be queried belongs, and the requested data identifier can be the field information of the data. The playback data query request includes: the device identifier, the requested data identifier, and the time interval of the data to be queried. The time interval of the data to be queried includes: the start time of the data to be queried and the end time of the data to be queried.
[0041] Optionally, before initiating a data query request, the front-end device where the target application is located and the data query service can establish WebSocket communication and maintain a long connection state. After receiving the data query request sent by the target application, the data query service can parse the data query request, obtain the request type of the data query request, and record the device identifier of the front-end device currently establishing WebSocket communication, the request type of the current data query request, and the data identifier of the data requested by the current data query request as the subscription information of the current WebSocket connection.
[0042] S303: If the data query request is a real-time data query request, the data query service determines whether the processed data is the data requested by the data query request, and if so, pushes the processed data to the target application.
[0043] The data query service can continuously receive real-time data sent by the data subscription service. When the data query service receives a real-time data query request from a front-end device, it can compare the received processed data with the real-time data query request. If the processed data meets the conditions of the real-time data query request, the data query service can push the processed data to the target application that initiated the data query request on the front-end device.
[0044] It should be noted that the data query service can establish WebSocket communication with the target applications of multiple front-end devices and record subscription information. At the same time, the data query service can receive processed data from multiple devices. After receiving the processed data, the data query service can compare the processed data with all saved subscription information. If the subscription information indicates that the data query request is a real-time data query request, and the device identifier of the processed data is consistent with the device identifier in the data query request, and the data identifier of the processed data is consistent with the data identifier in the data query request, then the processed data is the data requested by the data query request.
[0045] S304: If the data query request is a playback data query request, the data query service determines the target data requested by the data query request from the time series database according to the data query request, and pushes the target data to the target application.
[0046] Optionally, the playback data query request includes a device identifier, a requested data identifier, and a time interval to be queried. The data query service can generate a database query statement based on the playback data query request, and query the target data from the time series database.
[0047] It should be noted that the data query service can push part of the data to the target application each time, and the frequency of pushing data can be determined according to the time interval of the data or the time interval of the data query. For example, if the data is aggregated in seconds, the data query service can push one piece of data to the target application every second.
[0048] The playback data query request may also include playback parameters to indicate the order of data playback and the rate of data playback. Exemplarily, the order of data playback may be reverse playback, indicating that the data is played back from the end time. The rate of data playback indicates the frequency at which the data query service pushes data to the target application, which may be determined based on the time interval of the data, or based on the time interval of the data query, or based on the time interval, or may be customized by the user, and this application does not limit this.
[0049] Optionally, after obtaining the target data from the time series database, the data query service may cache the query result in memory first, and push the data to the target application at the data playback rate indicated in the playback data query request.
[0050] In an embodiment of the present application, a data subscription service receives real-time data in a message queue, pre-processes the real-time data to obtain processed data, sends the processed data to a data query service, and stores the processed data in a time series database. A target application establishes WebSocket communication with the data query service, and sends a data query request to the data query service. The request types of the data query request include: a real-time data query request or a playback data query request. If the data query request is a real-time data query request, the data query service determines whether the processed data is the data requested by the data query request. If so, the processed data is pushed to the target application. If the data query request is a playback data query request, the data query service determines the target data requested by the data query request from the time series database according to the data query request, and pushes the target data to the target application.
[0051] By establishing a WebSocket long link between the front-end device and the back-end service, the back-end service can respond to the request of the front-end device in a timely manner. By actively pushing data through the back-end, the data query link is shortened, the problem of low efficiency of real-time data query and dependence on server performance is solved, and the efficiency of real-time data query is improved. When replaying data query, the data query service queries the target data from the database and pushes the target data to the front-end device in batches, thereby greatly reducing the pressure on the database, server and front-end device performance when the data playback time span is large.
[0052] The following is a further description of the above data subscription service receiving real-time data in the message queue, preprocessing the real-time data, obtaining processed data, and pushing the processed data to the data query service and time series database. Figure 4 As shown, the above step S301 includes: S401. The data subscription service subscribes to a message queue.
[0053] It should be understood that multiple data subscription service instances can be deployed in the server. This application uses the operation process of a data subscription service instance that processes time series data as an example for explanation. A message queue can store multiple types of data, including time series data, media data, and relational data. Each data subscription service instance can be used to subscribe to and process a type of data, for example, data subscription service instance 1 subscribes to and processes time series data, data subscription service instance 2 subscribes to and processes media data, and data subscription service instance 3 subscribes to and processes relational data.
[0054] Among them, different topics in the message queue can correspond to different data types. After the data subscription service subscribes to the message queue, when the message in the message queue is updated, the latest message in the subscribed message queue can be obtained.
[0055] S402: The data subscription service monitors the message queue. If the message in the message queue is updated, the data subscription service obtains the newly added real-time message from the message queue and pre-processes the real-time message to obtain processed data.
[0056] In the first implementation, the data subscription service can monitor the messages in the message queue. If the number of messages in the message queue is updated, such as the number increases, or the identifier of the latest message changes, the newly added real-time data can be obtained from the message queue and pre-processed. The data subscription service can save the identifier of the most recently obtained message and obtain incremental data from the message queue based on the identifier of the most recently obtained message.
[0057] In the second implementation, when new messages are added to the message queue and the number of new messages reaches a preset threshold, the message queue can actively push the new messages to the message subscription service that has subscribed to the current message queue.
[0058] Among them, the data subscription service can parse the message, obtain the fields of the data contained in the message, and pre-process the data of each field separately, such as performing precision processing on fields containing numbers, or filtering the data of some fields based on preset data thresholds.
[0059] S403: The data subscription service stores the processed data in a time series database, and sends the processed data to the data query service.
[0060] The data subscription service can store the processed data in a time series database according to timestamps and send the processed data to the data query service.
[0061] After the target application establishes WebSocket communication with the data query service and sends a data query request to the data query service, the following steps are also included: The data query service parses the data query request, obtains the subscription information of the data query request, and stores the subscription information of the data query request in the memory cache.
[0062] The subscription information includes the device identification of the front-end device that establishes WebSocket communication with the data query service, the request type of the current data query request, and the data identification of the data requested by the current data query request, and the subscription information of the data query request is stored in the memory cache.
[0063] After the data query service receives the processed data pushed by the data subscription service, it can check all saved subscription information and match the request type of real-time data query requests in the subscription information one by one. If the device identifier of the processed data and the data identifier of the processed data are consistent with the subscription information, the processed data can be pushed to the front-end device corresponding to the subscription information.
[0064] Optionally, when the data query request is a real-time data query request, the data query request includes: subscription information, and the subscription information includes: a device identifier and a data identifier of the data to be queried.
[0065] The data identifier of the data to be queried may be a field of the data to be queried, and the device identifier may be a unique identifier of a sensor or device to which the data belongs, such as a device serial number or a sensor serial number.
[0066] The data query service determines whether the processed data is data corresponding to the data query request. If so, the step of pushing the processed data to the target application includes: The data query service matches the processed data with the subscription information in the memory cache. If the device identifier of the processed data is the same as the device identifier in the subscription information, and the data identifier of the processed data matches the data identifier indicated by the subscription information, the processed data is pushed to the target application.
[0067] After receiving the processed data, the data query service may check all subscription information whose request type is a real-time data query request, and compare the device identifier and data identifier in the subscription information with the device identifier and data identifier in the processed data.
[0068] The data identifier of the processed data matches the data identifier indicated by the subscription information, and the data identifier in the subscription information may include the data identifier of the processed data, that is, the fields of the two are the same.
[0069] Next, combine Figure 5 , the process of real-time data query in this application is described. Figure 5 After the front-end application establishes a WebSocket long link with the data query service, it can send a real-time data query request to the data query service. After the data query service receives the real-time data query request, it can record the subscription information of the real-time data query request.
[0070] At the same time, the data subscription service can subscribe to the data in the specified message queue and accept the push of the message queue. After receiving the pushed message, the data subscription service can parse the message to obtain real-time data, pre-process the real-time data, obtain the processed data, and push the processed data to the data query service through the HTTP interface.
[0071] After receiving the processed data, the data query service can match the processed data with the subscription information. If there is matching subscription information, the data query service can push the processed data to the front-end application corresponding to the subscription information in the form of a WebSocket message.
[0072] Optionally, when the data query request is a playback data query request, the data query request includes: subscription information and a request time interval, where the request time interval is used to indicate a start time and an end time of the data to be queried.
[0073] The above data query service determines the target data corresponding to the data query request from the time series database according to the data query request, and pushes the target data to the target application, such as Figure 6 As shown, including: S601: The data query service generates a data query statement according to the subscription information and the requested time interval in the data query request.
[0074] S602: The data query service executes a data query statement to obtain target data from the time series database and save the target data in memory.
[0075] The data query service can determine the time range of the data to be searched based on the request time interval, and determine the data to be searched and the device to which the data belongs based on the subscription information, thereby generating a data query statement.
[0076] It is worth noting that after the data query service obtains the target data through query, it can also process the target data according to user-defined rules, such as calculating the average, maximum, minimum, etc. of the target data, obtain the processed target data, and send the processed target data to the target application.
[0077] S603: The data query service reads the target data from the memory and sends it to the target application according to the preset data sending strategy.
[0078] After the data query service executes the data query statement and obtains the target data, it can save the target data in the memory and send the target data to the target application according to the playback frequency indicated by the data query request.
[0079] The preset sending strategy includes: the frequency of sending data and the order of sending data. The sending strategy can be predefined or determined based on user-defined playback parameters, which is not limited in this application.
[0080] The frequency of sending data can be the same as the time interval of the data. For example, if the data is aggregated in seconds, the data query service can push one piece of data to the target application every second. The amount of data sent each time can also be determined based on the user-defined data sending frequency and the data time interval. For example, if the user-defined data sending frequency is 2, it means that the playback data rate is twice the speed. If the data is aggregated in seconds, the data query service can push two pieces of data to the target application every second.
[0081] The above data query service reads the target data from the memory and sends it to the target application according to the preset data sending strategy, such as Figure 7 As shown, it also includes: S701. The data query service determines a data sending frequency according to a requested time interval.
[0082] Optionally, different request time intervals may correspond to different data sending frequencies. For example, when the data request time interval is larger, the data sending frequency may be larger; when the data request time interval is smaller, the data sending frequency may be smaller, thereby reducing the amount of data sent each time by the data query service and alleviating the pressure on each device on the data link.
[0083] S702: The data query service determines the target data to be sent corresponding to the current time, reads the target data to be sent from the memory according to the data sending frequency, and sends the target data to be sent to the target application.
[0084] The data query service can determine the amount of data to be sent each time based on the data sending frequency, so that before sending the data, the target data to be sent this time is first determined, and the target data to be sent is read from the memory according to the data sending frequency.
[0085] For example, assuming that the requested time interval is data within the past 24 hours, and the data sending frequency determined based on the requested time interval is to send one hour of data per second, the data query service can obtain one hour of data as the target data to be sent every second, and send the target data to be sent to the target application.
[0086] The following is a further description of the above data query service determining the target data to be sent corresponding to the current time, reading the target data to be sent from the memory according to the data sending frequency, and sending the target data to be sent to the target application, such as Figure 8 As shown, the above step S702 includes: S801. The data query service determines first target data to be sent corresponding to the current time, reads the first target data to be sent from the memory, and sends the first target data to be sent to the target application.
[0087] Among them, the data query service can read the data in the requested time interval from the memory in sequence according to the order indicated by the playback parameters. After the amount of data N sent at each moment is determined based on the data sending frequency, N data can be read from the memory in sequence at each moment as the first target data to be sent, and the first target data to be sent is sent to the target application.
[0088] S802: The data query service stops for a preset time period under the instruction of the data sending frequency.
[0089] S803: The data query service determines the second target data to be sent corresponding to the target time, reads the second target data to be sent from the memory and sends it to the target application. The target time is the time after the data query service stops for a preset period of time.
[0090] The preset duration may be one second. For example, after sending N data in the first second, the data query service may sleep for one second, determine the second target data to be sent in the third second, and continue to send data to the target application. Stopping the preset duration after sending the data can ensure that the time axis of the sent target data is consistent with the actual time axis of the front-end application playback data.
[0091] Reference Fig. 9 , is a flowchart of a playback data query given in this application. Fig. 9 After the front-end application establishes a WebSocket long link with the data query service, it can send a real-time data query request to the data query service. After receiving the real-time data query request, the data query service can generate a data query statement based on the playback data query request, obtain the target data from the time series database and save the target data in memory.
[0092] The data query service can divide the target data into multiple batches and send them, sleeping for one second between sending each batch of data to simulate the smoothness of real data playback.
[0093] Based on the same inventive concept, a data query link system corresponding to the data query method is also provided in the embodiment of the present application. Since the principle of solving the problem by the system in the embodiment of the present application is similar to the above-mentioned data query method in the embodiment of the present application, the implementation of the system can refer to the implementation of the method, and the repeated parts will not be repeated.
[0094] Fig.10 A structural schematic diagram of an electronic device provided in an embodiment of the present application is shown. The electronic device can be a front-end device or a back-end server in the above-mentioned system, including: a processor 1001, a storage medium 1002 and a bus 1003. The storage medium 1002 stores machine-readable instructions executable by the processor 1001. When the electronic device runs a data query method such as that in the embodiment, the processor 1001 communicates with the storage medium 1002 through the bus 1003, and the processor 1001 executes the machine-readable instructions, and the processor 1001 executes the preamble of the method item to execute the steps in the above-mentioned data query method.
[0095] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program is executed when a processor is running, and the processor executes the steps in the above-mentioned data query method.
[0096] In the embodiment of the present application, the computer program can also execute other machine-readable instructions when run by the processor to execute other methods described in the embodiment. For the specific execution method steps and principles, please refer to the description of the embodiment, which will not be repeated here.
[0097] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0098] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0099] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0100] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0101] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0102] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A data query method, characterized in that: Applied to a data query link system, the data query link system includes: a target application deployed at the front end, a data query service, a data subscription service, a message queue and a time series database deployed at the back end, the data subscription service is connected to the message queue and the time series database, the data query service is connected to the time series database, and the method includes: The data subscription service receives the real-time data in the message queue, pre-processes the real-time data to obtain processed data, sends the processed data to the data query service, and stores the processed data in the time series database; The target application establishes WebSocket communication with the data query service, and sends a data query request to the data query service, wherein the request type of the data query request includes: a real-time data query request or a playback data query request; If the data query request is a real-time data query request, the data query service determines whether the processed data is the data requested by the data query request, and if so, pushes the processed data to the target application; If the data query request is a playback data query request, the data query service determines the target data requested by the data query request from the time series database according to the data query request, and pushes the target data to the target application.
2. The data query method according to claim 1, characterized in that: The data subscription service receives the real-time data in the message queue, pre-processes the real-time data to obtain processed data, and pushes the processed data to the data query service and the time series database, including: The data subscription service subscribes to the message queue; The data subscription service monitors the message queue. If the data in the message queue is updated, the data subscription service obtains the newly added real-time data from the message queue and pre-processes the real-time data to obtain the processed data. The data subscription service stores the processed data in the time series database, and sends the processed data to the data query service.
3. The data query method according to claim 1, characterized in that: After the target application establishes WebSocket communication with the data query service and sends a data query request to the data query service, the method further includes: The data query service parses the data query request, obtains subscription information of the data query request, and stores the subscription information of the data query request in a memory cache.
4. The data query method according to claim 1, characterized in that: When the data query request is a real-time data query request, the data query request includes: subscription information, and the subscription information includes: device identification and data identification of the data to be queried; The data query service determines whether the processed data is data corresponding to the data query request, and if so, pushes the processed data to the target application, including: The data query service matches the processed data with the subscription information in the memory cache. If the device identifier of the processed data is the same as the device identifier in the subscription information, and the data identifier of the processed data matches the data identifier indicated by the subscription information, the processed data is pushed to the target application.
5. The data query method according to claim 1, characterized in that: When the data query request is a playback data query request, the data query request includes: subscription information, a request time interval, and the request time interval is used to indicate the start time and end time of the data to be queried; The data query service determines target data corresponding to the data query request from the time series database according to the data query request, and pushes the target data to the target application, including: The data query service generates a data query statement according to the subscription information and the request time interval in the data query request; The data query service executes the data query statement to query the target data from the time series database and saves the target data in the memory; The data query service reads the target data from the memory and sends the target data to the target application according to a preset data sending strategy.
6. The data query method according to claim 5, characterized in that: The data query service reads the target data from the memory and sends the target data to the target application according to a preset data sending strategy, including: The data query service determines the data sending frequency according to the request time interval; The data query service determines the target data to be sent corresponding to the current time, reads the target data to be sent from the memory according to the data sending frequency, and sends the target data to be sent to the target application.
7. The data query method according to claim 6, characterized in that: The data query service determines the target data to be sent corresponding to the current time, reads the target data to be sent from the memory according to the data sending frequency, and sends the target data to be sent to the target application, including: The data query service determines the first target data to be sent corresponding to the current time, reads the first target data to be sent from the memory, and sends the first target data to be sent to the target application; The data query service stops for a preset time period under the instruction of the data sending frequency; The data query service determines second target data to be sent corresponding to a target time, reads the second target data to be sent from a memory and sends the second target data to the target application, wherein the target time is the time after the data query service stops for a preset period of time.
8. A data query link system, characterized in that: The data query link system includes: a target application deployed at the front end, a data query service, a data subscription service, a message queue and a time series database deployed at the back end, the data subscription service is connected to the message queue and the time series database, the data query service is connected to the time series database, and the system is used to execute the steps of the data query method as described in any one of claims 1-7.
9. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the data query method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data query method according to any one of claims 1 to 7 are executed.
Citation Information
Patent Citations
Method for pushing data to mobile equipment at regular time
CN101674318A
Message pushing method, system and device and storage medium
CN116939028A
Transaction information query method and device, electronic equipment and storage medium
CN117633019A
Data query method, device and equipment based on Pandorah index and storage medium
CN118643056A
Thermal power generating unit energy consumption real-time monitoring and playback system based on SVG vector picture
CN119254997A