Message sending, storing, pushing and subscribing method, server, message center, client and system
By combining RPC long connections with lightweight message queues, and adopting single linked list storage and sequence number processing, the real-time and resource efficiency issues of message subscription and push systems in the existing technology are solved, and efficient and flexible message processing is achieved.
Patent Information
- Application Number
- CN202510955713.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-09-05
AI Technical Summary
Existing message subscription and push systems struggle to strike a balance between real-time performance, resource efficiency, flexibility, and ease of use. Especially in small and medium-sized scenarios, it is difficult to provide lightweight, low-latency, and efficient message processing solutions.
A real-time message subscription and push method based on RPC long connection and lightweight message queue is adopted. Message objects are stored in the form of a single linked list, and each message is assigned a serial number that increases in sequence. The serial number is used as the processing basis to achieve real-time sending, storage, subscription and push of messages.
It improves the real-time and efficiency of message processing, reduces the dependence on polling and batch processing, reduces the overhead of connections and message queues, and provides flexibility and ease of use.
Smart Images

Figure CN120602547A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data processing technology, and in particular to a message sending, storage, push and subscription method, a server, a message center, a client and a system. Background Art
[0002] In distributed systems, real-time message subscription and push are core functions, widely used in scenarios such as real-time communication, database monitoring and alerting, and log collection. However, existing message subscription and push systems still face numerous challenges in practical applications. First, traditional message queues rely on polling or batch pull mechanisms, resulting in end-to-end latency typically exceeding seconds, making them unable to meet the demand for immediate feedback and lacking real-time performance. Second, currently used message subscription and push systems utilize high-frequency, short-term connections, resulting in significant connection establishment overhead, a surge in memory usage when messages accumulate, inefficient clearing of expired data, and overall low resource utilization. Furthermore, most current message queues rely heavily on middleware, requiring additional operational and maintenance costs for small and medium-sized systems and resulting in complex deployment. Finally, existing systems' routing schemes are often based on fixed rules and lack the flexibility to adapt to changing business needs. Overall, existing subscription and push mechanisms struggle to strike a balance between real-time performance, resource efficiency, flexibility, and ease of use. In particular, finding a lightweight, low-latency, and efficient message processing solution is difficult for small and medium-sized scenarios. Summary of the Invention
[0003] This application provides a message sending, storage, push and subscription method, server, message center, client and system to improve message processing efficiency.
[0004] In a first aspect, an embodiment of the present application provides a message sending method, which is applied to a server, comprising:
[0005] Generate a message based on the business data and determine the session level corresponding to the message;
[0006] The message and the session level are sent to a message center, so that the message center stores the message as a message object according to the session level. The message objects are stored in a single linked list, and the sequence number of each message object in the single linked list increases in sequence.
[0007] In a second aspect, an embodiment of the present application provides a message storage method, which is applied to a message center, including:
[0008] Receive a message and session level sent by the server, wherein the session level includes a session level and a user level, wherein the session level message corresponds to a session ID, and the user level message corresponds to a user ID list;
[0009] Create a message object for the currently received message and assign a sequence number, add the message object to the end of the singly linked list, and increase the sequence number of each message object in the singly linked list in sequence;
[0010] Update the corresponding session ID or user ID list according to the session level of the currently received message.
[0011] In a third aspect, an embodiment of the present application provides a data push sending method, which is applied to a message center and is characterized by comprising:
[0012] Obtaining a subscription request from a client, wherein the subscription request includes a starting sequence number;
[0013] Determine a list of message objects to be pushed according to the starting sequence number, the message objects in the message center are encapsulated according to the session level and stored in a single linked list, and the sequence number of each message object in the single linked list is incremented in sequence;
[0014] According to the corresponding session ID or user ID list, the message object list is pushed to the client.
[0015] In a fourth aspect, an embodiment of the present application provides a message subscription method, applied to a client, characterized by comprising:
[0016] Sending a subscription request to the message center, wherein the subscription request includes a starting sequence number;
[0017] receiving a message object list pushed by the message center according to the starting sequence number; the message objects in the message center are encapsulated according to the session level and stored in a single linked list, wherein the sequence number of each message object in the single linked list increases in sequence;
[0018] Extract the pushed message from the message object list.
[0019] In a fifth aspect, an embodiment of the present application provides a server, including:
[0020] at least one processor;
[0021] a memory communicatively connected to the at least one processor; wherein,
[0022] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the message sending method as described in the first aspect.
[0023] In a sixth aspect, an embodiment of the present application provides a message center, including:
[0024] at least one processor;
[0025] a memory communicatively connected to the at least one processor; wherein,
[0026] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the message storage method as described in the second aspect or the message push method as described in the third aspect.
[0027] In a seventh aspect, an embodiment of the present application provides a client, characterized in that it includes:
[0028] at least one processor;
[0029] a memory communicatively connected to the at least one processor; wherein,
[0030] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the message subscription method as described in the fourth aspect.
[0031] In an eighth aspect, an embodiment of the present application provides a message subscription and push system, including:
[0032] The server as described in the fifth aspect, the message center as described in the sixth aspect, and the client as described in the seventh aspect.
[0033] In the ninth aspect, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements the message sending method as described in the first aspect, the message storage method as described in the second aspect, the message push method as described in the third aspect, or the message subscription method as described in the fourth aspect.
[0034] In the tenth aspect, an embodiment of the present application provides a computer program product, including a computer program and / or instructions, which, when executed by a processor, implements the message sending method as described in the first aspect, the message storage method as described in the second aspect, the message push method as described in the third aspect, or the message subscription method as described in the fourth aspect.
[0035] The embodiment of the present application provides a message sending, storage, push and subscription method, server, message center, client and system. The message sending, storage, push and subscription method includes: determining the target column to be queried and the target table corresponding to the target column according to the filter conditions in the query statement; determining the partition column of the upper-level partition master table of the target table; if the partition column is the same as the target column, updating the filter conditions according to the partition column and the target table to obtain a new query statement; querying data according to the new query statement. The above technical solution stores messages in the form of a single linked list, and assigns a serial number that increases in sequence to each message object. The serial number can be used as a processing basis during the message sending, storage, subscription and push process. Messages can be continuously processed one by one during the long connection process, meeting real-time requirements, without relying on polling or batch processing, and without considering the overhead of a large number of connections and message queues, thereby improving message processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.
[0037] Figure 1 A schematic diagram of the interaction between a server, a client, and a message center provided in one embodiment;
[0038] Figure 2 A flowchart of a message sending method provided by an embodiment;
[0039] Figure 3 A flowchart of a data storage method provided by an embodiment;
[0040] Figure 4 A schematic diagram of a message storage process provided by an embodiment;
[0041] Figure 5 A flowchart of a data push method provided by an embodiment;
[0042] Figure 6 A schematic diagram of a message push process provided by an embodiment;
[0043] Figure 7 A schematic diagram of a resource cleanup and recycling process provided by an embodiment;
[0044] Figure 8 A flowchart of a data subscription method provided by an embodiment;
[0045] Figure 9A schematic diagram of the structure of a server provided in one embodiment;
[0046] Figure 10 A schematic diagram of the structure of a message center provided by an embodiment;
[0047] Figure 11 A schematic diagram of the structure of a client provided by an embodiment;
[0048] Figure 12 A schematic structural diagram of a data subscription and push system provided by one embodiment. DETAILED DESCRIPTION
[0049] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are intended only to illustrate the present application and are not intended to limit the present application. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions of the present application, not all of the structures.
[0050] Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the steps as sequential processes, many of the steps can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the steps can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0051] It should be noted that the concepts of "first" and "second" mentioned in the embodiments of this application are only used to distinguish different devices, modules, units or other objects, and are not used to limit the order or interdependence of the functions performed by these devices, modules, units or other objects.
[0052] In addition, the embodiments and features in the embodiments of the present application may be combined with each other unless there is any conflict.
[0053] The acquisition, storage, use, and processing of data in this application's technical solution comply with relevant national laws and regulations.
[0054] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned. They should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the relevant content of the solution.
[0055] In the embodiment of the present application, the message sending, storage, subscription and push system mainly includes the following modules: server (Server), client (Client), message center (MessageCenter). The server is mainly responsible for sending business data, message level and other content to the message center; the message center is mainly responsible for packaging business data into messages and storing messages in the form of a single linked list, supporting message push and expiration cleanup. The client is mainly responsible for subscription requests and performs the next step of processing on the received messages. In this system, a single message center can correspond to one or more servers and one or more clients. The interaction between the server, client and message center is as follows: Figure 1 shown.
[0056] This application provides a real-time message subscription and push method based on a persistent connection, namely the Remote Procedure Call Protocol (RPC) and a lightweight message queue. RPC is a protocol that requests services from a remote computer program over a network without requiring knowledge of the underlying network technology. By combining RPC persistent connections, lightweight message queues, and custom filtering rules, the application aims to address the existing technology's difficulty in balancing real-time performance, resource efficiency, flexibility, and ease of use. This approach can provide an efficient, flexible, and easy-to-use solution for small and medium-sized real-time message subscription and push scenarios.
[0057] In the embodiments of the present application, the interaction between a single server and a message center is mainly used to illustrate the message reception and storage process, the interaction between a single client and a message center is used to illustrate the message subscription and push process, and the message center background resource cleaning and recycling process is explained.
[0058] Figure 2 This is a flowchart of a message sending method provided in an embodiment of the present application. This embodiment is applicable to situations where a server generates a message. Specifically, the message sending method can be executed by a message sending device, which can be implemented in software and / or hardware and integrated into the server.
[0059] like Figure 2 As shown, the method specifically includes the following steps:
[0060] S110, generating a message according to the service data and determining a session level corresponding to the message;
[0061] In this embodiment, the server can receive user input or business data processed by other processes and generate messages based on this information. Messages can be generated by the server and sent to the message center, which can then be subscribed to by the client and pushed to the client by the message center. Messages can be divided into two levels: session level and user level. Session-level messages can be pushed only to a single session, while user-level messages can be pushed to all sessions of at least two users.
[0062] S120: Send the message and the session level to a message center, so that the message center stores the message as a message object according to the session level. The message objects are stored in a single linked list, and the sequence number of each message object in the single linked list increases in sequence.
[0063] In this embodiment, the message center can receive messages sent by the server, encapsulate them into message objects, and store them. Messages can be categorized as session-level messages and user-level messages, depending on whether a session and user ID list are set. After the server sends the message and session level to the message center, the message center can create a message for the message using the latest sequence number and set the message's session ID or user ID list, depending on the session level. Messages are stored in a single linked list with increasing sequence numbers, with the latest message added to the end of the linked list.
[0064] An embodiment of the present application provides a message sending method, in which a server sends a message to a message center, so that the message can be stored in the form of a single linked list, and each message object corresponds to a serial number that increases in sequence. The serial number can be used as a processing basis during the message sending, storage, subscription, and push process. Messages can be continuously processed one by one during a long connection process to meet real-time requirements, without relying on polling or batch processing, and without considering the overhead of a large number of connections and message queues, thereby improving message processing efficiency.
[0065] Figure 3 This is a flowchart of a message storage method provided in an embodiment of the present application. This embodiment is applicable to situations where a message center stores messages. Specifically, the message storage method can be executed by a message sending device, which can be implemented in software and / or hardware and integrated into the message center.
[0066] like Figure 3 As shown, the method specifically includes the following steps:
[0067] S210: Receive a message and session level sent by the server, where the session level includes a session level and a user level. The session level message corresponds to a session ID, and the user level message corresponds to a user ID list.
[0068] S210: Create a message object for the currently received message and assign a sequence number to it, add the message object to the end of a singly linked list, and increment the sequence number of each message object in the singly linked list.
[0069] S230: Update the corresponding session ID or user ID list according to the session level of the currently received message.
[0070] In this embodiment, the message center can receive messages sent by the server, encapsulate them into message objects, and store them. A message can include fields such as the message creation time, message number, service data, session ID, user ID list, and / or next message. Messages can be classified as session-level messages or user-level messages based on whether the session ID and user ID list are set. Specifically, if the session ID is not empty, the message is a session-level message; otherwise (the user ID list is not empty), the message is a user-level message.
[0071] Figure 4 FIG. 1 is a schematic diagram of a message storage process provided by an embodiment. Figure 4 As shown, after the server generates a message and sends it along with the session level (such as a session ID or user ID list) to the message center, the message center can create a message for it using the latest sequence number. If the highest existing sequence number is denoted as sequence, the latest message can be assigned a sequence number of sequence+1. The session ID or user ID list of the message is set based on the session level of the latest message to indicate whether the latest message is sent to a single session or to all sessions of multiple users. Messages can be stored in a singly linked list with increasing sequence numbers, with the latest message appended to the end of the list. At the same time, the message center can call the notifyAll method to wake up the message subscription thread.
[0072] A message storage method provided by an embodiment of the present application stores messages in the form of a single linked list and assigns a serial number that increases in sequence to each message object. The serial number can be used as a processing basis during the sending, storage, subscription, and push of messages. Messages can be processed one by one continuously during long connections to meet real-time requirements. It does not rely on polling or batch processing, and there is no need to consider the overhead of a large number of connections and message queues, thereby improving message processing efficiency.
[0073] Figure 5This is a flowchart of a message push method provided in an embodiment of the present application. This embodiment is applicable to situations where a message center pushes messages to a client. Specifically, the message push method can be executed by a message sending device, which can be implemented in software and / or hardware and integrated into the message center. Figure 5 As shown, the method specifically includes the following steps:
[0074] S310: Obtain a subscription request from the client, where the subscription request includes a starting sequence number;
[0075] The starting sequence number can be used to identify the starting position of the message subscribed by the client. The message center can use the starting sequence number to determine the message object to be pushed in the singly linked list. The client can send a subscription request through the messageService.subscribe(seqNum) method.
[0076] S320: Determine a list of message objects to be pushed based on the starting sequence number, encapsulate the message objects in the message center according to the session level and store them in a single linked list, and the sequence number of each message object in the single linked list increases in sequence;
[0077] For example, the client specifies the starting sequence number (seqNum) of the message in the subscription request, and the message center stores the latest message sequence number (curSeqNum). The message center can first determine whether seqNum is valid. If so, it uses seqNum as the starting sequence number of the current client and determines the message objects to be pushed accordingly.
[0078] S330: Push the message object list to the client according to the corresponding session ID or user ID list.
[0079] The message object list can contain one or more messages to be pushed, with the first message having the starting sequence number specified by the client. Each message is classified as either a session-level message or a user-level message, depending on whether a session and user ID list are set. This indicates whether the message is pushed only to clients with the same session ID or to all sessions of all users whose IDs are in the list.
[0080] In one embodiment, before pushing the message object list to the client according to the corresponding session ID or user ID list, the method further includes:
[0081] Creating a context object according to the starting sequence number, wherein the context object is used to update the sequence number during the message push process;
[0082] The context object is used as the first element of the message object list.
[0083] Exemplarily, the message center can create a context object based on the client's starting sequence number, which is used to save the message subscription auxiliary context of seqNum. In the entire message push process, context can save the client's starting sequence number, and assist in quick scanning according to the sequence number of the message during the message pull process, while updating its own saved seqNum. Before filtering all messages and preparing to push them to the client, the context object can be placed at the first position of the message object list (list) and the list can be returned. The pushed client can take out the first element of the list, convert the element into a context object and take out seqNum, so as to clarify the maximum sequence number of the message pushed this time, and based on this, the client's starting sequence number can be updated. For example, the maximum sequence number recorded in the context is used as the starting sequence number of the next subscription request.
[0084] In one embodiment, determining a list of message objects to be pushed according to the starting sequence number includes:
[0085] S3210: Acquire a message snapshot, where the data structure of the message snapshot includes a snapshot message header and a snapshot message footer;
[0086] S3220: Process the message snapshot according to the starting sequence number to obtain a list of message objects to be pushed.
[0087] For example, after initializing seqNum and the corresponding context object in the subscribe method, the message center can obtain the message center's message snapshot (messageQueueSnapshot), then call the extract method to process the message snapshot and obtain the data to be pushed. messageQueueSnapshot is a data structure that contains the snapshot message header (head) and snapshot message tail (tail). Messages are implemented as a singly linked list, so only the head and tail are needed to identify all messages to be pushed.
[0088] After executing the extract method, you will get a datas object. If datas is not empty, it means that the data that needs to be pushed to the client has been obtained. You can put context into the first element position of datas and return it; if datas is empty, it means that there is no message in the message center that needs to be pushed to the client. In this case, you can call the subscribe(ms) method of the message center to make it stuck for ms milliseconds and wait for notification to wake up. For example, after receiving a new message, the message center will call the notifyAll method, and then the stuck message center can be woken up. It is understandable that in order to prevent the situation where there are new messages after the extract method is executed and before subscribe(ms) and they cannot be pushed to the client, a "try to extract messages-no messages-wait" loop mechanism is constructed until a message that can be pushed to the client is obtained or the loop ends. The number of loops is obtained through the tryCount method, which can be overridden by the user and the number of loops can be customized.
[0089] In one embodiment, processing the snapshot according to the starting sequence number to obtain a list of message objects to be pushed includes: traversing the message objects in the message snapshot; if the sequence number of the current message object is greater than the current sequence number of the context object, adding the current message object to the list of message objects to be pushed.
[0090] For example, in the extract method, the message snapshot can be traversed. First, the message's sequence number is determined to be greater than the seqNum in the context. If it is, the message is valid; if it is, it is invalid and is skipped. If the message is valid, the isMine(message) method is called to determine whether the message meets the push conditions for the client. If so, the message is placed in the list of message objects to be returned (datas). The isMine method is an inherited and overridable method, allowing users to implement custom message filtering rules. Furthermore, if the sessionID of the message is not null, it indicates that the message will only be pushed to the current client session. Therefore, the business data pointer of the message is directly disconnected, accelerating memory release. Furthermore, regardless of whether the message meets the push conditions, as long as the message is valid, the context's seqNum is updated to the message's seqNum, ensuring that the client will not be pushed messages that have already been pushed. This process repeats until the message snapshot traversal is complete and the extract method ends.
[0091] In one embodiment, pushing the message object list to the client according to the corresponding session ID or user ID list includes:
[0092] If the corresponding session ID is not empty, the message object list is pushed to the client; otherwise, the message object list is pushed to the client corresponding to the user ID list.
[0093] Exemplarily, each message is classified as either a session-level message or a user-level message, depending on whether a session and user ID list are set. Exemplarily, when pushing a list, if the session ID corresponding to the message is not empty, the message is a session-level message and is only pushed to clients with the same session ID. If the user ID list is not empty, the message is a user-level message and can be pushed to all sessions of all users whose IDs are in the list.
[0094] Figure 6 FIG. 1 is a schematic diagram of a message push process provided by an embodiment. Figure 6As shown, the starting sequence number seqNum is initially -1, indicating that the subscription request is sent for the first time. During the message push process, seqNum can be increased by 1 one by one as the message is pushed. After each message is pushed, seqNum will be updated to the maximum sequence number of seqNum pushed this time, and can be used as the starting sequence number for the next subscription message. The message center also saves the current latest message sequence number curSeqNum. In the subscribe method, it first determines whether the seqNum of the corresponding client is valid. If seqNum < 0 or seqNum > curSeqNum, seqNum is invalid, indicating that the request is created for the first time or the process has been restarted. In this case, curSeqNum can be used as the starting sequence number, otherwise seqNum is used as the starting sequence number of the current client. The message center uses seqNum to create a context object and create datas. You can enter the "try to extract messages - no messages - wait" state through tryCount. Loop mechanism: in each attempt, obtain the message snapshot snapshot and create the variable message, that is, traverse from the snapshot message header. For each message starting from the snapshot message header, if the sequence number corresponding to the message is greater than the current sequence number in the context, the message is valid, otherwise it is invalid; when the message is valid, you can call the isMine(message) method to determine whether the message meets the conditions for being pushed to the client. If it meets the conditions, put it into the message object list (datas), and assign the context sequence number to the message sequence number, and then continue to traverse the next message to be valid; if MiscUtil.isNotEmpty(datas), that is, datas is not empty, then add context to the list as the first element, otherwise it will be stuck for 1 second to wait for a message to enter. If there is still no message, you can try to get the message next time.
[0095] In one embodiment, the method further comprises:
[0096] S340. Check the validity of the message objects at the set time interval in the following manner: check whether the corresponding message objects are expired in order according to the validity period of each message object; if the currently checked message object has expired, the currently checked message object is invalid, and the next message object is checked; if the currently checked message object has not expired, the currently checked message object and the message objects after it are all valid, and the check stops; if a valid message object exists, set the snapshot message header of the message snapshot to the first valid message object; if no valid message object exists, set the snapshot message header and snapshot message footer of the message snapshot to empty.
[0097] (1) For example, for resource cleanup and recycling, the message center can start a background thread that automatically cleans up invalid messages. When encapsulating messages, the message center can set a message creation time field for the message. In order to improve resource utilization, the effective time MESSAGE_ALIVE_TIME of all messages can be defined, and messages that have exceeded this time (expired) will become invalid messages. In order to recycle the resources occupied by invalid messages, the message center can start the related message validity check thread during initialization. The thread will execute the check method at the time interval of MESSAGE_ALIVE_CHECK_FREQ.
[0098] Figure 7 FIG. 1 is a schematic diagram of a resource cleanup and recycling process provided by an embodiment. Figure 7 As shown, the logic of the check process is: starting from the head node of the message center, check whether the message is expired in order. If it is expired, continue to check the next node. If it is not expired, it means that the messages starting from this message are not expired (because the creation time of the message is positively correlated with the order), and you can exit directly. After the check is completed, you can get the valid message in the current message center, or the entire message center may be invalid and get a null result. If a valid message is obtained, set the head to the first message; if null is obtained, set both the head and tail to null.
[0099] After executing the check method, the invalid message loses its reference to the message center and can be automatically garbage collected by the Java Virtual Machine (JVM), completing the invalid message cleanup process. By looping through this invalid message background cleanup thread, related resources can be effectively recycled, further improving resource utilization.
[0100] Figure 8 This is a flowchart of a message subscription method provided in an embodiment of the present application. This embodiment is applicable to the case where a client subscribes to a message. Specifically, the message subscription method can be executed by a message sending device, which can be implemented in software and / or hardware and integrated into the client. Figure 8 As shown, the method specifically includes the following steps:
[0101] S410: Send a subscription request to a message center, where the subscription request includes a starting sequence number.
[0102] For example, a client subscribes to a message using the messageService.subscribe(seqNum) method. The seqNum parameter specifies the starting sequence number of the message. The initial seqNum for each client is -1, indicating the first subscription request.
[0103] S420: Receive a message object list pushed by the message center according to the starting sequence number; the message objects in the message center are encapsulated according to the session level and stored in a single linked list, and the sequence number of each message object in the single linked list is incremented in sequence;
[0104] S430: Extract the pushed message from the message object list.
[0105] In one embodiment, it further includes:
[0106] S440: Convert the first element in the message object list into a context object;
[0107] S450: Use the current sequence number in the context object as a new starting sequence number.
[0108] For example, after the messageService.subscribe(seqNum) method completes, the client receives a datas object. The client first retrieves the context from datas and updates seqNum, then retrieves the pushed message for further processing. Once processing is complete, the client can send the new seqNum in a subscription request the next time it pulls messages, continuing until the client program terminates.
[0109] Through the processing of the above server, client and message center, a real-time message subscription and push method based on RPC persistent connection and lightweight message queue can be implemented, solving the problem of the existing technology that it is difficult to strike a balance between real-time performance, resource efficiency, flexibility and ease of use.
[0110] The present application also provides a message sending device, which includes:
[0111] A generating module, configured to generate a message according to the service data and determine a session level corresponding to the message;
[0112] The sending module is used to send the message and the session level to the message center, so that the message center stores the message as a message object according to the session level. The message objects are stored in the form of a single linked list, and the sequence number of each message object in the single linked list increases sequentially.
[0113] The present application also provides a message storage device, which includes:
[0114] A receiving module, configured to receive a message and a session level sent by a server, wherein the session level includes a session level and a user level, wherein the session level message corresponds to a session ID, and the user level message corresponds to a user ID list;
[0115] A storage module is used to create a message object for the currently received message and assign a serial number, and add the message object to the end of the singly linked list, wherein the serial number of each message object in the singly linked list increases in sequence;
[0116] The updating module is used to update the corresponding session ID or user ID list according to the session level of the currently received message.
[0117] The embodiment of the present application also provides a message push device, which includes:
[0118] An acquisition module is used to obtain a subscription request from a client, wherein the subscription request includes a starting sequence number;
[0119] a determination module, configured to determine a list of message objects to be pushed according to the starting sequence number, wherein the message objects in the message center are encapsulated according to the session level and stored in a single linked list, wherein the sequence number of each message object in the single linked list increases in sequence;
[0120] The push module is used to push the message object list to the client according to the corresponding session ID or user ID list.
[0121] In one embodiment, before pushing the message object list to the client according to the corresponding session ID or user ID list, the apparatus further includes:
[0122] A creation module, configured to create a context object according to the starting sequence number, wherein the context object is used to update the sequence number during the message push process;
[0123] An adding module is used to add the context object as the first element of the message object list.
[0124] In one embodiment, the determination module includes:
[0125] A snapshot acquiring unit, configured to acquire a message snapshot, wherein the data structure of the message snapshot includes a snapshot message header and a snapshot message footer;
[0126] The snapshot processing unit is used to process the message snapshot according to the starting sequence number to obtain a list of message objects to be pushed.
[0127] In one embodiment, the snapshot processing unit is specifically configured to:
[0128] Traversing the message objects in the message snapshot;
[0129] If the sequence number of the current message object is greater than the current sequence number of the context object, the current message object is added to the list of message objects to be pushed.
[0130] In one embodiment, the push module is specifically configured to: if the corresponding session ID is not empty, push the message object list to the client; otherwise, push the message object list to the client corresponding to the user ID list.
[0131] In one embodiment, the device also includes: a checking module, which is used to check the validity of the message object at a set time interval in the following manner: checking whether the corresponding message object is expired in sequence according to the validity time of each message object, wherein if the message object currently being checked has expired, the message object currently being checked is invalid, and the next message object is checked; if the message object currently being checked has not expired, the message object currently being checked and the message objects thereafter are all valid, and the check is stopped; if there is a valid message object, the snapshot message header of the message snapshot is set to the first valid message object; if there is no valid message object, the snapshot message header and snapshot message footer of the message snapshot are set to empty.
[0132] The embodiment of the present application further provides a message subscription device, which includes:
[0133] A subscription module is used to send a subscription request to a message center, wherein the subscription request includes a starting sequence number;
[0134] A receiving module, configured to receive a list of message objects pushed by the message center according to the starting sequence number; the message objects in the message center are encapsulated according to the session level and stored in a single linked list, wherein the sequence number of each message object in the single linked list increases in sequence;
[0135] The extraction module is used to extract the pushed message from the message object list.
[0136] In one embodiment, the apparatus further comprises:
[0137] a conversion module, configured to convert the first element in the message object list into a context object;
[0138] The updating module is configured to use the current sequence number in the context object as a new starting sequence number.
[0139] The message sending, storage, push and subscription device provided in the embodiments of the present application can be used to execute the message sending, storage, push and subscription method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0140] Figure 9A schematic diagram of a server 10 that can be used to implement an embodiment of the present application is shown. The server 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The server 10 can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, user equipment, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0141] like Figure 9 As shown, the server 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by the at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. Various programs and data required for the operation of the server 10 can also be stored in the RAM 13. The processor 11, ROM 12 and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0142] Multiple components in the server 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard and mouse; an output unit 17, such as various types of displays and speakers; a storage unit 18, such as a magnetic disk and optical disk; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the server 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and wireless networks.
[0143] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above.
[0144] In some embodiments, the method of the above embodiment can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the server 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute any of the above embodiment methods in any other appropriate manner (for example, by means of firmware).
[0145] Figure 10 A schematic diagram of a message center 20 that can be used to implement embodiments of the present application is shown. Message center 20 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Message center 20 can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, user equipment, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit the implementation of the present application as described and / or claimed herein.
[0146] like Figure 10 As shown, the message center 20 includes at least one processor 21 and memory, such as a read-only memory (ROM) 22 and a random access memory (RAM) 23, communicatively connected to the at least one processor 21. The memory stores computer programs executable by the at least one processor. The processor 21 can perform various appropriate actions and processes based on the computer program stored in the ROM 22 or loaded from the storage unit 28 into the RAM 23. The RAM 23 can also store various programs and data required for the operation of the message center 20. The processor 21, ROM 22, and RAM 23 are interconnected via a bus 24. An input / output (I / O) interface 25 is also connected to the bus 24.
[0147] Multiple components in the message center 20 are connected to the I / O interface 25, including: an input unit 26, such as a keyboard, a mouse, etc.; an output unit 27, such as various types of displays, speakers, etc.; a storage unit 28, such as a magnetic disk, an optical disk, etc.; and a communication unit 29, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 29 allows the message center 20 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and wireless networks.
[0148] The processor 21 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 21 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 21 performs the various methods and processes described above.
[0149] In some embodiments, the methods of the above embodiments may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 28. In some embodiments, part or all of the computer program may be loaded and / or installed on message center 20 via ROM 22 and / or communication unit 29. When the computer program is loaded into RAM 23 and executed by processor 21, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, processor 21 may be configured to perform any of the methods of the above embodiments in any other appropriate manner (e.g., via firmware).
[0150] Figure 11 A schematic diagram of a client 30 that can be used to implement embodiments of the present application is shown. Client 30 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Client 30 can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, user equipment, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided for example only and are not intended to limit the implementation of the present application as described and / or claimed herein.
[0151] like Figure 11 As shown, client 30 includes at least one processor 31 and memory, such as read-only memory (ROM) 32 and random access memory (RAM) 33, communicatively connected to at least one processor 31. The memory stores computer programs executable by the at least one processor, and processor 31 can perform various appropriate actions and processes based on the computer programs stored in ROM 32 or loaded from storage unit 38 into RAM 33. RAM 33 can also store various programs and data required for the operation of client 30. Processor 31, ROM 32, and RAM 33 are interconnected via bus 34. An input / output (I / O) interface 35 is also connected to bus 34.
[0152] Multiple components in client 30 are connected to I / O interface 35, including: input unit 36, such as a keyboard, mouse, etc.; output unit 37, such as various types of displays, speakers, etc.; storage unit 38, such as a magnetic disk, optical disk, etc.; and communication unit 39, such as a network card, modem, wireless communication transceiver, etc. Communication unit 39 allows client 30 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks and wireless networks.
[0153] The processor 31 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Examples of the processor 31 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors for running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 31 executes the various methods and processes described above.
[0154] Figure 12 This is a structural diagram of a message subscription and push system provided by an embodiment. Figure 12 As shown, the system includes: a server 10, a message center 20, and a client 30. There may be one or more servers 10, and one or more clients 30.
[0155] The message subscription and push system provided in the embodiments of the present application can be used to execute the message sending, storage, push and subscription methods provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0156] In some embodiments, the methods of the above embodiments may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as storage unit 38. In some embodiments, part or all of the computer program may be loaded and / or installed on client 30 via ROM 32 and / or communication unit 39. When the computer program is loaded into RAM 33 and executed by processor 31, one or more steps of the method described above may be performed. Alternatively, in other embodiments, processor 31 may be configured to perform any of the methods of the above embodiments in any other appropriate manner (e.g., by means of firmware).
[0157] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0158] To provide interaction with a user, the systems and techniques described herein may be implemented on a server 10 having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the server 10. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0159] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0160] An embodiment of the present application also provides a computer program product, including a computer program and / or instructions, which, when executed by a processor, implements the message sending, storage, push and subscription methods described in any of the above embodiments.
[0161] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of this application can be achieved. This is not limited herein.
[0162] The above specific embodiments do not constitute a limitation on the scope of protection of this application. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application shall be included within the scope of protection of this application.
Claims
1. A message sending method, applied to a server, characterized in that: include: Generate a message based on the business data and determine the session level corresponding to the message; The message and the session level are sent to a message center, so that the message center stores the message as a message object according to the session level. The message objects are stored in a single linked list, and the sequence number of each message object in the single linked list increases in sequence.
2. A message storage method, applied to a message center, characterized in that: include: Receive a message and session level sent by the server, wherein the session level includes a session level and a user level, wherein the session level message corresponds to a session ID, and the user level message corresponds to a user ID list; Create a message object for the currently received message and assign a sequence number, add the message object to the end of the singly linked list, and increase the sequence number of each message object in the singly linked list in sequence; Update the corresponding session ID or user ID list according to the session level of the currently received message.
3. A message push method, applied to a message center, characterized in that: include: Obtaining a subscription request from a client, wherein the subscription request includes a starting sequence number; Determine a list of message objects to be pushed according to the starting sequence number, the message objects in the message center are encapsulated according to the session level and stored in a single linked list, and the sequence number of each message object in the single linked list is incremented in sequence; According to the corresponding session ID or user ID list, the message object list is pushed to the client.
4. The method according to claim 3, characterized in that Before pushing the message object list to the client according to the corresponding session ID or user ID list, the method further includes: Creating a context object according to the starting sequence number, wherein the context object is used to update the sequence number during the message push process; The context object is used as the first element of the message object list.
5. The method according to claim 4, characterized in that Determining a list of message objects to be pushed according to the starting sequence number includes: Obtain a message snapshot, wherein the data structure of the message snapshot includes a snapshot message header and a snapshot message footer; The message snapshot is processed according to the starting sequence number to obtain a list of message objects to be pushed.
6. The method according to claim 5, characterized in that Processing the snapshot according to the starting sequence number to obtain a list of message objects to be pushed includes: Traversing the message objects in the message snapshot; If the sequence number of the current message object is greater than the current sequence number of the context object, the current message object is added to the list of message objects to be pushed.
7. The method according to claim 3, characterized in that Pushing the message object list to the client according to the corresponding session ID or user ID list includes: If the corresponding session ID is not empty, the message object list is pushed to the client; Otherwise, the message object list is pushed to the client corresponding to the user ID list.
8. The method according to claim 5, characterized in that Also includes: At the set time interval, the validity of the message objects is checked in the following manner: the corresponding message objects are checked in order according to the validity period of each message object. If the message object currently being checked has expired, the message object currently being checked is invalid, and the next message object is checked. If the message object currently being checked has not expired, the message object currently being checked and the message objects after it are all valid, and the check stops. If there is a valid message object, the snapshot message header of the message snapshot is set to the first valid message object; If there is no valid message object, the snapshot message header and snapshot message footer of the message snapshot are set to empty.
9. A message subscription method, applied to a client, characterized in that: include: Send a subscription request to the message center, wherein the subscription request includes a starting sequence number; receiving a message object list pushed by the message center according to the starting sequence number; the message objects in the message center are encapsulated according to the session level and stored in a single linked list, wherein the sequence number of each message object in the single linked list increases in sequence; Extract the pushed message from the message object list.
10. The method according to claim 9, characterized in that Also includes: Convert the first element in the message object list to a context object; The current sequence number in the context object is used as the new starting sequence number.
11. A server, characterized in that: include: at least one processor; a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the message sending method according to claim 1.
12. A message center, characterized in that: include: at least one processor; a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the message storage method according to claim 2 or the message push method according to any one of claims 3-8.
13. A client, characterized in that: include: at least one processor; a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to execute the message subscription method according to any one of claims 9 to 10.
14. A message subscription and push system, characterized in that: include: The server according to claim 11, the message center according to claim 12, and the client according to claim 13.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the message sending method according to claim 1 or the message storage method according to claim 2 or the message push method according to any one of claims 3-8 or the message subscription method according to any one of claims 9-10.
16. A computer program product comprising a computer program and / or instructions, characterized in that When the computer program and / or instructions are executed by the processor, the message sending method according to claim 1 or the message storage method according to claim 2 or the message push method according to any one of claims 3-8 or the message subscription method according to any one of claims 9-10 is implemented.
Citation Information
Cited By
Message synchronization method, device side and system
CN122247962A