Message push methods, devices, storage media, and processors
By acquiring business scenario and resource information, WebSocket or SSE is dynamically selected as the communication method, solving the problem of inflexible communication methods in existing technologies and realizing the flexibility, adaptability and efficiency of message push.
Patent Information
- Application Number
- CN202410811050.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2044-06-21
AI Technical Summary
Existing message push methods cannot flexibly adapt to various scenarios after the communication method is determined, resulting in an inflexible communication method that cannot meet various needs.
By acquiring current business scenario information and resource information, the system dynamically selects WebSocket or SSE as the communication method based on preset strategy decision rules, and determines the most suitable communication method based on factors such as client support, changes in business scenarios, real-time communication needs, and system resource utilization.
It achieves flexible adaptability to communication methods, is applicable to various scenarios, ensures the correct implementation of message push, and improves the efficiency and applicability of message push.
Smart Images

Figure CN118694815B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a message push method, a message push device, a machine-readable storage medium, a computer program product, and a processor. Background Technology
[0002] Push notifications refer to servers sending messages to clients, typically through instant messaging tools. The development of push notification technology has made it easier for developers to implement real-time communication and message delivery functions, providing users with a better experience and service.
[0003] Real-time communication methods include: short polling, long polling (Comet), server-sent events (SSE), and the WebSocket protocol. Short polling is unsuitable for web applications with a large number of concurrent users and where performance is critical. Long polling is simple to implement but consumes high resources and suffers from latency. Server-sent events offer good real-time performance and are suitable for real-time notifications, but only support one-way communication from server to client. The WebSocket protocol enables bidirectional real-time communication with high performance, but requires specific server support. For more flexible real-time communication, WebSocket or SSE can be chosen for message push.
[0004] However, once a communication method is determined, the existing message push method uses that method for every message push request, which makes the communication method of message push not flexible enough and cannot meet the needs of various scenarios. Summary of the Invention
[0005] The purpose of this application is to provide a message push method, a message push device, a machine-readable storage medium, a computer program product, and a processor. This message push method can determine the communication method according to actual conditions. Compared to existing methods that select only one communication method for message push, this method makes the communication method more flexible, applicable to various scenarios, and ensures the correct implementation of message push.
[0006] To achieve the above objectives, the first aspect of this application provides a message push method, the message push method comprising:
[0007] In response to a push notification request, obtain current business scenario information and current resource information;
[0008] Based on the message push request, current business scenario information, and current resource information, the corresponding communication method is determined according to the preset strategy decision rules.
[0009] Get the message to be sent;
[0010] The message to be sent is pushed using the corresponding communication method.
[0011] The step of determining the corresponding communication method based on the message push request, current business scenario information, and current resource information, according to preset strategy decision rules, includes:
[0012] Based on the message push request, determine whether the client supports WebSocket;
[0013] If it is determined that the client supports WebSocket, it is determined whether the business scenario has changed based on the current business scenario information;
[0014] If the business scenario remains unchanged, determine whether real-time communication is required for the current business scenario based on the current business scenario information.
[0015] If it is determined that real-time communication is not required in the current business scenario, the system resource utilization rate is judged based on the current resource information to see if it exceeds the threshold.
[0016] If the system resource utilization rate is determined to be within the threshold, the corresponding communication method is determined to be WebSocket.
[0017] In this embodiment of the application, it also includes:
[0018] If it is determined that the client does not support WebSocket, the corresponding communication method is determined to be SSE;
[0019] When the business scenario changes, the corresponding communication method is determined to be WebSocket.
[0020] Given that the current business scenario requires real-time communication, the corresponding communication method is determined to be WebSocket.
[0021] If the system resource utilization rate exceeds the threshold, the corresponding communication method is determined to be SSE.
[0022] In this embodiment of the application, determining whether the business scenario has changed based on the current business scenario information includes:
[0023] Obtain a first timestamp and a second timestamp, wherein the first timestamp is the timestamp when the message push request arrives at the server, and the second timestamp is the timestamp when the server completes the response to the message push request;
[0024] Calculate the difference between the first timestamp and the second timestamp to obtain the time difference;
[0025] Based on the time difference, determine whether the network conditions meet the requirements;
[0026] If the network conditions are determined to meet the requirements, it is then determined whether the business scenario has changed based on the current business scenario information.
[0027] In this embodiment of the application, determining whether real-time communication is required for the current business scenario based on the current business scenario information includes:
[0028] Determine whether the current business requires real-time updates;
[0029] If it is confirmed that the current business requires real-time updates, the corresponding communication method is determined to be WebSocket;
[0030] If it is confirmed that the current business does not require real-time updates, determine whether the current business scenario requires real-time communication based on the current business scenario information.
[0031] In this embodiment of the application, the current resource information includes CPU utilization and memory utilization;
[0032] The step of determining whether the system resource utilization rate exceeds the threshold based on the current resource information includes:
[0033] Determine whether both CPU utilization and memory utilization exceed their respective utilization thresholds.
[0034] If both CPU utilization and memory utilization are determined to be within their respective utilization thresholds, then the system resource utilization is determined to be within the thresholds.
[0035] In this embodiment of the application, determining whether the client supports WebSocket based on the message push request includes:
[0036] By examining the user agent header information in the request, the client's type and version information can be obtained.
[0037] Based on the client's type and version information, determine whether the client supports WebSocket.
[0038] A second aspect of this application provides a message push device, the message push device comprising:
[0039] The first acquisition module is used to respond to message push requests and acquire current business scenario information and current resource information;
[0040] The determination module is used to determine the corresponding communication method based on the message push request, current business scenario information, and current resource information, according to a preset strategy decision rule. This includes: determining whether the client supports WebSocket based on the message push request; if the client supports WebSocket, determining whether the business scenario has changed based on the current business scenario information; if the business scenario has not changed, determining whether real-time communication is required based on the current business scenario information; if real-time communication is not required, determining whether the system resource utilization rate exceeds a threshold based on the current resource information; and if the system resource utilization rate does not exceed the threshold, determining that the corresponding communication method is WebSocket.
[0041] The second acquisition module is used to acquire messages to be sent;
[0042] The push module is used to push the message to be sent using the corresponding communication method.
[0043] A third aspect of this application provides a processor configured to perform the aforementioned message push method.
[0044] A fourth aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the aforementioned message push method.
[0045] The fifth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned message push method.
[0046] The above technical solution involves responding to a message push request by acquiring current business scenario information and current resource information; based on the message push request, current business scenario information, and current resource information, determining the corresponding communication method according to preset strategy decision rules; acquiring the message to be sent; and pushing the message to be sent using the corresponding communication method. By using the message push request, the current business scenario information, and current resource information, and following preset strategy decision rules, a suitable communication method can be determined, ensuring that the communication method changes with each message push request. Compared to existing methods that select only one communication method for message push, this method is more flexible, applicable to multiple scenarios, and guarantees the correct implementation of message push. Furthermore, the determination of the corresponding communication method comprehensively considers multiple factors, including the message push request, the current business scenario, and current resources, making the corresponding communication method more suitable for the current scenario and further ensuring the correct implementation of message push.
[0047] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0048] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings:
[0049] Figure 1 This illustration shows an application environment diagram of the message push method according to an embodiment of this application;
[0050] Figure 2 The schematic diagram illustrates a flowchart of a message push method according to an embodiment of this application;
[0051] Figure 3 This illustration schematically shows a flowchart of the message push strategy decision-making process according to an embodiment of this application;
[0052] Figure 4 This schematic diagram illustrates a structural block diagram of a message push device according to an embodiment of this application;
[0053] Figure 5 The diagram illustrates the internal structure of a computer device according to an embodiment of this application.
[0054] Explanation of reference numerals in the attached figures
[0055] 102-Terminal; 104-Server; 410-First Acquisition Module; 420-Determination Module; 430-Second Acquisition Module; 440-Push Module; A01-Processor; A02-Network Interface; A03-Internal Memory; A04-Display Screen; A05-Input Device; A06-Non-Volatile Storage Medium; B01-Operating System; B02-Computer Program. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0057] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of the components in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0058] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0059] The acquisition, transmission, storage, use, and processing of data in this application comply with relevant national laws and regulations. Furthermore, it should be noted that existing industry solutions such as software, components, and models may be mentioned in the embodiments of this application. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0060] The message push method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. Based on the message push request, the current business scenario information, and the current resource information, and according to preset strategy decision rules, the appropriate communication method can be determined. This allows the communication method to change flexibly according to the actual situation. Compared to the existing method of selecting one communication method for message push, this method makes the communication method more flexible, applicable to multiple scenarios, and ensures the correct implementation of message push. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0061] Figure 2 A schematic flowchart illustrating a message push method according to an embodiment of this application is shown. Figure 2 As shown, in one embodiment of this application, a message push method is provided. This embodiment mainly applies this method to the above-mentioned... Figure 1Taking terminal 102 (or server 104) as an example, the following steps are included:
[0062] Step 210: In response to the message push request, obtain the current business scenario information and current resource information;
[0063] In this embodiment, the message push request is sent by the client. After receiving the message push request from the client, the server obtains the current business scenario information and current resource information. The message push request includes the client type, version information, etc., and the current business scenario information includes the business scenario type, business logic, order status, personalized recommendations, etc. The current resource information can be obtained by monitoring the server's CPU, memory, and other resource usage. Specifically, it can be obtained by separately obtaining the CPU utilization rate and memory utilization rate. The CPU utilization rate can be obtained by returning a floating-point number between 0 and 1, representing the system's CPU load. The memory utilization rate can be obtained by calculating the ratio of used memory to maximum memory.
[0064] Step 220: Based on the message push request, current business scenario information, and current resource information, determine the corresponding communication method according to the preset strategy decision rules;
[0065] In this embodiment, the aforementioned preset strategy decision rules are pre-set and can be used to select the communication method based on the system's autonomous decision-making logic. The strategy decision rules can be comprehensively set based on factors such as system requirements, client support, and performance considerations. In specific implementation, this can be achieved by introducing a decision module or strategy class. By combining message push requests, current business scenario information, and current resource information with the strategy decision rules, the appropriate communication method can be determined in real time.
[0066] In some embodiments, in order to achieve real-time communication, the preset strategy decision rules are used to determine whether the communication method is WebSocket or SSE; the system can choose to use SSE or WebSocket for communication based on its autonomous decision-making logic.
[0067] Accordingly, determining the corresponding communication method based on the message push request, current business scenario information, and current resource information, according to preset strategy decision rules, includes the following steps:
[0068] First, based on the message push request, determine whether the client supports WebSocket;
[0069] In this embodiment, determining whether a client supports WebSocket can be achieved by the backend server, upon receiving a push notification request from the client, checking the User-Agent header in the request to obtain the client's type and version information. Based on this information, the server can then determine whether the client supports WebSocket. The User-Agent is part of the Hypertext Transfer Protocol (HTTP) request header, used to identify the user agent (e.g., a browser, search engine crawler). The user agent informs the server of its type, operating system, browser version, etc., through the User-Agent header. The User-Agent string typically contains the string "Mozilla," used to transmit browser and operating system information to the website server. The User-Agent header information allows for a quick and accurate determination of whether a client supports WebSocket.
[0070] In practice, the class used to define and implement different communication strategies can determine the client type based on the user agent header information. When the backend detects that the user agent contains the string "Mozilla", it may assume that the client is a regular web browser and decide to use SSE; otherwise, it will further determine whether to use WebSocket for communication.
[0071] Then, if it is determined that the client supports WebSocket, it is determined whether the business scenario has changed based on the current business scenario information;
[0072] In this embodiment, if the client supports WebSocket, it is further determined whether to use WebSocket for communication. The determination of whether the business scenario has changed can be based on whether there is an order status change notification or a personalized recommendation notification. Having either one is sufficient to confirm a change in the business scenario; conversely, if neither is present, the business scenario is considered unchanged. The order status refers to creating an order, processing an order, shipping, etc., while personalized recommendations refer to providing users with personalized product or content recommendations.
[0073] In some embodiments, to further determine whether normal communication can be achieved using WebSocket, after determining that the client supports WebSocket, the network conditions can be assessed on the server side by monitoring the client's network response time. The step of determining whether the business scenario has changed based on the current business scenario information includes the following steps:
[0074] The first step is to obtain a first timestamp and a second timestamp. The first timestamp is the timestamp when the message push request arrives at the server, and the second timestamp is the timestamp when the server completes the response to the message push request.
[0075] In this embodiment, the first timestamp is obtained by monitoring the network response time of the client, and the second timestamp can be obtained by recording the time when the server completes the response.
[0076] The second step is to calculate the difference between the first timestamp and the second timestamp to obtain the time difference;
[0077] The third step is to determine whether the network conditions meet the requirements based on the time difference.
[0078] In this embodiment, the time difference between the first timestamp and the second timestamp is calculated, and then it is determined whether the time difference is within a preset response time range. If it is, the requirement is met; otherwise, it is not. The preset response time range can be set in advance according to actual needs.
[0079] The fourth step is to determine whether the business scenario has changed based on the current business scenario information, provided that the network conditions meet the requirements.
[0080] In this embodiment, if the network conditions meet the requirements, WebSocket communication can be used to further determine whether the business scenario has changed based on the current business scenario information. Conversely, if the network conditions do not meet the requirements, SSE is used directly for communication.
[0081] In the above implementation process, after confirming that the client supports WebSocket, the network conditions are evaluated by monitoring the client's network response time. If the network conditions meet the requirements, it is further determined whether the business scenario has changed based on the current business scenario information. If the network conditions do not meet the requirements, SSE is used directly for communication, thereby ensuring that WebSocket can be used for normal communication and thus ensuring the normal push of messages.
[0082] Then, if it is determined that the business scenario has not changed, it is determined whether the current business scenario requires real-time communication based on the current business scenario information;
[0083] In this embodiment, after determining that the business scenario has not changed, it is further possible to determine whether the current business scenario requires real-time communication based on the business scenario type of the current business scenario information.
[0084] In some embodiments, determining whether real-time communication is required for the current business scenario based on the current business scenario information includes the following steps:
[0085] The first step is to determine whether the current business requires real-time updates;
[0086] The second step is to determine the corresponding communication method as WebSocket after confirming that the current business requires real-time updates.
[0087] The third step is to determine whether real-time communication is required for the current business scenario, based on the current business scenario information, if it is confirmed that the current business scenario does not require real-time updates.
[0088] In this embodiment, the message push method can be determined directly based on the real-time requirements in the business logic. If the business requires real-time updates, it can directly specify the use of WebSocket for communication without additional real-time checks; otherwise, it is determined whether the current business scenario requires real-time communication based on the current business scenario information.
[0089] By determining whether the current business requires real-time updates, it is possible to quickly decide whether to use WebSocket for communication, avoiding additional judgments on real-time performance, saving time, and improving message push efficiency.
[0090] Then, if it is determined that the current business scenario does not require real-time communication, the system resource utilization rate is judged based on the current resource information to see if it exceeds the threshold.
[0091] In this embodiment, the system resource utilization rate can reflect the server performance and load. Based on the server load, a communication protocol that matches the current server performance can be selected.
[0092] In some embodiments, the current resource information includes CPU utilization and memory utilization; correspondingly, determining whether the system resource utilization exceeds a threshold based on the current resource information includes:
[0093] The first step is to determine whether both CPU utilization and memory utilization exceed their respective utilization thresholds.
[0094] In this embodiment, the corresponding utilization thresholds refer to the thresholds for CPU utilization and memory utilization. These thresholds can be preset according to requirements and can be the same or different. For example, if the corresponding utilization thresholds are both set to 90%, it is possible to determine whether the CPU utilization and memory utilization exceed 90% respectively.
[0095] The second step is to determine that the system resource utilization rate does not exceed the threshold if both CPU utilization and memory utilization rate do not exceed the corresponding utilization rate threshold.
[0096] In this embodiment, if neither CPU utilization nor memory utilization exceeds the corresponding utilization threshold, it is determined that the system resource utilization has not exceeded the threshold; otherwise, it is determined that the system resource utilization has exceeded the threshold.
[0097] By determining whether both CPU utilization and memory utilization exceed their respective thresholds, the system resource utilization can be quickly and accurately determined, thus enabling the appropriate communication method to be identified promptly and accurately.
[0098] Finally, after confirming that the system resource utilization rate did not exceed the threshold, the corresponding communication method was determined to be WebSocket.
[0099] In this embodiment, if the system resource utilization rate is lower than the set threshold, it means that the system resources can meet the requirements of WebSocket, so WebSocket is selected to be used; otherwise, SSE is selected to be used.
[0100] In the above implementation process, the decision to select WebSocket as the communication method is made in real time based on four factors: whether the client supports WebSocket, whether the business scenario has changed, whether the current business scenario requires real-time communication, and whether the system resource utilization exceeds the threshold. The determination factors are more comprehensive. Since the communication method is determined by considering multiple factors, the communication method is more accurate, which helps to ensure the correct implementation of message push.
[0101] In some embodiments, it also includes:
[0102] If it is determined that the client does not support WebSocket, the corresponding communication method is determined to be SSE;
[0103] When the business scenario changes, the corresponding communication method is determined to be WebSocket.
[0104] Given that the current business scenario requires real-time communication, the corresponding communication method is determined to be WebSocket.
[0105] If the system resource utilization rate exceeds the threshold, the corresponding communication method is determined to be SSE.
[0106] In this embodiment, when the client does not support WebSocket, SSE communication is used directly; otherwise, it is further determined whether to use WebSocket communication. If the business scenario changes, WebSocket communication is used directly; if the current business scenario requires real-time communication, WebSocket communication is used directly; when the system resource utilization exceeds a threshold, SSE communication is used. This satisfies the needs of different business scenarios.
[0107] The following section provides a detailed explanation of the strategy decision-making rules using specific examples. Please refer to [link / reference]. Figure 3 , Figure 3 The diagram illustrates a message push strategy decision-making flowchart according to an embodiment of this application. First, it determines whether the client supports WebSocket. If not, SSE is used directly. Otherwise, it further determines whether there is an order status change notification or a personalized recommendation notification. If yes, WebSocket is used directly. Otherwise, it further determines whether there is a non-real-time communication requirement. If yes, WebSocket is used directly. Otherwise, it further determines whether the system resource utilization exceeds a threshold. If yes, SSE is used; otherwise, WebSocket is used.
[0108] It should be noted that the above-mentioned preset strategy decision rules are used to determine whether the communication method is WebSocket or SSE. You can also set strategy decision rules according to actual needs to determine different communication methods. The process of determining the corresponding communication method is similar to the process of determining whether the communication method is WebSocket or SSE, so it will not be described again here.
[0109] Step 230: Obtain the message to be sent;
[0110] In this embodiment, a message push manager class can be created to receive messages to be sent and select a specific push implementation class to push the message based on the corresponding communication method. The message push manager can also provide methods to receive and process messages.
[0111] Step 240: Push the message to be sent using the corresponding communication method.
[0112] In this embodiment, the controller layer can handle client requests based on the selected communication method. If WebSocket is selected, the corresponding processing logic is invoked; if SSE is selected, the corresponding data stream is returned. In the specific implementation of pushing messages to be sent, an abstract message push interface can be defined, containing methods for sending and subscribing to messages. This interface can be a base class or an interface definition, which can be implemented by concrete implementation classes of different communication methods.
[0113] For SSE push implementation, a concrete SSE push implementation class can be created. This class is responsible for establishing an SSE connection with the client and implementing real-time message push functionality. The creation process includes: a) First, an endpoint or route capable of handling SSE connections needs to be created on the server side. b) In this endpoint or route, an HTTP connection is established with the client, and messages are sent to the client after the connection is established. c) The server can periodically send messages to the client, and the client listens for these messages to achieve real-time updates. For WebSocket push implementation, a concrete WebSocket push implementation class can be created. This class is responsible for establishing a WebSocket connection with the client and conducting bidirectional communication through WebSocket. This functionality can be directly implemented using the WebSocket Application Programming Interface (API) of the Java programming language.
[0114] On the client side, messages can be subscribed to and processed according to the corresponding communication method (SSE or WebSocket). For SSE, the client can subscribe to and receive messages through an EventSource. For WebSocket, the WebSocket API can be used to subscribe to and process received messages. Specifically, the client can be configured with either SSE or WebSocket as the communication method. The server returns a corresponding response based on the selected communication protocol, specifically an identifier in the message push request response indicating whether the client uses SSE or WebSocket. The client can also choose the appropriate communication method based on browser support. For example, if the browser does not support WebSocket, SSE will be used directly.
[0115] In the above implementation process, in response to a message push request, current business scenario information and current resource information are obtained; based on the message push request, current business scenario information, and current resource information, the corresponding communication method is determined according to a preset strategy decision rule; the message to be sent is obtained; and the message to be sent is pushed using the corresponding communication method. By using the message push request, the current business scenario information, and current resource information, and according to the preset strategy decision rule, the appropriate communication method can be determined, thus ensuring that the communication method changes with each message push request. Compared to the existing method of selecting a single communication method for message push, this method is more flexible, applicable to multiple scenarios, and ensures the correct implementation of message push. Furthermore, the determination of the corresponding communication method is based on a comprehensive consideration of multiple factors, including the message push request, the current business scenario, and current resources, making the corresponding communication method more suitable for the current scenario and further guaranteeing the correct implementation of message push.
[0116] Figure 2 This is a flowchart illustrating a message push method in one embodiment. It should be understood that, although... Figure 2 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0117] This embodiment provides a message push device; please refer to [link / reference]. Figure 4 , Figure 4 A schematic block diagram of a message push device according to an embodiment of this application is shown. The message push device includes a first acquisition module 410, a determination module 420, a second acquisition module 430, and a push module 440, wherein:
[0118] The first acquisition module 410 is used to acquire current business scenario information and current resource information in response to a message push request;
[0119] The determination module 420 is used to determine the corresponding communication method based on the message push request, current business scenario information and current resource information, according to preset strategy decision rules;
[0120] The second acquisition module 430 is used to acquire the message to be sent.
[0121] The push module 440 is used to push the message to be sent using the corresponding communication method.
[0122] The preset strategy decision rules are used to determine whether the communication method is WebSocket or SSE.
[0123] The determining module 420 includes:
[0124] The first judgment unit is used to determine whether the client supports WebSocket based on the message push request;
[0125] The second judgment unit is used to determine whether the business scenario has changed based on the current business scenario information, provided that the client supports WebSocket.
[0126] The third judgment unit is used to determine whether real-time communication is required for the current business scenario based on the current business scenario information, provided that the business scenario has not changed.
[0127] The fourth judgment unit is used to determine whether the system resource utilization rate exceeds a threshold based on the current resource information when it is determined that real-time communication is not required in the current business scenario.
[0128] The first determining unit is used to determine that the corresponding communication method is WebSocket when the system resource utilization rate does not exceed the threshold.
[0129] The determining module 420 further includes:
[0130] The second determining unit is used to determine that the corresponding communication method is SSE when it is determined that the client does not support WebSocket.
[0131] The third determining unit is used to determine that the corresponding communication method is WebSocket when the business scenario changes.
[0132] The fourth determining unit is used to determine that the corresponding communication method is WebSocket when it is determined that the current business scenario requires real-time communication.
[0133] The fifth determining unit is used to determine the corresponding communication method as SSE when the system resource utilization rate exceeds the threshold.
[0134] The second determination unit includes:
[0135] The time acquisition subunit is used to acquire a first timestamp and a second timestamp, wherein the first timestamp is the timestamp when the message push request arrives at the server, and the second timestamp is the timestamp when the server completes the response to the message push request;
[0136] The calculation subunit is used to calculate the difference between the first timestamp and the second timestamp to obtain the time difference;
[0137] The condition judgment subunit is used to determine whether the network conditions meet the requirements based on the time difference; and if the network conditions meet the requirements, it determines whether the business scenario has changed based on the current business scenario information.
[0138] The third judgment unit includes:
[0139] An update judgment subunit is used to determine whether the current business needs real-time updates; and if it is confirmed that the current business needs real-time updates, the corresponding communication method is determined to be WebSocket; if it is confirmed that the current business does not need real-time updates, the current business scenario is determined based on the current business scenario information to determine whether the current business scenario needs real-time communication.
[0140] The current resource information includes CPU utilization and memory utilization.
[0141] The fourth judgment unit includes:
[0142] The threshold judgment subunit is used to determine whether both CPU utilization and memory utilization exceed the corresponding utilization thresholds; and if it is determined that neither CPU utilization nor memory utilization exceeds the corresponding utilization thresholds, it determines that the system resource utilization does not exceed the threshold.
[0143] The first determination unit includes:
[0144] The inspection subunit is used to obtain client type and version information by inspecting the user agent header information in the request;
[0145] The system supports a judgment subunit, which is used to determine whether the client supports WebSocket based on the client's type and version information.
[0146] The message push device includes a processor and a memory. The first acquisition module 410, the determination module 420, the second acquisition module 430, and the push module 440 are all stored in the memory as program units. The processor executes the program modules stored in the memory to implement the corresponding functions.
[0147] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and message push methods can be implemented by adjusting kernel parameters.
[0148] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0149] This application provides a machine-readable storage medium storing a program that, when executed by a processor, implements the aforementioned message push method.
[0150] This application provides a processor for running a program, wherein the program executes the above-described message push method during runtime.
[0151] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown in the figure, the computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements a message push method. The display screen A04 can be an LCD screen or an e-ink display screen. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0152] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0153] In one embodiment, the message push device provided in this application can be implemented as a computer program, and the computer program can be implemented as follows: Figure 5 It runs on the computer device shown. The computer device's memory can store the various program modules that make up the message push device, for example, Figure 4 The diagram shows a first acquisition module 410, a determination module 420, a second acquisition module 430, and a push module 440. The computer program comprised of these modules causes the processor to execute the steps of the message push methods in the various embodiments of this application described in this specification.
[0154] Figure 5 The computer equipment shown can be used as follows Figure 4 The first acquisition module 410 in the message push device shown executes step 210. The computer device can execute step 220 via the determination module 420. The computer device can execute step 230 via the second acquisition module 430. The computer device can execute step 240 via the push module 440.
[0155] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the following method steps:
[0156] In response to a push notification request, obtain current business scenario information and current resource information;
[0157] Based on the message push request, current business scenario information, and current resource information, the corresponding communication method is determined according to the preset strategy decision rules.
[0158] Get the message to be sent;
[0159] The message to be sent is pushed using the corresponding communication method.
[0160] The step of determining the corresponding communication method based on the message push request, current business scenario information, and current resource information, according to preset strategy decision rules, includes:
[0161] Based on the message push request, determine whether the client supports WebSocket;
[0162] If it is determined that the client supports WebSocket, it is determined whether the business scenario has changed based on the current business scenario information;
[0163] If the business scenario remains unchanged, determine whether real-time communication is required for the current business scenario based on the current business scenario information.
[0164] If it is determined that real-time communication is not required in the current business scenario, the system resource utilization rate is judged based on the current resource information to see if it exceeds the threshold.
[0165] If the system resource utilization rate is determined to be within the threshold, the corresponding communication method is determined to be WebSocket.
[0166] In one embodiment, it also includes:
[0167] If it is determined that the client does not support WebSocket, the corresponding communication method is determined to be SSE;
[0168] When the business scenario changes, the corresponding communication method is determined to be WebSocket.
[0169] Given that the current business scenario requires real-time communication, the corresponding communication method is determined to be WebSocket.
[0170] If the system resource utilization rate exceeds the threshold, the corresponding communication method is determined to be SSE.
[0171] In one embodiment, determining whether the business scenario has changed based on the current business scenario information includes:
[0172] Obtain a first timestamp and a second timestamp, wherein the first timestamp is the timestamp when the message push request arrives at the server, and the second timestamp is the timestamp when the server completes the response to the message push request;
[0173] Calculate the difference between the first timestamp and the second timestamp to obtain the time difference;
[0174] Based on the time difference, determine whether the network conditions meet the requirements;
[0175] If the network conditions are determined to meet the requirements, it is then determined whether the business scenario has changed based on the current business scenario information.
[0176] In one embodiment, determining whether real-time communication is required for the current business scenario based on the current business scenario information includes:
[0177] Determine whether the current business requires real-time updates;
[0178] If it is confirmed that the current business requires real-time updates, the corresponding communication method is determined to be WebSocket;
[0179] If it is confirmed that the current business does not require real-time updates, determine whether the current business scenario requires real-time communication based on the current business scenario information.
[0180] In one embodiment, the current resource information includes CPU utilization and memory utilization;
[0181] The step of determining whether the system resource utilization rate exceeds the threshold based on the current resource information includes:
[0182] Determine whether both CPU utilization and memory utilization exceed their respective utilization thresholds.
[0183] If both CPU utilization and memory utilization are determined to be within their respective utilization thresholds, then the system resource utilization is determined to be within the thresholds.
[0184] In one embodiment, determining whether the client supports WebSocket based on the message push request includes:
[0185] By examining the user agent header information in the request, the client's type and version information can be obtained.
[0186] Based on the client's type and version information, determine whether the client supports WebSocket.
[0187] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0188] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0189] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0190] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0191] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0192] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0193] Computer-readable media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0194] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0195] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A message pushing method, characterized by, The message pushing method comprises: In response to a message pushing request, obtaining current service scenario information and current resource information; Based on the message pushing request, the current service scenario information and the current resource information, a corresponding communication mode is determined according to a preset strategy decision rule; Obtaining a to-be-sent message; The to-be-sent message is pushed by using the corresponding communication mode; Wherein, based on the message pushing request, the current service scenario information and the current resource information, the corresponding communication mode is determined according to the preset strategy decision rule, comprising: Based on the message pushing request, it is judged whether the client supports WebSocket; In the case where it is determined that the client supports WebSocket, it is judged whether the service scenario changes based on the current service scenario information; In the case where it is determined that the service scenario does not change, it is judged whether the current service scenario needs real-time communication based on the current service scenario information; In the case where it is determined that the current service scenario does not need real-time communication, it is judged whether the system resource utilization rate exceeds a threshold based on the current resource information; In the case where it is determined that the system resource utilization rate does not exceed the threshold, the corresponding communication mode is determined to be WebSocket.
2. The method of claim 1, wherein, Further comprising: In the case where it is determined that the client does not support WebSocket, the corresponding communication mode is determined to be SSE; In the case where it is determined that the service scenario changes, the corresponding communication mode is determined to be WebSocket; In the case where it is determined that the current service scenario needs real-time communication, the corresponding communication mode is determined to be WebSocket; In the case where it is determined that the system resource utilization rate exceeds the threshold, the corresponding communication mode is determined to be SSE.
3. The method of claim 1, wherein, The current service scenario information is used to judge whether the service scenario changes, comprising: Obtaining a first timestamp and a second timestamp, the first timestamp being the timestamp of the message pushing request arriving at the server, and the second timestamp being the timestamp of the server completing the message pushing request response; The difference between the first timestamp and the second timestamp is calculated to obtain a time difference; Based on the time difference, it is judged whether the network condition meets the requirements; In the case where it is determined that the network condition meets the requirements, it is judged whether the service scenario changes based on the current service scenario information.
4. The method of claim 1, wherein, The current service scenario information is used to judge whether the current service scenario needs real-time communication, comprising: It is judged whether the current business needs real-time update; In the case where it is confirmed that the current business needs real-time update, the corresponding communication mode is determined to be WebSocket; In the case where it is confirmed that the current business does not need real-time update, it is judged whether the current service scenario needs real-time communication based on the current service scenario information.
5. The method of claim 1, wherein, The current resource information comprises CPU usage and memory usage; The current resource information is used to judge whether the system resource utilization rate exceeds a threshold, comprising: It is respectively judged whether the CPU usage and the memory usage exceed the corresponding usage threshold; In a case where it is determined that neither the CPU usage nor the memory usage exceeds the corresponding usage threshold, it is determined that the system resource utilization does not exceed the threshold.
6. The method of claim 1, wherein, The determining whether the client supports WebSocket based on the message push request comprises: The type and version information of the client are obtained by checking the user agent header information in the request. The determining whether the client supports WebSocket based on the type and version information of the client.
7. A message pushing apparatus characterized by comprising: The message push device comprises: A first obtaining module configured to obtain current business scenario information and current resource information in response to a message push request; A determining module configured to determine a corresponding communication mode based on the message push request, the current business scenario information and the current resource information according to a preset policy decision rule, including: determining whether the client supports WebSocket based on the message push request; in a case where it is determined that the client supports WebSocket, determining whether a business scenario changes based on the current business scenario information; in a case where it is determined that the business scenario does not change, determining whether the current business scenario needs real-time communication based on the current business scenario information; in a case where it is determined that the current business scenario does not need real-time communication, determining whether system resource utilization exceeds a threshold based on the current resource information; in a case where it is determined that the system resource utilization does not exceed the threshold, determining that the corresponding communication mode is WebSocket; A second obtaining module configured to obtain a to-be-sent message; A pushing module configured to push the to-be-sent message by using the corresponding communication mode.
8. A processor, comprising: The message push device is configured to perform the message push method according to any one of claims 1 to 6.
9. A machine-readable storage medium having stored thereon instructions, the instructions being executable by a machine to cause the machine to perform operations comprising: The instruction, when executed by a processor, causes the processor to be configured to perform the message push method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the message push method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Message pushing method, message pushing server, client and system
CN107124440A
Method and device for pushing information in real time, computer equipment and storage medium
CN111092809A