SSE-based large model data pushing method and Java server
By using SSE technology on the Java server to establish a connection with the big model service, receive and process data, and push the data to the front-end page, the problem of data communication and persistence between the front-end page and the big model is solved, and real-time push and synchronous display of big model data is realized.
Patent Information
- Application Number
- CN202510006678.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-03
- Publication Date
- 2025-04-22
AI Technical Summary
Data communication and persistence between the front-end page and the big model are difficult to achieve, resulting in the big model data being unable to be pushed from the server to the front-end page to be displayed to the user in real time.
Using SSE-based data push method, an SSE connection is established with the big model service through the Java server using the SseEmitter object, receiving and processing the pushed data, and pushing the parsed data to the front-end page through the SSE connection.
Real-time push of big model data is realized, data synchronization from the server to the front-end page, solving the problems of data communication and persistence, and improving the system's response capabilities and data real-timeness.
Smart Images

Figure CN119865528A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of large models, and in particular to a large model data pushing method based on SSE and a Java server. Background Art
[0002] The front-end page is the browser interface used by users, which allows users to view and operate by displaying the received data. The big model service is the server that provides data push. It is an urgent problem to combine the big model service with the front-end page to realize the data pushed by the big model service to the front-end, and finally display the data effect on the front-end page.
[0003] At present, data communication and persistence between the front-end page and the large model are difficult to achieve, resulting in the inability to push the large model data from the server to the front-end page in real time to display it to users. Summary of the invention
[0004] The embodiment of the present invention provides a large model data push method based on SSE and a Java server, which can push the large model data from the server to the front-end page in real time for display to the user.
[0005] According to one aspect of the present invention, a large model data push method based on SSE is provided, which is applied to a Java server, comprising:
[0006] In response to the SSE connection establishment request from the front-end page, the SseEmitter object is instantiated and established through the SSE session holder class SSESessionHolder;
[0007] Establish an SSE connection with the large model service through the SseEmitter object;
[0008] Receive data pushed by the large model service, use BufferedReader to continuously read, process and verify the data;
[0009] Perform structural analysis of the verified data in Json format. If there is no exception, it will be persistently stored. If there is an analysis exception, skip data reception.
[0010] The parsed data is pushed to the front-end page through the SSE connection using the SseEmitter object.
[0011] Optionally, establishing an SSE connection with a large model service through the SseEmitter object includes:
[0012] Use the UUID library to generate a unique id, bind the id to the initialized SseEmitter object as a key-value pair for storage, and set the corresponding response header;
[0013] Set the end event and timeout event of SseEmitter and set the timeout period;
[0014] A new thread is started using the thread pool technology of Executors, and the SseEmitter object is passed into the new thread to establish an SSE connection with the large model service.
[0015] Optionally, the method further includes:
[0016] If no data is sent before the timeout period is reached or the end event is triggered, a cleanup operation is performed to release resources, record logs, and disconnect the SSE connection.
[0017] Optionally, the method further includes:
[0018] If the SSE connection with the large model service fails, the request is retried a preset number of times according to the preset retry strategy;
[0019] If the retry strategy still fails, the SSE connection established with the front-end page will print the exception log and push the alarm.
[0020] Optionally, the processing and verifying data includes:
[0021] Use BufferedReader to continuously read received data;
[0022] For each row of data read, use the message processor to process it;
[0023] Perform data validation to check the format, range and type of the data.
[0024] Optionally, the method further includes:
[0025] If the structured analysis has a preset number of consecutive exceptions, the connection with the large model service is disconnected;
[0026] If the structured analysis is abnormal, the data is repackaged according to the protocol.
[0027] Optionally, the method further includes:
[0028] When data reception is completed or an exception is encountered, the input stream and BufferedReader are closed, the complet method of SseEmitter is called to close the SSE connection with the front-end page, the SseEmitter object in the key-value pair storage structure is deleted, and the established thread is closed.
[0029] According to another aspect of the present invention, there is provided a Java server, comprising:
[0030] The object creation unit is used to instantiate and create an SseEmitter object through the SSE session holder class SSESessionHolder in response to the SSE connection creation request from the front-end page;
[0031] A connection establishing unit, used to establish an SSE connection with the large model service through the SseEmitter object;
[0032] The data processing unit is used to receive data pushed by the large model service, use BufferedReader to continuously read the data, and process and verify the data;
[0033] The data parsing unit is used to perform structured parsing of the verified data in Json format. If there is no exception, it will be persistently stored. If there is an analysis exception, data reception will be skipped.
[0034] The data push unit is used to push the parsed data to the front-end page through the SSE connection using the SseEmitter object.
[0035] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0036] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the SSE-based large model data push method described in any embodiment of the present invention.
[0037] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the SSE-based large model data push method described in any embodiment of the present invention when executed.
[0038] The solution of the embodiment of the present invention includes: responding to the SSE connection establishment request from the front-end page, instantiating and establishing the SseEmitter object through the SSE session holder class SSESessionHolder; establishing an SSE connection with the large model service through the SseEmitter object; receiving the data pushed by the large model service, using BufferedReader to continuously read the data and process and verify the data; performing structured parsing of the verified data in Json format, and persistently storing it if there is no exception, and skipping data reception if the parsing is abnormal; pushing the parsed data to the front-end page through the SSE connection using the SseEmitter object. The technical solution of the embodiment of the present invention solves the data communication and persistence problems between the front-end page and the large model, so that the generated model data can be pushed from the server to the front-end page in real time to be displayed to the user.
[0039] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 It is a flow chart of a large model data push method based on SSE provided by one embodiment of the present invention;
[0042] Figure 2 It is a schematic diagram of executing a large model data push method based on SSE provided by one embodiment of the present invention;
[0043] Figure 3 is a schematic diagram of a retry mechanism provided by an embodiment of the present invention;
[0044] Figure 4 This is a schematic diagram of the structure of a Java server provided by an embodiment of the present invention;
[0045] Figure 5 It is a structural schematic diagram of an electronic device for implementing the SSE-based large model data push method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0047] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0048] The background technologies involved in the embodiments of the present invention are as follows:
[0049] Server-SentEvents (SSE): A web technology used to enable the server to push data to the client in real time. It is based on the HTTP protocol and allows the server to send data to the client in the form of an event stream.
[0050] Multithreading: A technology that implements multiple threads of execution concurrently in software or hardware. Computers with multithreading capabilities can execute more than one thread at the same time due to hardware support, thereby improving overall processing performance.
[0051] Stream Processing: A computing model and programming paradigm for real-time data processing. It realizes real-time analysis, filtering, aggregation and other operations of data by continuously and efficiently processing infinite data streams.
[0052] like Figure 1 As shown, an embodiment of the present invention provides a large model data push method based on SSE, which is applied to a Java server. The method may include the following steps:
[0053] S110. In response to the SSE connection establishment request from the front-end page, an SseEmitter object is instantiated and established through the SSE session holder class SSESessionHolder.
[0054] The embodiment of the present invention is based on SSE and multi-threading technology, and establishes an SSE connection between the front-end page (browser) and the back-end service (Java server), and the back-end service establishes an SSE connection with the large model service, and finally realizes the real-time push function of the model data. Figure 2 As shown, an embodiment of the present invention provides an execution schematic diagram of a large model data push method based on SSE, and the implementation process is as follows:
[0055] First, the front-end page ensures that the browser supports Server-SentEvents (SSE) technology, creates an EventSource object using JavaScript, and adds a message event listener to the EventSource object.
[0056] The front end requests the Java server to establish an SSE connection by specifying the URL. When establishing the SSE connection, the front end passes the user authentication information or necessary request parameters to the Java server by sending a custom request header or query parameters. At the same time, the front end uses a reconnection mechanism to deal with network disconnection or other connection anomalies. After receiving the front end request, the back end uses a special SSE session holder class (SSESessionHolder) to instantiate and establish an SseEmitter object.
[0057] S120. Establish an SSE connection with the large model service through the SseEmitter object.
[0058] In the embodiment of the present invention, step S120 specifically includes:
[0059] Use the UUID library to generate a unique id, bind the id to the initialized SseEmitter object as a key-value pair for storage, and set the corresponding response header;
[0060] Set the end event and timeout event of SseEmitter and set the timeout period;
[0061] A new thread is started using the thread pool technology of Executors, and the SseEmitter object is passed into the new thread to establish an SSE connection with the large model service.
[0062] The backend uses the UUID library to generate a unique ID, and uses a key-value pair storage structure to bind the ID to the initialized SseEmitter. The response header is set to set Content-Type to "text / event-stream" and Cache-Control to "no-cache" to ensure that the data will not be cached.
[0063] Set the end event of SseEmitter, so that you can listen to the end operation of the SseEmitter object.
[0064] Set the timeout event of SseEmitter. For example, set the timeout to 600 seconds through the TimeoutMillis parameter.
[0065] The backend uses the Executors thread pool technology to reasonably configure the thread pool size according to the system load capacity and expected concurrency. The submit method is used to start a new thread and pass the SseEmitter object to the new thread. This thread is used to asynchronously process communications with the large model service and is responsible for sending data received by the model service to the front end.
[0066] In an embodiment of the present invention, the method may further include:
[0067] If no data is sent before the timeout period is reached or the end event is triggered, a cleanup operation is performed to release resources, record logs, and disconnect the SSE connection.
[0068] If no data is sent when the timeout parameter (such as 600 seconds) is reached or the end event is triggered, a cleanup operation is performed, at which time resources are released, log operations are recorded, and finally the SSE connection is disconnected.
[0069] In the newly created thread, the backend requests the large model server to establish an SSE connection. After the connection is successfully established, the model server uses HttpURLConnection technology to transmit data to the backend in the form of a stream.
[0070] In an embodiment of the present invention, the method may further include:
[0071] If the SSE connection with the large model service fails, the request is retried a preset number of times according to the preset retry strategy;
[0072] If the retry strategy still fails, the SSE connection established with the front-end page will print the exception log and push the alarm.
[0073] Figure 3 is a schematic diagram of a retry mechanism provided by an embodiment of the present invention, such as Figure 3 As shown in the figure, if the request to the large model server fails (connection timeout, permission verification failure), the request will be retried several times according to the retry strategy. Figure 3 3 times in total.
[0074] If the retry strategy still fails, the exception handling mechanism is entered. At this time, an SSE connection is established with the front-end page, and the exception log is printed and an alarm is pushed.
[0075] The large model service returns the SSE connection establishment completion to the Java server. At this time, the SSE connection between the model service and the Java server has been established, and the Java server can receive the information pushed by the large model service through the stream. The large model service pushes data to the Java server through the SSE connection.
[0076] S130. Receive data pushed by the large model service, use BufferedReader to continuously read the data, and process and verify the data.
[0077] In the embodiment of the present invention, processing and verifying data in step S130 includes:
[0078] Use BufferedReader to continuously read received data;
[0079] For each row of data read, use the message processor to process it;
[0080] Perform data validation to check the format, range and type of the data.
[0081] The backend uses BufferedReader to continuously read the received data
[0082] For each row of data read, use the message processor (MsgHandler) to process the data and perform data verification to check the format, range, type, etc. of the data.
[0083] In an embodiment of the present invention, the method may further include:
[0084] If the structured analysis has a preset number of consecutive exceptions, the connection with the large model service is disconnected;
[0085] If the structured analysis is abnormal, the data is repackaged according to the protocol.
[0086] If parsing exceptions occur multiple times in succession, the connection to the large model service is disconnected.
[0087] After all the preceding operation steps are normal, the Java backend will repackage the parsed data according to the protocol.
[0088] S140, perform structured analysis of the verified data in Json format, and store it persistently if there is no abnormality. If the analysis is abnormal, skip data reception.
[0089] After the Java backend completes the data verification, it will perform a structured analysis of the received data in Json format, and store the data persistently if there is no abnormality in the analysis. If there is an abnormality in the analysis, the data reception will be skipped and the next reception will be performed.
[0090] S150. Push the parsed data to the front-end page through the SSE connection using the SseEmitter object.
[0091] After encapsulation is completed, use the instantiated SseEmitter object to push the structured data to the front-end page through the SSE connection through the send method. The front-end page uses the message event listener in step 1 to receive the monitored data. After parsing the data, use JavaScript to update the elements on the page. Use the state management and update mechanism provided by Vue to improve the responsiveness of data updates and page performance. And use animation or transition effects to finally display it on the page.
[0092] In an embodiment of the present invention, the method may further include:
[0093] When data reception is completed or an exception is encountered, the input stream and BufferedReader are closed, the complet method of SseEmitter is called to close the SSE connection with the front-end page, the SseEmitter object in the key-value pair storage structure is deleted, and the established thread is closed.
[0094] When the backend service completes data reception or encounters an exception, it closes the input stream and BufferedReader, and calls the complete method of SseEmitter to close the SSE connection established with the frontend. Since the system can listen to the set end event, the SseEmitter object in the key-value pair storage structure is deleted at this time, and the established thread is closed.
[0095] The solution of the embodiment of the present invention does not need to introduce complex third-party libraries or frameworks. It allows the backend to receive data from the large model service side and push it to the frontend in real time. This mechanism ensures the real-time nature of the data and the responsiveness of the system, reduces the frequency of data requests between the frontend and the backend, reduces the burden on the server, and improves the concurrent processing capability of the system through asynchronous processing and multithreading. It supports multiple types of data push and can be applied to various scenarios, such as stock quotes, message notifications, etc.
[0096] The embodiment of the present invention solves the data communication and persistence problems between the front-end page and the large model, so that the generated model data can be pushed from the server to the front-end page in real time, and finally displayed to the user after rendering processing.
[0097] like Figure 4 As shown, an embodiment of the present invention provides a Java server, which may include the following components:
[0098] The object creation unit 410 is used to instantiate and create an SseEmitter object through the SSE session holder class SSESessionHolder in response to the SSE connection creation request from the front-end page;
[0099] A connection establishing unit 420, configured to establish an SSE connection with the large model service through the SseEmitter object;
[0100] The data processing unit 430 is used to receive the data pushed by the large model service, use BufferedReader to continuously read the data, and process and verify the data;
[0101] The data parsing unit 440 is used to perform structural parsing of the verified data in Json format, and to store the data persistently if there is no abnormality, and to skip data reception if there is an abnormality in the parsing;
[0102] The data push unit 450 is used to push the parsed data to the front-end page through the SSE connection using the SseEmitter object.
[0103] Optionally, the connection establishing unit 420 is specifically configured to execute:
[0104] Use the UUID library to generate a unique id, bind the id to the initialized SseEmitter object as a key-value pair for storage, and set the corresponding response header;
[0105] Set the end event and timeout event of SseEmitter and set the timeout period;
[0106] A new thread is started using the thread pool technology of Executors, and the SseEmitter object is passed into the new thread to establish an SSE connection with the large model service.
[0107] Optionally, the connection establishing unit 420 is further configured to execute:
[0108] If no data is sent before the timeout period is reached or the end event is triggered, a cleanup operation is performed to release resources, record logs, and disconnect the SSE connection.
[0109] Optionally, the connection establishing unit 420 is further configured to execute:
[0110] If the SSE connection with the large model service fails, the request is retried a preset number of times according to the preset retry strategy;
[0111] If the retry strategy still fails, the SSE connection established with the front-end page will print the exception log and push the alarm.
[0112] Optionally, the data processing unit 430, when processing and verifying data, specifically performs:
[0113] Use BufferedReader to continuously read received data;
[0114] For each row of data read, use the message processor to process it;
[0115] Perform data validation to check the format, range and type of the data.
[0116] Optionally, the data parsing unit 440 is further configured to execute:
[0117] If the structured analysis has a preset number of consecutive exceptions, the connection with the large model service is disconnected;
[0118] If the structured analysis is abnormal, the data is repackaged according to the protocol.
[0119] Optionally, the connection establishing unit 420 is further configured to execute:
[0120] When data reception is completed or an exception is encountered, the input stream and BufferedReader are closed, the complet method of SseEmitter is called to close the SSE connection with the front-end page, the SseEmitter object in the key-value pair storage structure is deleted, and the established thread is closed.
[0121] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the Java server. In other embodiments of the present invention, the Java server may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0122] The information interaction, execution process and other contents between the units in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention. For specific contents, please refer to the description in the embodiment of the method of the present invention, and no further description is given here.
[0123] Figure 5A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0124] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0125] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0126] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the large model data push method based on SSE.
[0127] In some embodiments, the large model data push method based on SSE may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the large model data push method based on SSE described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the large model data push method based on SSE in any other appropriate manner (e.g., by means of firmware).
[0128] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0129] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0130] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0131] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0132] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0133] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0134] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0135] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A large model data push method based on SSE, characterized in that: Applied to Java server, including: In response to the SSE connection establishment request from the front-end page, the SseEmitter object is instantiated and established through the SSE session holder class SSESessionHolder; Establish an SSE connection with the large model service through the SseEmitter object; Receive data pushed by the large model service, use BufferedReader to continuously read, process and verify the data; Perform structural analysis of the verified data in Json format. If there is no exception, it will be persistently stored. If there is an analysis exception, skip data reception. The parsed data is pushed to the front-end page through the SSE connection using the SseEmitter object.
2. The method according to claim 1, characterized in that The establishing of an SSE connection with the large model service through the SseEmitter object includes: Use the UUID library to generate a unique id, bind the id to the initialized SseEmitter object as a key-value pair for storage, and set the corresponding response header; Set the end event and timeout event of SseEmitter and set the timeout period; A new thread is started using the thread pool technology of Executors, and the SseEmitter object is passed into the new thread to establish an SSE connection with the large model service.
3. The method according to claim 2, characterized in that Further including: If no data is sent before the timeout period is reached or the end event is triggered, a cleanup operation is performed to release resources, record logs, and disconnect the SSE connection.
4. The method according to claim 2, characterized in that: Further including: If the SSE connection with the large model service fails, the request is retried a preset number of times according to the preset retry strategy; If the retry strategy still fails, the SSE connection established with the front-end page will print the exception log and push the alarm.
5. The method according to claim 1, characterized in that The processing and verification of data includes: Use BufferedReader to continuously read received data; For each row of data read, use the message processor to process it; Perform data validation to check the format, range and type of the data.
6. The method according to claim 1, characterized in that Further including: If the structured analysis has a preset number of consecutive exceptions, the connection with the large model service is disconnected; If the structured analysis is abnormal, the data is repackaged according to the protocol.
7. The method according to claim 2, characterized in that Further including: When data reception is completed or an exception is encountered, the input stream and BufferedReader are closed, the complet method of SseEmitter is called to close the SSE connection with the front-end page, the SseEmitter object in the key-value pair storage structure is deleted, and the established thread is closed.
8. Java server, characterized in that: include: The object creation unit is used to instantiate and create an SseEmitter object through the SSE session holder class SSESessionHolder in response to the SSE connection creation request from the front-end page; A connection establishing unit, used to establish an SSE connection with the large model service through the SseEmitter object; The data processing unit is used to receive data pushed by the large model service, use BufferedReader to continuously read the data, and process and verify the data; The data parsing unit is used to perform structured parsing of the verified data in Json format. If there is no exception, it will be persistently stored. If there is an analysis exception, data reception will be skipped. The data push unit is used to push the parsed data to the front-end page through the SSE connection using the SseEmitter object.
9. An electronic device, characterized in that include: at least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the SSE-based large model data push method described in any one of claims 1-7.
10. A computer readable medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the SSE-based large model data push method according to any one of claims 1 to 7 when executed.
Citation Information
Cited By
Method and device for SSE streaming output of edited data and medium
CN120449840A