Message processing method and device, distributed instant messaging system, storage medium and program product
By receiving message sets and estimating the time spent on server tasks, combined with long-connection clients, and rationally allocating message sets, the problem of untimely message push in distributed instant messaging systems is solved, improving the timeliness and efficiency of message push.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- E-SURFING DIGITAL LIFE TECH CO LTD
- Filing Date
- 2024-11-19
- Publication Date
- 2026-04-28
AI Technical Summary
In distributed instant messaging systems, existing technologies struggle to effectively address the issue of some messages not being delivered in a timely manner when a large number of messages are pushed, especially when the number of message servers is evenly distributed, making it difficult for some messages to reach the target client promptly.
By receiving message sets and the estimated time spent on current tasks reported by each message server, the number of messages that each message server needs to process is determined. Based on the clients with long-term connections to the message servers, a certain type of message is prioritized for allocation to the long-term connected servers. Combined with the task load of the message servers, message sets are reasonably allocated to form a target message set to improve the timeliness of push notifications.
Reasonable allocation of message sets avoids situations where some messages are not pushed in a timely manner, reduces the number of long connections established between the message server and the client, and improves the timeliness and efficiency of message push.
Smart Images

Figure CN119484456B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of instant messaging technology, and in particular to a message processing method, apparatus, distributed instant messaging system, storage medium, and computer program product. Background Technology
[0002] With the rapid development of mobile internet, distributed instant messaging systems have become an indispensable part of people's daily lives.
[0003] By leveraging the message servers of a distributed instant messaging system, a message sent by one messaging client can be pushed to another. Distributed instant messaging systems sometimes face situations where a large number of messages need to be pushed. In such cases, to ensure timely delivery of these messages, they can be broken down into multiple parts and distributed to different message servers for pushing.
[0004] However, when splitting a large number of messages into multiple parts, they are usually divided evenly according to the number of message servers. In some scenarios, some messages are difficult to push out in a timely manner. Summary of the Invention
[0005] Therefore, it is necessary to provide a message processing method, apparatus, distributed instant messaging system, storage medium, and computer program product to address the aforementioned technical problems.
[0006] This application provides a message processing method, the method comprising:
[0007] Receive message sets and the estimated time for the current task reported by each message server;
[0008] The number of messages that each message server needs to process is determined based on the relative size of the estimated time spent on the current task reported by each message server and the total number of messages included in the message set.
[0009] Based on the message clients that currently have long connections with each of the aforementioned message servers, a number of target message clients are obtained;
[0010] The messages sent to the target message client in the message set are identified to obtain a message set of type one, and a message set of type two is obtained based on the messages in the message set other than the message set of type one.
[0011] By prioritizing the allocation of one type of message to message servers that have long-lived connections with the target message clients receiving the first type of message, and considering the number of messages each message server needs to process, the first type of message set and the second type of message set are allocated to obtain the target message set for each message server; the target message set is then sent to the message client by the message server through a long-lived connection.
[0012] In one embodiment, the number of messages that each message server needs to process is determined based on the relative magnitudes of the estimated time spent on current tasks reported by each message server and the total number of messages included in the message set, including:
[0013] Based on the relative magnitudes of the estimated time spent on current tasks reported by each message server, the message count ratios among the message servers are obtained.
[0014] Based on the message count ratio and the total number of messages included in the message set, the number of messages that each message server needs to process is determined.
[0015] In one embodiment, the message set of the first type and the message set of the second type are allocated based on a priority method of allocating one type of message to message servers that have long-term connections with the target message clients receiving the first type of message, and the number of messages that each message server needs to process, to obtain the target message set for each message server, including:
[0016] By summarizing messages in the message set that point to the same target message client, a subset of messages for each target message client is obtained.
[0017] A subset of messages from each target message client is assigned to a message server that has established a long connection with the target message client, thus obtaining a preliminary message set for each message server.
[0018] Based on the initial message sets of each message server, the two types of message sets are allocated to obtain the target message sets of each message server; the allocation of the two types of message sets ensures that the target message sets of each message server match the number of messages that need to be processed.
[0019] In one embodiment, before allocating the two types of message sets based on the initial message sets of each of the message servers, the method further includes:
[0020] Determine whether the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process;
[0021] If the number of messages in the initial message set of one of the message servers exceeds the number of messages that each server needs to process, then the message quantity excess value is obtained based on the number of messages in the initial message set of that message server and the number of messages that need to be processed.
[0022] If the message quantity exceeds the excess threshold, at least one subset of messages from the target client will be removed from the initial message set of the message server so that the number of messages in the initial message set of the message server after removal does not exceed the excess threshold.
[0023] The first subset of messages from the target clients to be removed is added to the second subset of messages.
[0024] In one embodiment, based on the initial message sets of each of the message servers, the two types of message sets are allocated, including:
[0025] If the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process, then the second type of message set is allocated based on the initial message set of each message server.
[0026] or,
[0027] If the message quantity excess value does not exceed the excess threshold, then the second type of message set is allocated based on the initial message set of each message server.
[0028] In one embodiment, a plurality of target message clients are obtained based on message clients that currently have long connections with each of the message servers, including:
[0029] Retrieve long-connection information reported by each message server;
[0030] Based on the long connection information, message clients that currently have long connections with each of the message servers are identified, resulting in a number of target message clients.
[0031] This application provides a message processing apparatus, the apparatus comprising:
[0032] The information receiving module is used to receive message sets and the estimated time of the current task reported by each message server;
[0033] The quantity determination module is used to determine the number of messages that each message server needs to process based on the relative size between the estimated time spent on the current task reported by each message server and the total number of messages included in the message set.
[0034] The target message client determination module is used to obtain a number of target message clients based on the message clients that currently have long connections with each of the message servers;
[0035] The message classification module is used to determine the messages sent to the target message client in the message set to obtain a message set of type one, and to obtain a message set of type two based on the messages in the message set other than the message set of type one;
[0036] The message allocation module is used to allocate the first type of message set and the second type of message set according to the method of prioritizing the allocation of a type of message to the message server that has a long connection with the target message client that receives the first type of message set, and in combination with the number of messages that each message server needs to process, to obtain the target message set of each message server; the target message set is sent to the message client by the message server through the long connection.
[0037] This application provides a distributed instant messaging system, the system including a gateway and a message server;
[0038] The gateway is used to execute the above method;
[0039] The message server is used to receive the corresponding target message set and send the target message set to the message client through a long connection.
[0040] This application provides a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor using the methods described above.
[0041] This application provides a computer program product having a computer program stored thereon, the computer program being executed by a processor using the above-described method.
[0042] In the aforementioned message processing method, apparatus, distributed instant messaging system, storage medium, and computer program product, the following steps are taken: receiving a message set and the estimated time of the current task reported by each message server; determining the number of messages that each message server needs to process based on the relative magnitudes of the estimated time of the current task reported by each message server and the total number of messages included in the message set; obtaining several target message clients based on the message clients that currently have long connections with each message server; determining the messages in the message set that are sent to the target message clients to obtain a first-class message set, and obtaining a second-class message set based on the messages in the message set other than the first-class message set; allocating the first-class message set and the second-class message set according to the method of prioritizing the allocation of first-class messages to message servers that have long connections with the target message clients that receive first-class messages, and combining this with the number of messages that each message server needs to process, to obtain the target message set for each message server; each message server is also used to receive the corresponding target message set and send the target message set to the message client through a long connection. In the solution provided in this application, when dividing the message set, the time spent on the current task to be processed by each message server is considered. Based on the relative size of the estimated time spent on the current task of each message server, the number of messages to be processed by each message server is obtained. The message set is divided reasonably, which can avoid the situation where some messages are not pushed in time due to the equal distribution of messages by the number of message servers. In addition, the solution provided in this application also considers message clients that currently have long connections with each message server. Messages sent to the message client are given priority to be distributed to the corresponding message server, which minimizes the need for message servers to establish long connections with message clients when pushing messages, and further improves the timeliness of message push. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a message processing method in one embodiment;
[0045] Figure 2 This is a flowchart illustrating the process of determining the number of messages in one embodiment;
[0046] Figure 3 This is a structural block diagram of a message processing device in one embodiment;
[0047] Figure 4 This is a schematic diagram of the devices included in a distributed instant messaging system in one embodiment;
[0048] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0050] This application provides a message processing method, the steps of which can be executed by a gateway, including... Figure 1 The steps are shown.
[0051] Step S101: Receive the message set and the estimated time of the current task reported by each message server.
[0052] A messaging client can send messages to another messaging client. After each messaging client sends a message, the messages are aggregated and sent to the gateway, which then receives the set of messages to be pushed. Each messaging server can calculate the estimated time for its current tasks based on its own pending tasks and report this estimate to the gateway.
[0053] Step S102: Determine the number of messages that each message server needs to process based on the relative size of the estimated time spent on the current task reported by each message server and the total number of messages included in the message set.
[0054] The longer the estimated time for the current task of the message server, the more time the current task of the message server needs to take to process. In order to push the messages out in a timely manner, the number of messages that the message server needs to push can be less.
[0055] The gateway can determine the number of messages each message server needs to process based on the relative magnitude of the estimated time for the current task of each message server and the total number of messages included in the message set; where the longer the estimated time for the current task is, the fewer messages need to be processed.
[0056] Step S103: Based on the message clients that currently have long connections with each message server, obtain a number of target message clients.
[0057] Each message server may currently have long-lived connections with some message clients. The gateway can identify message clients with long-lived connections to message servers as target message clients.
[0058] In one embodiment, step S103, which involves obtaining several target message clients based on message clients currently having long connections with each message server, may include: obtaining long connection information reported by each message server; determining message clients currently having long connections with each message server based on the long connection information, and thus obtaining several target message clients.
[0059] Specifically, each message server generates long-term connection information based on the message clients that have established long-term connections with it and reports this information to the gateway. After receiving the long-term connection information from the message servers, the gateway can identify the message clients that currently have long-term connections with the message servers and designate these message clients as target message clients.
[0060] Step S104: Determine the messages sent to the target message client in the message set to obtain a first-class message set, and obtain a second-class message set based on the messages in the message set other than the first-class message set.
[0061] Each message in a message set is associated with information about both the client that sent the message and the client that received it. Therefore, the gateway can determine the messages to be sent to the target client based on the information associated with each message, and group these messages into a message set.
[0062] The gateway can identify messages in the message set that are not of type one as type two messages, thus forming a type two message set.
[0063] Step S105: Prioritize allocating type I messages to message servers that have long connections with the target message clients that receive type I messages. Based on the number of messages that each message server needs to process, allocate type I message sets and type II message sets to obtain the target message sets for each message server.
[0064] The target message set is sent from the message server to the message client via a long-lived connection.
[0065] After the gateway divides the message set into two categories, since the target message client receiving the message of category I currently has a long connection with the corresponding message server, the message of category I can be sent to the message server first. The message server can send the message of category I directly based on the established long connection without spending time establishing a long connection, thus pushing the message to the target message client in a timely manner.
[0066] When the gateway allocates message sets of type I and type II to form the target message sets of each message server, the allocation principle prioritizes allocating type I messages to message servers that have long-term connections with the target message clients that receive type I messages. Then, it takes into account the number of messages that each message server needs to process, in order to minimize the time spent by message servers in establishing long-term connections and improve the timeliness of message push.
[0067] In the aforementioned message processing method, when dividing the message set, the time spent on the current task to be processed by each message server is considered. Based on the relative size of the estimated time spent on the current task by each message server, the number of messages to be processed by each message server is obtained. Reasonably dividing the message set can avoid the situation where some messages are not pushed in time due to the equal distribution by the number of message servers. Furthermore, the solution provided in this application also considers message clients that currently have long connections with each message server. Messages sent to these message clients are prioritized for distribution to the corresponding message servers, minimizing the need for message servers to establish long connections with message clients when pushing messages, thereby further improving the timeliness of message push.
[0068] In one embodiment, step S102 involves determining the number of messages each message server needs to process based on the relative magnitudes of the estimated time spent on current tasks reported by each message server and the total number of messages included in the message set. Figure 2 The steps shown are as follows: Step S201, obtain the message number ratio relationship between each message server based on the relative size of the estimated time spent on the current task reported by each message server; Step S202, determine the number of messages that each message server needs to process based on the message number ratio relationship and the total number of messages included in the message set.
[0069] For example, the estimated time spent on current tasks of three message servers can be obtained to get the time consumption ratio, such as 3:2.5:2. Based on the time consumption ratio, the message count ratio between each message server can be obtained. The larger the time consumption ratio, the smaller the message count ratio. If the time consumption ratio is 3:2.5:2, then the message count ratio can be 2:2.5:3.
[0070] After obtaining the message count ratio between each message server, the number of messages that each message server needs to process can be determined by combining the total number of messages included in the message set. The larger the message count ratio, the more messages need to be processed.
[0071] In one embodiment, step S105, which prioritizes allocating a type of message to a message server that has a long-term connection with the target message client receiving the type of message, allocates a type of message set and a type of message set based on the number of messages each message server needs to process, to obtain the target message set for each message server. This includes: summarizing the type of messages in the type of message set that point to the same target message client to obtain a type of message subset for each target message client; allocating the type of message subset for each target message client to the message server that has a long-term connection with the target message client to obtain a preliminary message set for each message server; and allocating a type of message set based on the preliminary message set for each message server to obtain the target message set for each message server. The allocation of the type of message set ensures that the target message set for each message server matches the number of messages it needs to process.
[0072] After the gateway divides a message set into categories, it can aggregate messages of the same category sent to the same target message client, forming a subset of messages of that category for that target message client. By aggregating messages in this way, several subsets of messages of the same category for different target message clients can be obtained.
[0073] Since the target message client currently has a long-lived connection with the corresponding message server, a subset of messages from the target message client can be assigned to the message server with which the target message client currently has a long-lived connection. In this way, a preliminary message set of the message server can be obtained.
[0074] After obtaining the initial message sets from each message server, the number of messages in the initial message sets may not match the number of messages the message servers need to process. Therefore, based on the initial message sets from each message server, two types of message sets are allocated to obtain the target message sets for each message server, ensuring that the number of messages in the target message sets of each message server matches the number of messages the message servers need to process.
[0075] In this embodiment, considering message clients that currently have long connections with each message server, messages sent to these message clients are preferentially allocated to the corresponding message servers. This minimizes the need for message servers to establish long connections with message clients when pushing messages, further improving the timeliness of message pushes. Then, the two types of message sets are allocated so that the number of messages in the target message set of the message server may match the number of messages the message server needs to process. This allows message servers with a longer estimated time for the current task to push fewer messages, and message servers with a shorter estimated time for the current task to push more messages.
[0076] In one embodiment, before allocating the second type of message set based on the initial message set of each message server, the method provided in this application further includes: determining whether the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process; if the number of messages in the initial message set of one of the message servers exceeds the number of messages that each server needs to process, obtaining a message quantity excess value based on the number of messages in the initial message set of that message server and the number of messages that need to be processed; if the message quantity excess value exceeds an excess threshold, removing at least one subset of messages from the target client from the initial message set of that message server, so that the number of messages in the initial message set of that message server after removal does not exceed the excess threshold; and adding the removed subset of messages from the target client to the second type of message set.
[0077] After obtaining the initial message sets from each message server, the number of messages included in the initial message set may not match the number of messages that the message server needs to process.
[0078] Therefore, the gateway can determine whether the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process.
[0079] If the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process, then a second type of message set can be allocated directly based on the initial message set of each message server.
[0080] If the number of messages in the initial message set of a message server exceeds the number of messages to be processed, the excess message count can be calculated based on the number of messages in the initial message set and the number of messages to be processed.
[0081] The gateway can determine whether the message quantity exceeds the excess threshold.
[0082] If the message quantity excess value does not exceed the threshold, it means that although the number of messages in the initial message set exceeds the number of messages to be processed, the excess will not be too much, and there is no need to reduce the number of messages in the initial message set; therefore, the second type of message set can be directly allocated based on the initial message set of each message server.
[0083] If the message quantity exceeds the excess threshold, it means that the number of messages in the initial message set of the message server needs to be reduced to prevent the message server from being overloaded and causing some messages to fail to be pushed in a timely manner.
[0084] Since the initial message set of the message server is formed based on a subset of messages from several target message clients, at least one subset of messages from a target message client can be removed from the initial message set to ensure that the number of messages in the initial message set after removal does not exceed the excess threshold. The gateway can treat the messages from the removed subset of messages from the target message clients as second-class messages and add the first-class message subset to the second-class message set, so that it can be randomly assigned to any message server along with the second-class message set.
[0085] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0086] Based on the same inventive concept, this application also provides a message processing apparatus for implementing the message processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more message processing apparatus embodiments provided below can be found in the limitations of the message processing method described above, and will not be repeated here.
[0087] In one embodiment, such as Figure 3 As shown, a message processing apparatus is provided, comprising:
[0088] Information receiving module 301 is used to receive message sets and the estimated time of the current task reported by each message server;
[0089] The quantity determination module 302 is used to determine the number of messages that each message server needs to process based on the relative size between the estimated time spent on the current task reported by each message server and the total number of messages included in the message set.
[0090] The target message client determination module 303 is used to obtain a number of target message clients based on the message clients that currently have long connections with each of the message servers;
[0091] The message classification module 304 is used to determine the messages sent to the target message client in the message set to obtain a message set of one type, and to obtain a message set of two types based on the messages in the message set other than the message set of one type.
[0092] The message allocation module 305 is used to allocate the first type of message set and the second type of message set according to the method of prioritizing the allocation of a type of message to the message server that has a long connection with the target message client that receives the first type of message set, and in combination with the number of messages that each message server needs to process, to obtain the target message set of each message server; the target message set is sent to the message client by the message server through the long connection.
[0093] In one embodiment, the quantity determination module 302 is further configured to: obtain the message number ratio relationship between each message server based on the relative size between the estimated time spent on the current task reported by each message server; and determine the number of messages that each message server needs to process based on the message number ratio relationship and the total number of messages included in the message set.
[0094] In one embodiment, the message allocation module 305 is further configured to: aggregate messages in the first type of message set that point to the same target message client to obtain a subset of messages for each target message client; allocate the subset of messages for each target message client to a message server that has established a long connection with the target message client to obtain a preliminary message set for each message server; allocate the second type of message set based on the preliminary message set of each message server to obtain a target message set for each message server; the allocation of the second type of message set ensures that the target message set of each message server matches the number of messages it needs to process.
[0095] In one embodiment, before allocating the second type of message set based on the initial message set of each message server, the message allocation module 305 is further configured to: determine whether the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process; if the number of messages in the initial message set of one of the message servers exceeds the number of messages that each server needs to process, obtain a message quantity excess value based on the number of messages in the initial message set of that message server and the number of messages that need to be processed; if the message quantity excess value exceeds an excess threshold, remove at least one type of message subset of the target client from the initial message set of that message server, so that the number of messages in the initial message set of that message server after removal does not exceed the excess threshold; and add the removed type of message subset of the target client to the second type of message set.
[0096] In one embodiment, the message allocation module 305 is further configured to: if the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process, allocate the second type of message set based on the initial message set of each message server; or, if the message quantity excess value does not exceed the excess threshold, allocate the second type of message set based on the initial message set of each message server.
[0097] In one embodiment, the target message client determination module 303 is further configured to: obtain long connection information reported by each message server; determine message clients that currently have long connections with each of the message servers based on the long connection information, thereby obtaining a number of target message clients.
[0098] Each module in the aforementioned message processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute the operations corresponding to each module.
[0099] This application provides a distributed instant messaging system, the system including a gateway and a message server, such as... Figure 4 As shown.
[0100] The gateway is used to execute the above method embodiments; the message server is used to receive the corresponding target message set and send the target message set to the message client through a long connection.
[0101] Distributed instant messaging systems achieve high efficiency, scalability, and maintainability through systematic domain modeling, loosely coupled architecture design, event sourcing, the application of CQRS (Command Query Responsibility Segregation) patterns, and the implementation of a series of high-performance optimization strategies. Specifically, this includes the following three aspects:
[0102] First, by using domain-driven design to deeply understand and accurately reflect the needs of the business domain, we can ensure that the design of the distributed instant messaging system is consistent with the business requirements.
[0103] Second, by leveraging microservice architecture and event-driven communication patterns, loose coupling between system components is achieved, thereby improving the scalability and flexibility of the distributed instant messaging system.
[0104] Third, introduce event sourcing and CQRS patterns to optimize data storage and access mechanisms, thereby improving the performance and responsiveness of the distributed instant messaging system.
[0105] The above aspects are described in detail below.
[0106] 1. Microservice architecture design and implementation
[0107] 1.1 Microservice partitioning:
[0108] User Services: Responsible for user account registration, login, and information management. Messaging Services: Handles message sending, receiving, storage, and retrieval. Group Services: Manages group creation, member management, and group message processing. Other Services (e.g., file services, notification services): Further subdivided according to business needs, ensuring each service has a single and independent responsibility.
[0109] 1.2 Communication Protocol Selection:
[0110] Each microservice can adopt a specific communication protocol as its primary communication protocol to ensure cross-platform and cross-language interoperability. For internal service communication with high performance requirements, a more efficient communication protocol can be used.
[0111] 1.3 Event-driven communication pattern:
[0112] An event bus is introduced for event publishing and subscription among microservices. When critical events such as user login and message sending occur, the relevant microservices publish the events to the event bus. Microservices that have subscribed to these events listen to the event bus and execute the corresponding business logic when the event occurs.
[0113] 1.4 Intelligent Message Routing Application:
[0114] In a microservice architecture, intelligent message routing, as part of a message middleware or service gateway, is responsible for routing messages from clients or external systems to the appropriate microservice instances. Intelligent message routing enables the following functionalities:
[0115] Service discovery and registration: Intelligent message routing can automatically discover and register microservice instances, ensuring that messages are accurately routed to the target service.
[0116] Load balancing and fault tolerance: Intelligent message routing can dynamically adjust message routing strategies based on the load and health status of microservice instances to achieve load balancing and fault tolerance.
[0117] Message filtering and transformation: During message routing, messages can be filtered and transformed to meet the processing needs of different microservice instances.
[0118] Security and Authentication: Intelligent message routing can integrate security authentication mechanisms to ensure the security and integrity of messages during transmission.
[0119] 2. Domain Modeling and Aggregate Design
[0120] 2.1 Domain Modeling:
[0121] Through close collaboration with the business team, we gained a deep understanding of the business needs and processes of the social platform. We identified key entities such as users, messages, and groups, as well as value objects such as user status and message content. We defined the relationships between entities, such as the send / receive relationship between users and messages, and the membership relationship between users and groups.
[0122] 2.2 Aggregate Design:
[0123] For each microservice, design clear aggregation boundaries. For example, in the user service, users and their associated information (such as user status and user preferences) constitute a user aggregation. Designate an aggregation root as the sole entry point for external access to the aggregation, ensuring the consistency and encapsulation of data within the aggregation. Implement business logic within the aggregation, ensuring that all necessary changes and validations are performed on the data within the aggregation.
[0124] 2.3 Domain Modeling and Microservice Partitioning Implementation:
[0125] Organize a cross-functional team, including business analysts, architects, and developers, to collaboratively perform domain modeling and microservice partitioning. Use auxiliary modeling tools to ensure that all key entities and relationships are accurately identified. Based on the partitioning results, create an independent codebase and deployment environment for each microservice.
[0126] 2.4 Aggregate Design and Implementation:
[0127] Within each microservice, implement the corresponding aggregates and aggregate roots according to aggregate design principles. Use object-oriented programming techniques to ensure tight relationships and consistency among entities within the aggregate. Implement the business logic of the aggregate root, including data validation and business rule execution. Introduce an event sourcing mechanism in the message service to record historical records of key events such as message sending and receiving. Implement the CQRS pattern to separate message sending (command) and receiving (query) operations into different models. Use event storage and projection mechanisms to ensure that the data in the query model remains consistent with the command model.
[0128] 2.5 Optimization and Implementation of Intelligent Message Routing:
[0129] Dynamically adjust routing strategies: Based on the real-time load of the system and message processing requirements, dynamically adjust the routing strategy to improve the overall performance of the system.
[0130] Introduce a caching mechanism: For frequently accessed routing information, a caching mechanism can be introduced to reduce the number of database accesses and response time.
[0131] Monitoring and logging: Real-time monitoring and logging of the operation of intelligent message routing to promptly identify and resolve issues.
[0132] Continuous optimization and iteration: Based on the system's operation and user feedback, continuously optimize the design and implementation of intelligent message routing to improve the system's stability and performance.
[0133] 2.6 Implementation of high-performance optimization strategies:
[0134] The system deploys a multi-level cache, including local and distributed caches. A message queue is used to implement an asynchronous processing mechanism to handle time-consuming operations such as message sending and user status updates. A load balancer is deployed to evenly distribute requests across the microservice nodes based on request type and load conditions.
[0135] 2.7 Implementation of Security and Reliability Assurance:
[0136] Encrypted transmission is used to ensure the security of data transmission. An authentication mechanism is introduced to verify and authorize user identities. System data is backed up regularly, and disaster recovery and failover mechanisms are set up to ensure high system availability and data security.
[0137] In one exemplary embodiment, the message server can be implemented by a computer device. The internal structure of the computer device can be as follows: Figure 5 As shown, the computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores the data involved in the aforementioned methods. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a message processing method.
[0138] 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.
[0139] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the various method embodiments described above.
[0140] In one embodiment, a computer program product is provided having a computer program stored thereon, the computer program being executed by a processor of the steps described in the various method embodiments above.
[0141] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0142] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0143] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0144] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A message processing method, characterized in that, Applied to a gateway, the method includes: Receive message sets and the estimated time for the current task reported by each message server; The number of messages that each message server needs to process is determined based on the relative size of the estimated time spent on the current task reported by each message server and the total number of messages included in the message set. Based on the message clients that currently have long connections with each of the aforementioned message servers, a number of target message clients are obtained; The messages sent to the target message client in the message set are identified to obtain a message set of type one, and a message set of type two is obtained based on the messages in the message set other than the message set of type one. The message set is allocated to the message server that has a long connection with the target message client that receives the message set of the first type, based on the number of messages that each message server needs to process, and the message set of the first type and the message set of the second type are allocated to obtain the target message set of each message server; the target message set is sent to the message client by the message server through the long connection. By prioritizing the allocation of one type of message to message servers with long-lived connections to the target message clients receiving that type of message, and considering the number of messages each message server needs to process, the first type of message set and the second type of message set are allocated to obtain the target message set for each message server, including: Aggregate the messages of the same type sent to the same target message client from the message set to obtain a subset of the message type for each target message client; A subset of messages from each target message client is assigned to a message server that has established a long connection with the target message client, thus obtaining a preliminary message set for each message server. Determine whether the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process; If the number of messages in the initial message set of one of the message servers exceeds the number of messages to be processed, then an excess message value is obtained based on the number of messages in the initial message set of that message server and the number of messages to be processed; if the excess message value exceeds an excess threshold, then at least one subset of messages from a target client is removed from the initial message set of that message server, so that the number of messages in the initial message set of that message server after removal does not exceed the excess threshold; the removed subset of messages from a target client is added to a second message set. Based on the initial message sets of each message server, the two types of message sets are allocated to obtain the target message sets of each message server; the allocation of the two types of message sets ensures that the target message sets of each message server match the number of messages that need to be processed.
2. The method according to claim 1, characterized in that, Based on the relative magnitudes of the estimated time spent on current tasks reported by each message server and the total number of messages included in the message set, the number of messages that each message server needs to process is determined, including: Based on the relative magnitudes of the estimated time spent on current tasks reported by each message server, the message count ratios among the message servers are obtained. Based on the message count ratio and the total number of messages included in the message set, the number of messages that each message server needs to process is determined.
3. The method according to claim 1, characterized in that, Based on the initial message sets of each of the aforementioned message servers, the two types of message sets are allocated, including: If the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process, then the second type of message set is allocated based on the initial message set of each message server. or, If the message quantity excess value does not exceed the excess threshold, then the second type of message set is allocated based on the initial message set of each message server.
4. The method according to claim 1, characterized in that, Based on the message clients that currently have long connections with each of the aforementioned message servers, several target message clients are obtained, including: Retrieve long-connection information reported by each message server; Based on the long connection information, message clients that currently have long connections with each of the message servers are identified, resulting in a number of target message clients.
5. A message processing device, characterized in that, Applied to a gateway, the device includes: The information receiving module is used to receive message sets and the estimated time of the current task reported by each message server; The quantity determination module is used to determine the number of messages that each message server needs to process based on the relative size between the estimated time spent on the current task reported by each message server and the total number of messages included in the message set. The target message client determination module is used to obtain a number of target message clients based on the message clients that currently have long connections with each of the message servers; The message classification module is used to determine the messages sent to the target message client in the message set to obtain a message set of type one, and to obtain a message set of type two based on the messages in the message set other than the message set of type one; The message allocation module is used to aggregate messages of a certain type sent to the same target message client from the aforementioned message set, obtaining a subset of messages of a certain type for each target message client; allocate the subset of messages of a certain type for each target message client to message servers that have established long connections with the target message clients, obtaining preliminary message sets for each message server; determine whether the number of messages in the preliminary message sets of each message server does not exceed the number of messages that each server needs to process; if the number of messages in the preliminary message set of one of the message servers exceeds the number of messages that it needs to process, then based on the number of messages in the preliminary message set of that message server and the number of messages that it needs to process, the module allocates the subset of messages to each message server. The number of messages processed is used to obtain the message quantity excess value. If the message quantity excess value exceeds the excess threshold, at least one subset of messages from a target client is removed from the initial message set of the message server to ensure that the number of messages in the initial message set of the message server after removal does not exceed the excess threshold. The removed subset of messages from the target client is added to a second set of messages. Based on the initial message sets of each message server, the second set of messages is allocated to obtain the target message set of each message server. The allocation of the second set of messages ensures that the target message set of each message server matches the number of messages it needs to process.
6. The apparatus according to claim 5, characterized in that, The quantity determination module is used for: Based on the relative magnitudes of the estimated time spent on current tasks reported by each message server, the message count ratios among the message servers are obtained. Based on the message count ratio and the total number of messages included in the message set, the number of messages that each message server needs to process is determined.
7. The apparatus according to claim 5, characterized in that, The message distribution module is used for: If the number of messages in the initial message set of each message server does not exceed the number of messages that each server needs to process, then the second type of message set is allocated based on the initial message set of each message server. or, If the message quantity excess value does not exceed the excess threshold, then the second type of message set is allocated based on the initial message set of each message server.
8. A distributed instant messaging system, characterized in that, The system includes a gateway and a message server; The gateway is configured to perform the method according to any one of claims 1 to 4; The message server is used to receive the corresponding target message set and send the target message set to the message client through a long connection.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 4.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 4.
Citation Information
Patent Citations
Load balancing method and system for message servers
CN104243587A
Distributed message push system and method
CN104717133A
Message pushing method and device, equipment and medium
CN116016654A