A method, system, device and storage medium for sending messages and updating data
By adopting publish subscription mode and request communication methods of websocket or https polling in web communication technology, the delay problem caused by multitasking and multiple requests is solved, and fixed-point reception of messages is realized, improving user experience and code maintainability.
Patent Information
- Application Number
- CN202211528976.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-30
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-11-30
AI Technical Summary
The prior art has delays in processing multitasking and multiple requests, resulting in too long page waiting time and the sending of messages in the global state manager cannot be received at a fixed location.
The message/event is encapsulated using the publish subscription mode, and the request communication method is polled by websocket or https. Different events are processed when receiving messages, and corresponding event tasks are issued to each page to realize the channel for receiving ajax messages.
It solves the problem that the page wait time caused by the delay in requesting data, and realizes fixed-point reception of messages, avoids the limitations of the global state manager, and improves the simplicity and maintainability of the code.
Smart Images

Figure CN115913874B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of web communication technology, and more specifically, to a method, system, device and storage medium for sending messages and updating data. Background Art
[0002] With the development of business, the number of parallel requests is gradually increasing, and multi-tasking and multiple requests on the view page are common. In particular, in response to the increasingly differentiated business expansion, the development of big data, and the popularization and large-scale application of cloud computing, it has become a common practice to rely on third-party cloud computing to run data and process logic. However, there is a certain delay in the background multi-tasking processing and the API run by the third party. The waiting time of asynchronous requests will bring a certain experience impact, so a method that can monitor data updates in real time and assign corresponding events to the next level page is needed to implement changes to the view layer.
[0003] The current mainstream frameworks generally use state management to develop objects and object actions for multi-layer, large-scale, or point-to-point data transmission, updates, and data delivery. For example, vue's vuex, react's redux, and angular's Ngrx / Store, mainstream platforms all use a global management framework to deliver, update, and monitor data. However, when the same data is delivered continuously, better and unified monitoring cannot be achieved. At the same time, it is impossible to more easily and clearly specify the reception and update of multiple pages for a single event, and adopt different targeted interactions / event interactions. Summary of the invention
[0004] The technical problem to be solved by the present invention is to address the above-mentioned deficiencies in the prior art. The first purpose of the present invention is to provide a method for sending messages and updating data, which can solve the problem of delays in requesting data causing long page waiting time to affect the experience, and at the same time solve the limitation that messages sent in the global state manager cannot be received at a fixed point.
[0005] The second purpose of the present invention is to provide a system for sending messages and updating data, which can solve the problem of delays in requesting data causing long page waiting time to affect the experience, and at the same time solve the limitation that messages sent in the global state manager cannot be received at a fixed point.
[0006] A third object of the present invention is to provide a computer device.
[0007] A fourth objective of the present invention is to provide a computer-readable storage medium.
[0008] In order to achieve the above-mentioned purpose one, the present invention provides a method for sending messages and updating data, which adopts the publish-subscribe mode to encapsulate messages / events, processes different events when receiving messages through the request communication method of websocket or https polling, and sends corresponding event tasks to each page, thereby realizing the channel for receiving ajax messages on the page.
[0009] As a further improvement, the following steps are specifically included:
[0010] Step 1. Encapsulate the message / event monitoring system of the publish-subscribe model;
[0011] Step 2. Specify the communication protocol between the front-end and back-end, set the message number of the data return, which is used to update the requested queue; specify the event tag event returned in the interface, which is used to issue different event subscriptions to update data in real time;
[0012] Step 3. When the page that needs to be updated is initialized, use the $on monitoring system to monitor the events of the corresponding mark;
[0013] Step 4. Create a message request event, set the message number queue, and save it in local storage;
[0014] Step 5. Create a binding listener event $on when the corresponding page is initialized, and specify the corresponding event key;
[0015] Step 6. The page sends a request that needs to be processed with a delay or for a long time. After receiving the request, the background returns data and establishes a message queue, in which the data includes the waiting status and the message queue number; the message queue adopts wesocket or http polling method;
[0016] Step 7. After the previous task is processed, the monitoring system created in step 1 returns the message queue data to the front end.
[0017] Furthermore, the monitoring system includes:
[0018] Set the event queue Queue object;
[0019] Create a monitoring method $on, set key and function as input parameters, and assign corresponding functions to different keys;
[0020] Establish a message / event publishing system $emit, pass key and data and process and distribute them.
[0021] Furthermore, the monitoring system also includes: establishing a monitoring destruction method to release resources.
[0022] Furthermore, in step 7, the front end performs the following processing after receiving the data:
[0023] Step 71. Determine whether there is a corresponding event based on the data returned by the message body, and if so, proceed to the next step;
[0024] Step 72: Categorize and process the events in the message body, and send the events via $emit;
[0025] Step 73. The listener established in the page in step 5 will receive the corresponding event and enter data update and view update according to the corresponding data;
[0026] Step 74. After the event processing is completed, update the corresponding message number.
[0027] Furthermore, after receiving the data, the front end also performs the following processing: Step 75. Pages can send events to other pages through $emit to update data, forming a fixed data update sequence.
[0028] Furthermore, after receiving the data, the front end also performs the following processing: Step 76. The page needs to stop listening to events to release resources during the destruction cycle.
[0029] In order to achieve the above-mentioned second objective, the present invention provides a system for sending messages and updating data, comprising:
[0030] Encapsulation module, which uses a publish-subscribe model to encapsulate messages / events, and processes different events when receiving messages through a request communication method such as websocket or https polling;
[0031] The sending module sends corresponding event tasks to each page and implements the channel for receiving ajax messages on the page.
[0032] In order to achieve the third objective above, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned method of sending messages and updating data when executing the computer program.
[0033] In order to achieve the fourth objective above, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for sending a message and updating data is implemented.
[0034] Beneficial Effects
[0035] Compared with the prior art, the present invention has the following advantages:
[0036] The present invention solves the user experience of waiting too long when the request has no response for a long time, by delaying and generating a queue so that the long request can run in the background, and the view can be updated in time when there is a response. The publish-subscribe mode distribution method adopted by the master in processing messages is relatively cumbersome and complicated compared to the commonly used state management framework and the multi-page layer-by-layer parameter transmission method. This method can provide a simpler and clearer transmission and update for the corresponding message / event, avoiding too much data management, and improving the simplicity and maintainability of the code. At the same time, it solves the limitation that the message sent in the global state manager cannot be received at a fixed point. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A schematic diagram of the encapsulation monitoring system in the present invention;
[0038] Figure 2 This is a schematic diagram of the event delivery in the present invention. DETAILED DESCRIPTION
[0039] The present invention will be further described below with reference to the specific embodiments in the accompanying drawings.
[0040] See also Figure 1-2 A method for sending messages and updating data. It uses the publish-subscribe model to encapsulate messages / events. It processes different events when receiving messages through websocket or https polling request communication, and sends corresponding event tasks to each page. It implements the ajax message receiving channel on the page to update data and generate interactions in a simple, complete, customizable, multi-dimensional, real-time and effective manner.
[0041] The specific steps include:
[0042] Step 1. Encapsulate the message / event monitoring system of the publish-subscribe model.
[0043] The monitoring system includes:
[0044] Set the event queue Queue object;
[0045] Create a monitoring method $on, set key and function as input parameters, and assign corresponding functions to different keys;
[0046] Establish a message / event publishing system $emit, pass key and data and process and distribute them;
[0047] Establish a listener destruction method to release resources.
[0048] Step 2. Specify the communication protocol between the front-end and back-end, set the message number of the data return, which is used to update the requested queue; specify the event tag event returned in the interface, which is used to issue different event subscriptions to update data in real time.
[0049] Step 3. When initializing the page that needs to be updated, use the $on monitoring system to monitor the events of the corresponding tags.
[0050] Step 4. Create a message request event, set the message number queue, and save it in local storage.
[0051] Step 5. Create a binding listener event $on when the corresponding page is initialized, and specify the corresponding event key.
[0052] Step 6. The page sends a request that requires delayed processing or long processing time. After receiving the request, the background returns data and establishes a message queue, in which the data includes the waiting status and the message queue number; the message queue uses wesocket or http polling.
[0053] Step 7. After the previous task is processed, the monitoring system created in step 1 returns the message queue data to the front end. After receiving the data, the front end performs the following processing:
[0054] Step 71. Determine whether there is a corresponding event based on the data returned by the message body, and if so, proceed to the next step;
[0055] Step 72: Categorize and process the events in the message body, and send the events via $emit;
[0056] Step 73. The listener established in the page in step 5 will receive the corresponding event and enter data update and view update according to the corresponding data;
[0057] Step 74. After the event processing is completed, update the corresponding message number;
[0058] Step 75. Pages can send events to other pages through $emit to update data, forming a fixed data update sequence;
[0059] Step 76. The page needs to stop listening to events to release resources during the destruction cycle.
[0060] A system for sending messages and updating data, comprising:
[0061] Encapsulation module: The encapsulation module uses the publish-subscribe mode to encapsulate messages / events, and processes different events when receiving messages through websocket or https polling request communication;
[0062] The sending module sends the corresponding event tasks to each page and implements the channel for receiving ajax messages on the page.
[0063] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the method for sending a message and updating data is implemented.
[0064] A computer-readable storage medium stores a computer program, which implements the above-mentioned method of sending messages and updating data when executed by a processor.
[0065] The present invention adopts a method of sending messages / events to various interfaces in a publish-subscribe mode, and processes delayed messages through websocket and http polling, which can solve the problem of long page waiting time caused by delay in requesting data and affect the experience, and at the same time solve the limitation that messages sent in the global state manager cannot be received at a fixed point.
[0066] The above are only preferred embodiments of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.
Claims
1. A method for sending a message and updating data, characterized in that: Adopt the publish-subscribe mode to encapsulate messages / events, and process different events when receiving messages through websocket or https polling request communication, and send corresponding event tasks to each page, so as to realize the ajax message receiving channel on the page; The specific steps include: Step 1. Encapsulate the message / event monitoring system of the publish-subscribe model; Step 2. Specify the communication protocol between the front-end and back-end, set the message number of the data return, which is used to update the requested queue; specify the event tag event returned in the interface, which is used to issue different event subscriptions to update data in real time; Step 3. When the page that needs to be updated is initialized, use the $on monitoring system to monitor the events of the corresponding tags; Step 4. Create a message request event, set the message number queue, and save it in local storage; Step 5. Create a binding listener event $on when the corresponding page is initialized, and specify the corresponding event key; Step 6. The page sends a request that needs to be processed with a delay or for a long time. After receiving the request, the background returns data and establishes a message queue, in which the data includes the waiting status and the message queue number; the message queue adopts wesocket or http polling method; Step 7. After the previous task is processed, the monitoring system created in step 1 returns the message queue data to the front end; The monitoring system includes: Set the event queue Queue object; Create a monitoring method $on, set key and function as input parameters, and assign corresponding functions to different keys; Establish a message / event publishing system $emit, pass key and data and process and distribute them; In step 7, the front end performs the following processing after receiving the data: Step 71. Determine whether there is a corresponding event based on the data returned by the message body, and if so, proceed to the next step; Step 72: Categorize and process the events in the message body, and send the events via $emit; Step 73. The listener established in the page in step 5 will receive the corresponding event and enter data update and view update according to the corresponding data; Step 74. After the event processing is completed, update the corresponding message number.
2. A method for sending messages and updating data according to claim 1, characterized in that: The monitoring system also includes: establishing a monitoring destruction method to release resources.
3. A method for sending messages and updating data according to claim 1, characterized in that: After receiving the data, the front end also performs the following processing: Step 75. Pages can send events to other pages through $emit to update data, forming a fixed data update order.
4. A method for sending messages and updating data according to claim 3, characterized in that: After receiving the data, the front end also performs the following processing: Step 76. The page needs to stop listening to events to release resources during the destruction cycle.
5. A system for sending messages and updating data, characterized in that: Executing the method according to any one of claims 1 to 4, comprising: Encapsulation module, which uses a publish-subscribe model to encapsulate messages / events, and processes different events when receiving messages through a request communication method such as websocket or https polling; The sending module sends corresponding event tasks to each page and implements the channel for receiving ajax messages on the page.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, a method for sending messages and updating data according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a method for sending messages and updating data according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Page message distribution method and device, equipment and storage medium
CN113051511A
Event message management method, electronic equipment and computer readable storage medium
CN115016954A