Communication message processing method, electronic device, storage medium and computer program product
Through the backend service component, a real-time communication link client is uniformly managed, and an independent message processing thread is established for each link, which solves the problems of poor link stability and unreal-time message processing in the existing technology, and achieves higher system stability and message processing reliability.
Patent Information
- Application Number
- CN202411997613.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-02
AI Technical Summary
The prior art fails to manage links uniformly in real-time communication, resulting in poor link stability and the inability to guarantee real-time priority of message processing.
The backend service component is used to manage the link clients for real-time communication, and multiple linked clients are managed uniformly through the client manager. Each linked client has a unique client identity. The message processor establishes an independent message processing thread for each link and maintains the message queue in the thread.
It improves the stability and scalability of the system, ensures the stability and sustainability of real-time communication links, avoids link interrupts caused by UI thread blocking or restarting, and improves the reliability and maintainability of message processing.
Smart Images

Figure CN119922222A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field related to message processing, and in particular to a communication message processing method, electronic equipment, storage medium and computer program product. Background Art
[0002] With the rapid development of Internet applications, the demand for real-time communication is becoming more and more diverse and universal. From traditional polling and long polling technologies to the now widely used WebSocket protocol, how to efficiently and stably transmit real-time messages has become an important issue in Internet technology. In order to solve the shortcomings of traditional communication protocols such as poor real-time performance and high overhead, the public usually chooses WebSocket as a mainstream technical solution based on actual scenarios when selecting technology. Although the WebSocket protocol has significant advantages in real-time communication, there are still some challenges in actual applications: message processing efficiency, link management, reliability of message transmission, etc.
[0003] like Figure 1 The figure shows a communication message processing framework of the prior art, which uses WebSocket as a real-time communication protocol, including: a WebSocket manager 1', a message processor 2', a business layer 3', a rendering layer 4' and a log collector 5'. Among them, the WebSocket manager 1' opens a new thread every time a Websocket link is established, and the reception and processing of messages are all processed in this thread, and the log collector 5' collects in each process node in an isolated manner.
[0004] In this way, the management of Websocket is not unified, which makes the module more fragmented and bloated when a large number of Websockets are connected. At the same time, since each connection creates a new thread separately and there is no priority, it cannot guarantee the expected effect when the message volume is huge and some messages received by some links need to be processed in real time. Summary of the invention
[0005] Based on this, it is necessary to provide a communication message processing method, electronic device, storage medium and computer program product to address the technical problems that the existing technology fails to uniformly manage links during real-time communication and has poor link stability.
[0006] The present invention provides a communication message processing method, comprising:
[0007] Running a background service component in the background, and running a client manager in the background service component;
[0008] A plurality of link clients are managed in the client manager, wherein the link clients use a real-time communication protocol to establish a communication link, and each of the link clients has a unique client identifier;
[0009] Sending the message received by the link client and the corresponding client identifier to a message processor, and the message processor storing the message in a thread queue of a message processing thread corresponding to the client identifier;
[0010] The message processing thread takes out the message from the thread queue for processing.
[0011] Further, managing a plurality of linked clients in the client manager includes:
[0012] Get one or more link messages to be created;
[0013] For each link message to be created, if the manager cache of the client manager stores the client identifier included in the link message to be created, the client link corresponding to the client identifier is retrieved from the manager cache; otherwise, a communication link is established based on the link message to be created using a real-time communication protocol; after successful establishment, the communication link is saved as a link client and stored in the management cache in association with the client identifier to be associated.
[0014] Furthermore, managing a plurality of linked clients in the client manager further includes:
[0015] When the link client receives a message, if an abnormal disconnection problem occurs, the link client with the abnormal disconnection problem is regarded as an abnormal client, the abnormal client is destroyed, the association between the abnormal client and the corresponding client identifier is disconnected, and the client identifier is removed from the manager cache.
[0016] Furthermore, the message processor stores the message in a thread queue of a message processing thread corresponding to the client identifier, including:
[0017] When the message processor receives the message and the corresponding client identifier, it searches whether there is a message processing thread corresponding to the client identifier. If so, it stores the message in the thread queue of the message processing thread corresponding to the client identifier; otherwise, it generates a new message processing thread and associates the link representation with the new message processing thread.
[0018] Furthermore, the generating a new message processing thread includes: generating a new message processing thread with a processing priority.
[0019] Further, the message processing thread takes out the message from the thread queue for processing, including:
[0020] The processing component of the message processing thread takes the message from the thread queue;
[0021] Preprocessing the message to obtain a preprocessed message;
[0022] Perform corresponding processing operations on the pre-processed message.
[0023] Furthermore, it also includes:
[0024] Tracking points are set in the service component, the client manager, the message processor, and the message processing thread, and the tracking points are used by the log collector to perform log recording.
[0025] The present invention provides an electronic device, comprising:
[0026] at least one processor; and,
[0027] a memory communicatively linked to at least one of the processors; wherein,
[0028] The memory stores instructions that can be executed by at least one of the processors. The instructions are executed by at least one of the processors to enable the at least one of the processors to execute the communication message processing method as described above.
[0029] The present invention provides a storage medium, wherein the storage medium stores computer instructions, and when a computer executes the computer instructions, it is used to execute all steps of the communication message processing method as described above.
[0030] The present invention provides a computer program product, comprising a computer program / instruction, which implements the communication message processing method as described above when executed by a processor.
[0031] The present invention improves the stability and scalability of the system, improves the stability and continuity of the real-time communication link, and avoids link interruption caused by UI thread blocking or restarting by using a background service to manage the link client of the real-time communication. At the same time, the message processor establishes an independent message processing thread for each link, maintains a queue in the thread, and the message processing thread takes messages from the queue for processing to ensure that the processing order is consistent with the receiving order. In addition, a unique identifier is generated for each real-time communication link to ensure that each link in the system is unique. When each message is generated, it is also accompanied by a unique identifier for subsequent tracking and management, avoiding conflicts and confusions between links and messages, and improving the reliability and maintainability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A communication message processing framework for the prior art;
[0033] Figure 2 A flowchart of a communication message processing method according to an embodiment of the present invention;
[0034] Figure 3 The communication message processing architecture of the best embodiment of the present invention;
[0035] Figure 4 A flowchart of a communication message processing method according to another embodiment of the present invention;
[0036] Figure 5 Creating a link logic flow chart for the client manager of the preferred embodiment of the present invention;
[0037] Figure 6 A workflow diagram of the client manager disconnection deletion management of the best embodiment of the present invention;
[0038] Figure 7 A message processor processing flow chart of the best embodiment of the present invention;
[0039] Figure 8 This is a log collection schematic diagram of the best embodiment of the present invention;
[0040] Fig. 9 The figure is a schematic diagram of the hardware structure of an electronic device of the present invention. DETAILED DESCRIPTION
[0041] The specific embodiments of the present invention are further described below in conjunction with the accompanying drawings. The same components are represented by the same reference numerals. It should be noted that the words "front", "rear", "left", "right", "upper" and "lower" used in the following description refer to directions in the accompanying drawings, and the words "inner" and "outer" refer to directions toward or away from the geometric center of a specific component, respectively.
[0042] Technical term explanation:
[0043] 1. WebSocket: WebSocket is a protocol for full-duplex communication over a single TCP connection, designed to enable real-time, low-latency communication between clients and servers;
[0044] 2. Message Queue: A message queue is a mechanism for delivering messages between message producers and message consumers. It can decouple producers and consumers and provide asynchronous communication and message persistence functions.
[0045] 3. Service: A service is a component that performs long-running operations in the background, usually used to perform tasks that need to be kept running or to continue operations when the application interface is not visible. The service runs without user interaction and can continue to run when the application is closed or moved to the background.
[0046] 4.Handler:Handler is used to send and process messages in the message queue of a specific thread. It is usually used to communicate between threads.
[0047] 5.HandlerThread:HandlerThread is a thread with a message loop.
[0048] like Figure 2 The flowchart of a communication message processing method according to an embodiment of the present invention includes:
[0049] Step S201, running a service component in the background, and running a client manager in the service component;
[0050] Step S202, managing a plurality of linked clients in the client manager, wherein the linked clients establish communication links using a real-time communication protocol, and each of the linked clients has a unique client identifier;
[0051] Step S203, sending the message received by the link client and the corresponding client identifier to the message processor, and the message processor stores the message in the thread queue of the message processing thread corresponding to the client identifier;
[0052] Step S204: the message processing thread takes out the message from the thread queue for processing.
[0053] Specifically, the present invention can be applied to a mobile terminal, such as a smart phone.
[0054] like Figure 3 The figure shows the communication message processing architecture of the best embodiment of the present invention, including: client manager 2: responsible for establishing and maintaining connection with the server, and sending and receiving messages; service component 1 (Service): running in the background, managing real-time communication connection, message queue and message transmission; message processor 3: responsible for processing received messages and executing corresponding business logic; business layer 4: used to maintain message processing threads, and perform corresponding preprocessing in message processing threads; rendering layer 5: rendering and outputting preprocessed data; log collector 6: receiving log data from real-time communication, summarizing and storing it.
[0055] The real-time communication protocol is preferably the WebSocket protocol, and the real-time communication link is a WebSocket link.
[0056] The specific logic is as follows:
[0057] First, step S201 is executed in the mobile terminal to run a service component in the background, and a client manager is run in the service component.
[0058] Among them, the service component is Service: Service is a component that runs in the background and is used to perform long-running operations without directly interacting with the user. It is suitable for performing tasks in the background of the application, such as playing music, processing network requests, performing file operations, etc. Even if the user switches to other applications, the Service can continue to run. It is an existing mature mobile backend component. Managing real-time communication links based on Service can effectively ensure the integrity and stability of real-time communication messages. The principle of the service component will not be elaborated on in detail.
[0059] Specifically, a client manager is run in the service component, wherein the client manager is preferably a WebSocket manager.
[0060] Then, step S202 is executed to manage a plurality of link clients in the client manager, wherein the link clients establish communication links using a real-time communication protocol, and each of the link clients has a unique client identifier.
[0061] Specifically, multiple link clients are managed in the client manager. For example, an entity is created by means of new WebSocket (wsUrl), and this entity is the link client, and a unique identifier is associated with this link client. The link client uses a real-time communication protocol to establish a communication link between the terminal and the server. Each link client establishes a communication connection with a server. The real-time communication protocol is preferably a WebSocket protocol. The link client is a communication link established based on communication parameters through a real-time communication protocol. Communication parameters include but are not limited to URL, port, etc. After the communication link is successfully established, it is saved as a link client and managed by the client manager, and a unique client identifier is associated with each link client.
[0062] Then, step S203 is executed to send the message received by the link client and the corresponding client identifier to the message processor, and the message processor stores the message in the thread queue of the message processing thread corresponding to the client identifier.
[0063] Specifically, when a linked client in the client manager receives a message from an external server, it will send the message with a unique client ID to the message processor for processing through a callback. In the message processor, a message processing thread is generated for each linked client, and all messages of the linked client will be stored in the thread queue of the corresponding message processing thread.
[0064] Then, step S204 is executed, and the message processing thread takes out the message from the thread queue for processing.
[0065] Specifically, the message is processed in the message processing thread, and the processed message is handed over to the rendering layer for front-end display or other operations, such as being sent back to the user through an interface callback. The user can define whether to continue to perform business logic in the message processing thread or switch to other threads for business logic processing.
[0066] The present invention improves the stability and scalability of the system, improves the stability and continuity of the real-time communication link, and avoids link interruption caused by UI thread blocking or restarting by using a background service to manage the link client of the real-time communication. At the same time, the message processor establishes an independent message processing thread for each link, maintains a queue in the thread, and the message processing thread takes messages from the queue for processing to ensure that the processing order is consistent with the receiving order. In addition, a unique identifier is generated for each real-time communication link to ensure that each link in the system is unique. When each message is generated, it is also accompanied by a unique identifier for subsequent tracking and management, avoiding conflicts and confusions between links and messages, and improving the reliability and maintainability of the system.
[0067] like Figure 4 The flowchart of a communication message processing method in another embodiment of the present invention includes:
[0068] Step S401: running a background service component in the background, and running a client manager in the background service component.
[0069] Step S402, obtaining one or more link messages to be created;
[0070] For each link message to be created, if the manager cache of the client manager stores the client identifier included in the link message to be created, the client link corresponding to the client identifier is retrieved from the manager cache; otherwise, a communication link is established based on the link message to be created using a real-time communication protocol; after successful establishment, the communication link is saved as a link client and stored in the management cache in association with the client identifier to be associated.
[0071] Step S403, when the link client receives a message, if an abnormal disconnection problem occurs, the link client with the abnormal disconnection problem is regarded as an abnormal client, the abnormal client is destroyed, the association between the abnormal client and the corresponding client identifier is disconnected, and the client identifier is removed from the manager cache.
[0072] Step S404, when the message processor receives the message and the corresponding client identifier, it searches whether there is a message processing thread corresponding to the client identifier. If so, the message is stored in the thread queue of the message processing thread corresponding to the client identifier; otherwise, a new message processing thread is generated and the link representation is associated with the new message processing thread.
[0073] In one embodiment, generating a new message processing thread includes: generating a new message processing thread with a processing priority.
[0074] Step S405, the processing component of the message processing thread takes the message from the thread queue;
[0075] Preprocessing the message to obtain a preprocessed message;
[0076] Perform corresponding processing operations on the pre-processed message.
[0077] In one embodiment, it also includes:
[0078] Tracking points are set in the service component, the client manager, the message processor, and the message processing thread, and the tracking points are used by the log collector to perform log recording.
[0079] Specifically, the background service component Service runs in the background and holds the client manager object to ensure that the application side can continue to receive messages from the linked client. The client manager is preferably a WebSocket manager, and the linked client receives WebSocket messages. After the background service component is started, the client manager uses a real-time communication protocol to create and manage the communication link. Preferably, WebSocket is used to create and manage the Socket link.
[0080] When the WebSocket manager receives a message from a linked client, it sends the message to the message processor, which preprocesses and stores the message. In the message processor, the message processor sends the message to the corresponding message processing thread, preprocesses the message in the message processing thread, and passes the preprocessed message to the rendering layer for visual display or other operations, such as returning it to the user through an interface callback. The user can define whether to continue to perform business logic in the message processing thread or switch to other threads for business logic processing.
[0081] Specifically, step S401 is first executed to run a background service component in the background, and a client manager is run in the background service component.
[0082] Among them, the service component is Service: Service is a component that runs in the background and is used to perform long-running operations without directly interacting with the user. It is suitable for performing tasks in the background of the application, such as playing music, processing network requests, performing file operations, etc. Even if the user switches to other applications, the Service can continue to run. It is an existing mature mobile backend component. Managing real-time communication links based on Service can effectively ensure the integrity and stability of real-time communication messages.
[0083] Then, step S402 is executed to obtain one or more link messages to be created;
[0084] For each link message to be created, if the manager cache of the client manager stores the client identifier included in the link message to be created, the client link corresponding to the client identifier is retrieved from the manager cache; otherwise, a communication link is established based on the link message to be created using a real-time communication protocol; after successful establishment, the communication link is saved as a link client and stored in the management cache in association with the client identifier to be associated.
[0085] The client manager mainly includes two functional modules: creating links and disconnecting links. Figure 5 The client manager of the best embodiment of the present invention creates a link logic flow chart, including:
[0086] Step S501, initializing the client manager;
[0087] Step S502: After the manager is successfully initialized, the connection is initialized. The initialization of the connection can be performed by using newWebsocket(wsUrl) to initialize the WebSocket connection client. When initializing the connection client, the user enters the client ID.
[0088] Step S503, determine whether the client identifier exists, if yes, execute step S504, otherwise execute step S505;
[0089] Step S504, directly query and return from the linked client cached by the manager, receive the message from the server through the linked client, and if abnormal, disconnect the association between the linked client and the client representation;
[0090] Step S505, start to establish a link. If successful, save the link client to the cache of the manager. If failed, try to re-establish the link.
[0091] Specifically, multiple Websocket clients can be established, each of which has a unique client identifier to ensure the uniqueness of the client and avoid unnecessary link creation. When the manager creates a link, it will first determine whether there is a corresponding link client based on the current identifier. If so, it will directly query and return the cached link client corresponding to the client identifier from the manager. If not, it will try to establish a link. If successful, the link client will be saved in the manager's cache. If it fails, it will try to re-establish the link.
[0092] When a created link client receives a message, there may be uncertain factors such as network anomalies that may cause the link client to be abnormally disconnected. Therefore, step S403 is executed. When the link client receives a message, if an abnormal disconnection problem occurs, the link client with the abnormal disconnection problem is regarded as an abnormal client, the abnormal client is destroyed, the association between the abnormal client and the corresponding client identifier is disconnected, and the client identifier is removed from the manager cache.
[0093] Specifically, Figure 6 Shown is a workflow diagram of the client manager disconnection deletion management of the best embodiment of the present invention, including:
[0094] Step S601, disconnect the link and obtain the client identifier;
[0095] Step S602, determine whether the client representation already exists, if not, end, otherwise execute step S603;
[0096] Step S603: Obtain the linked client corresponding to the client identifier from the manager cache, and disconnect and remove the client representation.
[0097] Specifically, when the communication of the linked client is abnormal, the second module of the client manager disconnects the link and mainly performs disconnection and deletion management through a single client identifier. The disconnection module actively destroys the abnormal linked client, removes the cached client identifier, and attempts to re-establish the link.
[0098] In the entire client manager, the client identifier is a very important object. When the client manager tries to disconnect a link, it first uses the client identifier to query whether the link client corresponding to the current identifier has been cached in the manager cache. If the current client identifier already exists, it means that the link client has established the link normally. Therefore, the existing link client is taken out from the manager cache to perform the disconnection operation. Finally, the client identifier in the manager cache is removed to complete the entire disconnection operation.
[0099] When a linked client in the client manager receives a message from the server, it sends the message with a unique client identifier to the message processor for processing through a callback, thereby executing step S404. When the message processor receives the message and the corresponding client identifier, it searches whether there is a message processing thread corresponding to the client identifier. If so, the message is stored in the thread queue of the message processing thread corresponding to the client identifier. Otherwise, a new message processing thread is generated and the link identifier is associated with the new message processing thread.
[0100] In one embodiment, generating a new message processing thread includes: generating a new message processing thread with a processing priority.
[0101] Specifically, when the message processor receives a message with a client identifier, it will first check whether there is a corresponding message processing thread (i.e., HandlerThread thread) represented by the client according to the client identifier. If so, the message will be stored in the first-in-first-out thread queue Message Queue of the corresponding message processing thread to ensure that the messages can be executed in an orderly manner. Otherwise, a message processing thread with a customizable processing priority will be generated, and the message will be stored in the first-in-first-out thread queue of the message processing thread.
[0102] Then, step S405 is executed, the processing component of the message processing thread takes out the message from the thread queue;
[0103] Preprocessing the message to obtain a preprocessed message;
[0104] Perform corresponding processing operations on the pre-processed message.
[0105] Specifically, each message processing thread has a Handler. When a message processing thread is created, the processing component Handler starts working. When there are messages in the thread queue Message Queue, the messages will be taken out of the Message Queue in turn and sent to the message processing thread with priority by the Handler for preprocessing. Preprocessing refers to unpacking the message to obtain the corresponding data.
[0106] Finally, the preprocessed data is handed over to the rendering layer for front-end display or other operations, such as being sent back to the user through an interface callback. The user can define whether to continue to perform business logic in the message processing thread or switch to other threads for business logic processing.
[0107] like Figure 7 Shown is a flow chart of a message processor process in a preferred embodiment of the present invention, comprising:
[0108] Step S701, the message processor receives the message + client identifier;
[0109] Step S702, according to the client indication, the message is stored in the corresponding message processing thread A, B, C, D, ...;
[0110] Step S703, in each message processing thread, storing the message in a first-in-first-out queue;
[0111] Step S704, the Handler takes the message from the queue and pre-processes the message in the message processing thread;
[0112] Step S705, sending the preprocessed data to the rendering layer for front-end display or other operations.
[0113] In one embodiment, it also includes:
[0114] Tracking points are set in the service component, the client manager, the message processor, and the message processing thread, and the tracking points are used by the log collector to perform log recording.
[0115] Specifically, the log collector in the prior art collects data in an isolated manner, which has the following problems:
[0116] 1. No precise control: Developers may not be able to precisely control the content of each log record, and the collected data may be generalized or not detailed enough.
[0117] 2. Delay: Due to asynchronous collection, logs may have a certain delay, and the real-time performance of log collection is poor, which is not suitable for scenarios that require immediate feedback.
[0118] 3. Dependence on external systems: It is necessary to rely on external log collection and storage systems. If the system fails, it may affect the integrity and availability of log data.
[0119] 4. Log loss problem: Even with asynchronous log collection, log data may be lost due to network or storage problems, especially when the network is unstable or the log queue is accumulated.
[0120] In this embodiment, the log collector is interspersed in various parts of the entire process in the form of embedded points, in order to ensure the troubleshooting of abnormal problems and statistics of data loss during message transmission and processing.
[0121] like Figure 8 The diagram shows a log collection diagram of the best embodiment of the present invention, wherein the log collector 6 can perform real-time log printing or local log caching after collecting logs.
[0122] In the entire process of this embodiment, the log collector is embedded from establishing links, abnormal reconnection to message reception and message preprocessing. When the actual process is executed to the corresponding position, the log collector will display the log information to the foreground and cache it locally in the form of files through real-time log printing and local log caching, so that problems can be counted and queried based on the log information during and after message processing.
[0123] This embodiment is a link client management based on service components. When processing messages, threads with priority are uniformly assigned through unique identifiers to process them, and messages are stored in a first-in-first-out message queue, and then polled for pre-processing. At the same time, logs are collected in a buried point manner.
[0124] Because this embodiment is based on the processing of the service component, it can better ensure that the linked client can still receive messages when the application is switched to the background, because the service component itself can perform time-consuming operations in the background for a long time without affecting the foreground application. The existing technology uses threads to manage links, which may cause link abnormalities after some pages in the application are destroyed, and the stability of the link cannot be guaranteed.
[0125] Before message processing, this embodiment will allocate and create threads with priorities based on the unique identifier of the link. The corresponding priority level can be set for the thread by manually adding priority sorting. When a large number of messages pour in, the system will give priority to the execution rights of threads with higher priorities, thereby ensuring that the program can output the expected results in order of priority.
[0126] When processing messages, this embodiment adds a corresponding first-in, first-out thread queue. Introducing a first-in, first-out (FIFO) message queue in a message processor has significant advantages, including ensuring the order of message processing, simplifying system design, improving system reliability and consistency, facilitating monitoring and debugging, and supporting concurrent processing.
[0127] The log collector is uniformly controlled in the solution, which will not have an intrusive impact on the existing code and reduce the complexity of code maintenance. It is suitable for scenarios that require rapid integration of log collection functions, such as system monitoring and data analysis after going online. It is easy to promote and apply in large-scale systems, reduce deployment costs and time, and can flexibly adjust the logging strategy as the business logic changes, facilitating independent maintenance and optimization of specific functional modules.
[0128] The summary is as follows: 1. This embodiment uses a background service (Service) to manage communication links and message processing, improve the stability and scalability of the system, improve the stability and continuity of communication links, and avoid connection interruptions caused by blocking or restarting the UI thread; 2. A first-in-first-out message queue is introduced in the message processor to ensure that messages are processed in the order in which they are received. Each connection maintains a queue, and the received messages are stored in the queue in order. The message processor takes out the messages from the queue in order for processing, ensuring that the processing order is consistent with the receiving order. 3. A unique identifier is generated for each communication link and each message to ensure that each connection in the system is unique. When each message is generated, it is also accompanied by a unique identifier for subsequent tracking and management, avoiding conflicts and confusion between connections and messages, and improving the reliability and maintainability of the system. 4. A message processing thread with settable priority is introduced, which can dynamically adjust the processing order according to the priority of the message. When each message processing thread is created, different priorities (high, medium, and low) can be set according to business needs. The message processing thread with high priority will give priority to urgent and important messages, and the message processing thread with low priority will process regular messages, improving the flexibility and efficiency of message processing, and ensuring that key messages are processed in a timely manner. 5. Realize real-time log collection, monitor system operation status and message processing, embed log collection modules in message processors and background services, record system operation status, message delivery status and processing results in real time, improve system monitorability, and obtain log information of system operation status and key events in real time.
[0129] Therefore, this embodiment can improve the efficiency of message processing; for multiple communication links, multiple data transmission links will be generated, and uniformly output to the message manager, and distributed to the message processes of different link batches through the message manager for consumption. When the message manager distributes, it is allowed to set different priorities for the message process according to the priority level of the message, and high-priority messages are processed first to ensure that key messages can be consumed in time and reduce delays. Through the management of background service components, the stability and fault tolerance of the system are enhanced. The service components running in the background are responsible for managing communication links and message processing to ensure that even if the application is switched to the background or killed, message processing can continue. The fault tolerance of the system is ensured by monitoring abnormal network status; real-time monitoring of abnormal network status changes, automatic reconnection and retransmission of unconfirmed messages when the network is restored, ensuring the reliability and continuity of message transmission when the network fluctuates or disconnects. Finally, this embodiment introduces a log collection tool to better monitor the entire system process and ensure that abnormal problems and data statistics can be quickly located and efficiently summarized.
[0130] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0131] like Fig. 9 The figure shows a hardware structure diagram of an electronic device of the present invention, including:
[0132] at least one processor 901; and,
[0133] A memory 902 that is communicatively linked to at least one of the processors 901; wherein,
[0134] The memory 902 stores instructions that can be executed by at least one of the processors. The instructions are executed by at least one of the processors to enable the at least one of the processors to execute the communication message processing method as described above.
[0135] Fig. 9 A processor 901 is taken as an example.
[0136] The electronic device may further include: an input device 903 and a display device 904 .
[0137] The processor 901, the memory 902, the input device 903 and the display device 904 may be linked via a bus or other means, and the figure takes linking via a bus as an example.
[0138] The memory 902 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the communication message processing method in the embodiment of the present application, for example, Figure 2 , Figure 4 The processor 901 executes various functional applications and data processing by running the non-volatile software programs, instructions and modules stored in the memory 902, that is, implements the communication message processing method in the above embodiment.
[0139] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created according to the use of the communication message processing method, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be linked to a device for executing the communication message processing method via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0140] The input device 903 can receive user clicks and generate signal inputs related to user settings and function control of the communication message processing method. The display device 904 can include display devices such as a display screen.
[0141] The one or more modules are stored in the memory 902, and when executed by the one or more processors 901, the communication message processing method in any of the above method embodiments is executed.
[0142] The present invention improves the stability and scalability of the system, improves the stability and continuity of the real-time communication link, and avoids link interruption caused by UI thread blocking or restarting by using a background service to manage the link client of the real-time communication. At the same time, the message processor establishes an independent message processing thread for each link, maintains a queue in the thread, and the message processing thread takes messages from the queue for processing to ensure that the processing order is consistent with the receiving order. In addition, a unique identifier is generated for each real-time communication link to ensure that each link in the system is unique. When each message is generated, it is also accompanied by a unique identifier for subsequent tracking and management, avoiding conflicts and confusions between links and messages, and improving the reliability and maintainability of the system.
[0143] An embodiment of the present invention provides a storage medium, wherein the storage medium stores computer instructions. When a computer executes the computer instructions, the storage medium is used to execute all steps of the communication message processing method as described above.
[0144] In the context of the present disclosure, a storage medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. The storage medium may be a machine-readable signal medium or a machine-readable storage medium. Alternatively, the storage medium may be a non-temporary computer-readable storage medium, for example, a non-temporary computer-readable storage medium may be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0145] An embodiment of the present invention provides a computer program product, including a computer program / instruction, which implements the communication message processing method as described above when executed by a processor.
[0146] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A communication message processing method, characterized in that: include: Running a background service component in the background, and running a client manager in the background service component; A plurality of link clients are managed in the client manager, wherein the link clients use a real-time communication protocol to establish a communication link, and each of the link clients has a unique client identifier; Sending the message received by the link client and the corresponding client identifier to a message processor, and the message processor storing the message in a thread queue of a message processing thread corresponding to the client identifier; The message processing thread takes out the message from the thread queue for processing.
2. The communication message processing method according to claim 1, characterized in that: The managing of multiple linked clients in the client manager includes: Get one or more link messages to be created; For each link message to be created, if the manager cache of the client manager stores the client identifier included in the link message to be created, the client link corresponding to the client identifier is retrieved from the manager cache; otherwise, a communication link is established based on the link message to be created using a real-time communication protocol; after successful establishment, the communication link is saved as a link client and stored in the management cache in association with the client identifier.
3. The communication message processing method according to claim 2, characterized in that: The managing of multiple linked clients in the client manager further includes: When the link client receives a message, if an abnormal disconnection problem occurs, the link client with the abnormal disconnection problem is regarded as an abnormal client, the abnormal client is destroyed, the association between the abnormal client and the corresponding client identifier is disconnected, and the client identifier is removed from the manager cache.
4. The communication message processing method according to claim 1, characterized in that: The message processor stores the message in a thread queue of a message processing thread corresponding to the client identifier, including: When the message processor receives the message and the corresponding client identifier, it searches whether there is a message processing thread corresponding to the client identifier. If so, it stores the message in the thread queue of the message processing thread corresponding to the client identifier; otherwise, it generates a new message processing thread and associates the link representation with the new message processing thread.
5. The communication message processing method according to claim 4, characterized in that: The generating a new message processing thread includes: generating a new message processing thread with a processing priority.
6. The communication message processing method according to claim 1, characterized in that: The message processing thread takes out the message from the thread queue for processing, including: The processing component of the message processing thread takes the message from the thread queue; Preprocessing the message to obtain a preprocessed message; Perform corresponding processing operations on the pre-processed message.
7. The communication message processing method according to claim 1, characterized in that: Also includes: Tracking points are set in the service component, the client manager, the message processor, and the message processing thread, and the tracking points are used by the log collector to perform log recording.
8. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively linked to at least one of the processors; wherein, The memory stores instructions that can be executed by at least one of the processors, and the instructions are executed by at least one of the processors to enable at least one of the processors to execute the communication message processing method according to any one of claims 1 to 7.
9. A storage medium, characterized in that: The storage medium stores computer instructions, and when a computer executes the computer instructions, it is used to execute all steps of the communication message processing method according to any one of claims 1 to 7.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the communication message processing method according to any one of claims 1 to 7 is implemented.