CN-115390834-B - File generation method, device, equipment and storage medium
Abstract
The application discloses a file generation method, a device, equipment and a storage medium, which relate to the technical field of computers and are used for solving the defects of poor consumption end performance and message loss caused by receiving a large number of requests at present, and comprise the steps of monitoring a message queue in real time, and acquiring changed first target data when the message queue is monitored to have data change; the method comprises the steps of storing first target data into a first database, reading tag information from the first database to obtain second target data which is not generated as file data, and sending the second target data to an asynchronous thread so as to complete corresponding file generation operation based on the second target data to obtain a target file. According to the application, the data change in the message queue is monitored, and the tag information is the data of the un-generated file and is sent to the asynchronous thread to complete the corresponding file generation operation, so that the maintenance cost is reduced, the performance is improved, and the use is convenient.
Inventors
- CHEN YUANJIE
- MA LIMING
Assignees
- 小马国炬(玉溪)科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20220829
Claims (7)
- 1. A file generation method, applied to a first service in a server, comprising: Receiving a request sent by a client through a second service in a server, and extracting third target data for generating a file from the request; Transmitting the third target data from the second service to a message queue; Monitoring the message queue in real time, and acquiring changed first target data when monitoring that the data change exists in the message queue; each data stored in the first database is provided with label information obtained according to state information corresponding to the current data; determining file generation state information corresponding to the first target data to obtain first target state information, wherein the file generation state information comprises an un-generated file, a generated file and file generation; generating corresponding tag information based on the first target state information, and adding the tag information to a region corresponding to the first target data in the first database; Reading tag information from the first database according to the tag information of each data in the first database, wherein the tag information is data of a file which is not generated, so as to obtain second target data; sending the second target data to an asynchronous thread so as to complete corresponding file generation operation based on the second target data to obtain a target file; Generating and returning file generated information through the asynchronous thread so as to change the label information corresponding to the second target data in the first database into the generated file.
- 2. The file generating method according to claim 1, wherein after said receiving the request sent by the client through the second service in the server, further comprising: Judging whether the request meets a preset warehousing rule or not; if the request meets the preset warehousing rules, extracting information to be stored from the request, wherein the information to be stored comprises parameters and login information; Storing the information to be stored into a second database; and if the request does not meet the preset warehousing rules, generating corresponding prompt information, and returning the prompt information to the client.
- 3. The method of generating a file according to claim 1, wherein after storing the first target data in the first database, further comprising: Deleting the first target data in the message queue.
- 4. The file generating method according to claim 1, wherein said reading tag information from said first database is data of an undepicted file to obtain second target data, comprising: setting a timer; And reading tag information from the first database at regular time through the timer to obtain second target data, wherein the tag information is data of a non-generated file.
- 5. A file generating apparatus, applied to a first service in a server, comprising: the system comprises a first data acquisition module, a message queue, a first data processing module and a second data processing module, wherein the first data acquisition module is used for receiving a request sent by a client through a second service in a server, extracting third target data for generating a file from the request, sending the third target data from the second service to the message queue, monitoring the message queue in real time, and acquiring changed first target data when the data change exists in the message queue; The data storage module is used for storing the first target data into a first database, setting tag information obtained according to state information corresponding to current data for each data stored in the first database, determining file generation state information corresponding to the first target data to obtain first target state information, wherein the file generation state information comprises an un-generated file, a generated file and file generation; The second data acquisition module is used for reading the tag information from the first database according to the tag information of each data in the first database to obtain second target data, wherein the tag information is the data of the file which is not generated; The file generation module is used for sending the second target data to an asynchronous thread so as to finish corresponding file generation operation based on the second target data to obtain a target file; generating and returning file generated information through the asynchronous thread so as to change the label information corresponding to the second target data in the first database into the generated file.
- 6. An electronic device, comprising: A memory for storing a computer program; a processor for executing the computer program to implement the steps of the file generation method as claimed in any one of claims 1 to 4.
- 7. A computer-readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the file generation method according to any one of claims 1 to 4.
Description
File generation method, device, equipment and storage medium Technical Field The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a file. Background In an actual java web system, actual file generation consumes server performance, and is analyzed in the middle along with a file generation mode, byte conversion is needed after the file is generated, and finally, the file is written into a server in a byte stream mode, if the file generation and interface response decoupling is not performed, the response of a client can wait for the response after the file generation, and the client is very unfriendly to users. In most of the existing solutions, a message is sent through an mq (message queue) in the program, so as to decouple the message in such a way that another mq in another service or in the service listens to the generated file. Thus, if a large number of requests are received simultaneously, the consumption end performance may not keep pace, and the message is lost. Disclosure of Invention Accordingly, the present invention is directed to a method, apparatus, device and storage medium for generating a file, which can reduce maintenance cost, improve performance and facilitate use. The specific scheme is as follows: In a first aspect, the present application discloses a file generating method, which is applied to a first service in a server, and includes: monitoring a message queue in real time, and acquiring changed first target data when monitoring that the data change exists in the message queue; storing the first target data to a first database; reading tag information from the first database as data of a non-generated file to obtain second target data; and sending the second target data to an asynchronous thread so as to finish corresponding file generation operation based on the second target data to obtain a target file. Optionally, before the real-time monitoring message queue, the method further includes: Receiving a request sent by a client through a second service in the server, and extracting third target data for generating a file from the request; and sending the third target data from the second service to the message queue. Optionally, after the request sent by the client is received through the second service in the server, the method further includes: Judging whether the request meets a preset warehousing rule or not; if the request meets the preset warehousing rules, extracting information to be stored from the request, wherein the information to be stored comprises parameters and login information; Storing the information to be stored into a second database; and if the request does not meet the preset warehousing rules, generating corresponding prompt information, and returning the prompt information to the client. Optionally, after the storing the first target data in the first database, the method further includes: Deleting the first target data in the message queue. Optionally, the reading tag information from the first database is data of an undepicted file, so as to obtain second target data, including: setting a timer; And reading tag information from the first database at regular time through the timer to obtain second target data, wherein the tag information is data of a non-generated file. Optionally, after the storing the first target data in the first database, the method further includes: Determining file generation state information corresponding to the first target data to obtain first target state information, wherein the file generation state information comprises the un-generated file, the generated file and file generation; and generating corresponding tag information based on the first target state information, and adding the tag information to an area corresponding to the first target data in the first database. Optionally, the sending the second target data to an asynchronous thread so as to complete a corresponding file generating operation based on the second target data, and after obtaining the target file, further includes: Generating and returning file generated information through the asynchronous thread so as to change the label information corresponding to the second target data in the first database into the generated file. In a second aspect, the present application discloses a file generating apparatus, applied to a first service in a server, including: The first data acquisition module is used for monitoring the message queue in real time, and acquiring changed first target data when the data change in the message queue is monitored; The data storage module is used for storing the first target data to a first database; the second data acquisition module is used for reading tag information from the first database to obtain second target data, wherein the tag information is data of a file which is not generated; and the file generation module is u