Real-time message pushing method and system based on HTTP response header information
By adopting the HTTP response header information based on the method in the real-time message push system, the problem of high resource occupation and complexity caused by the WebSocket implementation is solved, efficient message push and real-time data update are achieved, and the user experience is optimized.
Patent Information
- Application Number
- CN202510209729.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-05-30
AI Technical Summary
The existing real-time message push system is implemented based on WebSocket, resulting in high resource utilization and high complexity. Especially in high concurrency scenarios, it increases the server burden and complicates development and operation and maintenance.
The message real-time push method and system based on HTTP response header information is adopted to obtain the information to be pushed in real time through the server and cache it in the message buffer. Using the request-response model of the HTTP protocol, the content of the message is added to the HTTP response as the value of the custom HTTP response header and sent to the client.
It effectively avoids resource consumption caused by persistent connections, simplifies the complexity of implementation and maintenance, and realizes efficient acquisition and to be pushed messages, which is conducive to real-time data updates and user experience optimization.
Smart Images

Figure CN120075288A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of message pushing, and in particular to a method and system for real-time message pushing implemented based on HTTP response header information. Background Art
[0002] Current real-time message pushing systems are mainly implemented based on WebSocket. The client of the real-time message pushing system initiates a WebSocket connection to the server through an HTTP request, and the server of the real-time message pushing system accepts the request and maintains the connection. Although this persistent connection method can achieve real-time message pushing, it also faces some technical challenges, including resource consumption and complexity. Moreover, maintaining a WebSocket connection requires the server to consume resources, especially in high-concurrency scenarios, which will lead to an increased burden. In addition, implementing and maintaining a WebSocket server is relatively complex and requires handling connection management, error handling, and heartbeat detection, etc., thus increasing the difficulty of development and operation and maintenance. Summary of the Invention
[0003] To solve the technical problems existing in the background art, the present invention proposes a method and system for real-time message pushing implemented based on HTTP response header information.
[0004] In a first aspect, a real-time message pushing system implemented based on HTTP response header information proposed by the present invention includes: a client and a server, and the server includes a message buffer.
[0005] The server is used to obtain the message to be pushed and cache the message in the message buffer.
[0006] The client is used to send an HTTP request to the server.
[0007] The server is further used to receive the HTTP request, perform business logic according to the HTTP request to obtain business data, convert the business data into an HTTP response, determine whether there is a message in the message buffer.
[0008] If so, add the content of the message as the value of a custom HTTP response header to the HTTP response and send the HTTP response to the client.
[0009] If not, send the HTTP response to the client.
[0010] If not, send the HTTP response to the client.
[0011] Further, the message includes a message type, a processing instruction, and a last update time.
[0012] Further, the client is further used to receive the HTTP response and determine whether there is a custom HTTP response header in the HTTP response.
[0013] If so, read the value of the custom HTTP response header and perform asynchronous processing;
[0014] If not, end the processing.
[0015] Furthermore, during the asynchronous processing, the client is used to parse the structure of the message, extract the message type, processing instruction, and the last update time in the message;
[0016] And compare the last update time in the message with the last update time of the local information:
[0017] If the last update time of the local information is greater than or equal to the last update time in the message, it means that the processing instruction has expired and no operation is required;
[0018] If the last update time of the local information is less than the last update time in the message, it is necessary to execute the corresponding business operation according to the processing instruction and update the last update time in the local information.
[0019] In a second aspect, the present invention also proposes a method for real-time message push implemented based on HTTP response header information, which is applied to a client and a server, and includes:
[0020] The server obtains the message to be pushed and caches the message;
[0021] The client sends an HTTP request to the server;
[0022] The server receives the HTTP request, obtains business data according to the HTTP request for business logic, and converts the business data into an HTTP response; and determines whether there is a cached message;
[0023] If so, add the content of the message as the value of the custom HTTP response header to the HTTP response and send the HTTP response to the client;
[0024] If not, send the HTTP response to the client.
[0025] Furthermore, the message includes a message type, a processing instruction, and a last update time.
[0026] Furthermore, after sending the HTTP response to the client, it further includes:
[0027] The client receives the HTTP response and determines whether there is a custom HTTP response header in the HTTP response;
[0028] If so, read the value of the custom HTTP response header and perform asynchronous processing;
[0029] Otherwise, end the process.
[0030] Further, during the asynchronous processing, the client parses the structure of the message, extracts the message type, processing instruction, and last update time in the message;
[0031] And compare the last update time in the message with the last update time of the local information:
[0032] If the last update time of the local information is greater than or equal to the last update time in the message, it means that the processing instruction has expired and no operation is required;
[0033] If the last update time of the local information is less than the last update time in the message, it is necessary to execute the corresponding business operation according to the processing instruction and update the last update time in the local information.
[0034] In the present invention, the proposed method and system for real-time message push based on HTTP response header information obtain the information to be pushed in real time through the server, cache the information in the message buffer, and then use the request-response model of the HTTP protocol. After the server receives an HTTP request, add the content of the cached information as the value of the custom HTTP response header X-Message-Header to the HTTP response, and send the HTTP response to the client. While returning the business data to the client, the message is also returned, effectively avoiding the resource consumption caused by persistent connections, and at the same time simplifying the complexity of implementation and maintenance. The present invention can efficiently obtain the message to be pushed, which is beneficial to realizing real-time data update and optimizing the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic flowchart of the method for real-time message push based on HTTP response header information in an embodiment proposed by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0036] It should be noted that, without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the drawings and in conjunction with the embodiments.
[0037] In a first aspect, a system for real-time message push based on HTTP response header information proposed by the present invention includes: a client and a server, and the server includes a message buffer;
[0038] The server is used to obtain the message to be pushed and cache the message in the message buffer;
[0039] The client is used to send an HTTP request to the server;
[0040] The server is also used to receive HTTP requests, perform business logic based on the HTTP requests to obtain business data, convert the business data into an HTTP response.
[0041] Determine whether there is a message in the message buffer.
[0042] If so, add the content of the message as the value of the custom HTTP response header X-Message-Header to the HTTP response, and send the HTTP response to the client.
[0043] If not, send the HTTP response to the client.
[0044] The server in the message real-time push system implemented based on HTTP response header information proposed by the present invention can obtain the information to be pushed in real time, cache the information in the message buffer, and then use the request-response model of the HTTP protocol. After the server receives an HTTP request, add the content of the cached information as the value of the custom HTTP response header X-Message-Header to the HTTP response, and send the HTTP response to the client. While returning business data to the client, the message is also returned, effectively avoiding the resource consumption caused by persistent connections, and at the same time simplifying the complexity of implementation and maintenance. The present invention can efficiently obtain and push messages, which is beneficial to realizing real-time data update and optimizing the user experience.
[0045] In this embodiment, the message includes a message type, a processing instruction, and a last update time.
[0046] Among them, the message type is used to identify the message purpose and guide the client processing logic.
[0047] Among them, the process of obtaining the message to be pushed is specifically as follows: The server generates the message to be pushed according to business logic or external events. For example, the result of user operations, system notifications, real-time data updates, etc.
[0048] In another embodiment, the process of obtaining the message to be pushed is specifically a customized message directly created by the administrator background.
[0049] For example, in the airport scenario, when a new airport information is added, the server will generate a message to be pushed to instruct the client to update the local airport information cache.
[0050] The message buffer in this embodiment is a data structure in memory, such as a queue or a list, for quick access and update.
[0051] To achieve real-time data update, in this embodiment, the client is also used to receive an HTTP response and determine whether there is a custom HTTP response header X-Message-Header in the HTTP response;
[0052] If so, read the value of the custom HTTP response header X-Message-Header and perform asynchronous processing;
[0053] If not, end the processing.
[0054] In a further embodiment, during the asynchronous processing, the client is used to parse the structure of the message, extract the message type, processing instruction, and the last update time in the message;
[0055] And compare the last update time in the message with the last update time of the local information:
[0056] If the last update time of the local information is greater than or equal to the last update time in the message, it means the processing instruction has expired and no operation is required;
[0057] If the last update time of the local information is less than the last update time in the message, the corresponding business operation needs to be executed according to the processing instruction, and the last update time in the local information is updated to ensure that the user can access the latest data in real time.
[0058] For example, in an airport scenario, the message includes a message type, an update data instruction, and a last update time; among them, during the asynchronous processing, the client is used to parse the structure of the message, extract the message type, update data processing instruction, and the last update time in the message;
[0059] And compare the last update time in the message with the last update time of the local airport information:
[0060] If the last update time of the local airport information is greater than or equal to the last update time in the message, it means the local cache is already the latest and no operation is required;
[0061] If the last update time of the local airport information is less than the last update time in the message, the interface in the update data address in the update data processing instruction needs to be called according to the update data processing instruction to obtain the latest airport information, and the local cache and the last update time are updated according to the latest airport information to ensure that the user can access the latest airport data in real time.
[0062] In a second aspect, the present invention also proposes a method for real-time message push implemented based on HTTP response header information, which is applied to a client and a server, and includes:
[0063] The server obtains the messages to be pushed and caches the messages;
[0064] The client sends an HTTP request to the server;
[0065] The server receives the HTTP request, obtains service data according to the business logic of the HTTP request, and converts the service data into an HTTP response; and determines whether there are cached messages;
[0066] If so, the content of the message is added to the HTTP response as the value of the custom HTTP response header X-Message-Header, and the HTTP response is sent to the client;
[0067] If not, the HTTP response is sent to the client.
[0068] In this embodiment, the message includes a message type, a processing instruction, and a last update time.
[0069] Among them, the process of obtaining the messages to be pushed is specifically as follows: The messages to be pushed generated by the server according to the business logic or external events, for example, the results of user operations, system notifications, real-time data updates, etc.
[0070] In another embodiment, the process of obtaining the messages to be pushed is specifically a customized message directly created by the administrator background.
[0071] For example, when a new airport information is added, the server will generate a message to be pushed to indicate the client to update the local airport information cache.
[0072] In this embodiment, after the HTTP response is sent to the client, it further includes:
[0073] The client receives the HTTP response and determines whether there is a custom HTTP response header X-Message-Header in the HTTP response;
[0074] If so, the value of the custom HTTP response header X-Message-Header is read and processed asynchronously;
[0075] If not, the processing ends.
[0076] In a further embodiment, during the asynchronous processing, the client parses the structure of the message, extracts the message type, processing instruction, and last update time in the message;
[0077] And compares the last update time in the message with the last update time of the local information:
[0078] If the last update time of the local information is greater than or equal to the last update time in the message, it means that the processing instruction has expired and no action is required;
[0079] If the last update time of the local information is less than the last update time in the message, it is necessary to perform the corresponding business operation according to the processing instruction and update the last update time in the local information to ensure that users can access the latest data in real time.
[0080] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the technical solution and inventive concept of the present invention, makes equivalent substitutions or changes, and should be covered by the protection scope of the present invention.
Claims
1. A real-time message push system based on HTTP response header information, characterized in that: include: Client and server, the server includes a message buffer; The server is used to obtain the messages to be pushed and cache the messages in the message buffer; The client is used to send HTTP requests to the server; The server is also used to receive HTTP requests, perform business logic according to HTTP requests, obtain business data, and convert business data into HTTP responses; Determine whether there is a message in the message buffer; If yes, add the content of the message as the value of the custom HTTP response header to the HTTP response, and send the HTTP response to the client; If not, an HTTP response is sent to the client.
2. The real-time message push system based on HTTP response header information according to claim 1 is characterized in that: The message includes the message type, processing instructions, and last updated time.
3. The real-time message push system based on HTTP response header information according to claim 1 is characterized in that: The client is also used to receive HTTP responses and determine whether a custom HTTP response header exists in the HTTP response; If yes, read the value of the custom HTTP response header and process it asynchronously; If not, the process ends.
4. The real-time message push system based on HTTP response header information according to claim 3 is characterized in that: During asynchronous processing, the client is used to parse the structure of the message and extract the message type, processing instructions and last update time in the message; And compare the last updated time in the message with the last updated time of the local information: If the last update time of the local information is greater than or equal to the last update time in the message, it means that the processing instruction has expired and no action is required; If the last update time of the local information is less than the last update time in the message, it is necessary to perform the corresponding business operation according to the processing instruction and update the last update time in the local information.
5. A real-time message push method based on HTTP response header information, applied to a client and a server, comprising: The server obtains the message to be pushed and caches the message; The client sends an HTTP request to the server; The server receives the HTTP request, performs business logic according to the HTTP request to obtain business data, and converts the business data into an HTTP response; And determine whether there is a cached message; If yes, add the content of the message as the value of the custom HTTP response header to the HTTP response, and send the HTTP response to the client; If not, an HTTP response is sent to the client.
6. The method for real-time message push based on HTTP response header information according to claim 5, characterized in that: The message includes the message type, processing instructions, and last updated time.
7. The method for real-time message push based on HTTP response header information according to claim 5, characterized in that: After sending the HTTP response to the client, it also includes: The client receives the HTTP response and determines whether there is a custom HTTP response header in the HTTP response; If yes, read the value of the custom HTTP response header and process it asynchronously; If not, the process ends.
8. The method for real-time message push based on HTTP response header information according to claim 7, characterized in that: During asynchronous processing, the client parses the structure of the message and extracts the message type, processing instructions, and last update time from the message; And compare the last updated time in the message with the last updated time of the local information: If the last update time of the local information is greater than or equal to the last update time in the message, it means that the processing instruction has expired and no action is required; If the last update time of the local information is less than the last update time in the message, it is necessary to perform the corresponding business operation according to the processing instruction and update the last update time in the local information.