A message sending implementation method based on asynchronous thread pool

By combining asynchronous thread pools and message queues in a distributed messaging system, and using interceptors and factory modes to partition messages, the problems of message queue blocking and uncontrollable network transmission are solved, and the stability and non-blocking nature of message sending are achieved. , which improves the portability and resource utilization efficiency of the system.

CN112084047BActive Publication Date: 2025-01-24SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010958817.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-14
Publication Date
2025-01-24
Estimated Expiration
2040-09-14

AI Technical Summary

Technical Problem

Existing distributed message systems are difficult to control during network transmission, resulting in messages that may not be delivered, and message queue blocking problems are common, affecting system stability and resource utilization efficiency.

Method used

An asynchronous thread pool-based message sending implementation method is adopted, messages are partitioned through interceptors and factory patterns, and the asynchronous thread pool and message queue are combined to achieve the stability and non-blocking nature of message sending.

Benefits of technology

The stability and non -blocking of the message sending are realized, the probability of message loss and the probability of queue blocking, and improve the transplantability and resource utilization efficiency of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112084047B_ABST
    Figure CN112084047B_ABST
Patent Text Reader

Abstract

The invention discloses a message sending implementation method based on an asynchronous thread pool, and relates to the technical field of message processing. The method of the invention is used to filter a message after being filtered by an interceptor when the message arrives at a message entrance, and then partition the message using a factory mode, and start an asynchronous thread pool for the partitioned message to call different sending platforms via a message queue to send the message; the message storage and the message sending are separated, and in order to ensure the real-time and accuracy of the message sending, the asynchronous thread pool and the message queue are combined, so that the message sending only needs to focus on the interaction with the message queue, and good portability is achieved, the advantages of the message queue are brought into play to the greatest extent, and the probability of queue blocking is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention discloses an implementation method, and relates to the technical field of message processing, in particular to a message sending implementation method based on an asynchronous thread pool. Background Art

[0002] With the development of information technology, various distributed message queues emerge in an endless stream. Most message queues themselves will combine distributed frameworks to meet the basic principle of asynchronous sending. However, since the underlying layer of distributed messages is based on the UDP and TCP protocols of the network, the network is the most uncontrollable factor in information technology. Messages may not be delivered to the target for various reasons. Network transmission is difficult to control, and the quality of network communication has therefore become difficult to predict. Many large-scale distributed message systems are very difficult to build due to communication problems. Although different manufacturers have unique requirements for their own products, most of them have basically the same requirements for message systems. If the message system is integrated with other business logics, it will not only affect the quality of the main message sending, but also easily cause duplicate construction and waste of resources. Summary of the invention

[0003] In view of the problems of the prior art, the present invention provides a message sending implementation method based on an asynchronous thread pool, which ensures the stability of message sending and solves the problem of message queue blocking. The message entry and message sending are separated to adapt to different product environments and different business scenarios. The method has the characteristics of no loss of message records and no blocking of message sending, which facilitates the location of sending failure problems.

[0004] The specific scheme proposed by the present invention is:

[0005] A message sending implementation method based on asynchronous thread pool: after the message arrives at the message entrance and is filtered by the interceptor, the message is partitioned using the factory mode, and the asynchronous thread pool is started for the partitioned message to call different sending platforms through the message queue to send the message.

[0006] Preferably, in the message sending implementation method based on the asynchronous thread pool, the chain of responsibility pattern is used to implement the sorting of interceptors according to priority.

[0007] Preferably, the filtering process in the message sending implementation method based on asynchronous thread pool:

[0008] The interceptor with the highest priority is placed at the first level of the responsibility chain, and messages that meet the conditions continue to be filtered by the next level of filters until they pass all interceptors.

[0009] Preferably, in the message sending implementation method based on the asynchronous thread pool, message filtering is dynamically adjusted by changing the responsibility chain or mobilizing the order of interceptors.

[0010] Preferably, in the message sending implementation method based on the asynchronous thread pool, the number of threads in the asynchronous thread pool is started according to the blocking threshold of the message queue.

[0011] Preferably, in the message sending implementation method based on the asynchronous thread pool, the corePoolSize and maxPoolSize in the asynchronous thread pool are adjusted to coordinate the buffer concurrent operations.

[0012] A message sending implementation system based on an asynchronous thread pool includes a filtering module, a partitioning module and a sending module.

[0013] The filtering module uses the interceptor to filter the message when it arrives at the message entry. The partitioning module uses the factory mode to partition the message. For the partitioned message, the sending module starts the asynchronous thread pool and calls different sending platforms through the message queue to send the message.

[0014] A message sending implementation device based on an asynchronous thread pool, comprising at least one memory and at least one processor;

[0015] The at least one memory is used to store a machine-readable program;

[0016] The at least one processor is used to call the machine-readable program to execute the message sending implementation method based on the asynchronous thread pool.

[0017] The benefits of the present invention are:

[0018] The present invention provides a message sending implementation method based on an asynchronous thread pool, which uses an interceptor and a factory mode to act on a message entrance to separate message storage from message sending. In order to ensure the real-time and accuracy of message sending, the asynchronous thread pool and the message queue are combined according to the characteristics of the message queue and the scenario in which the distributed framework is used, so that message sending only needs to focus on the interaction with the message queue, thereby achieving good portability, maximizing the advantages of the message queue, and reducing the probability of queue blocking. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 It is a schematic diagram of the message filtering and storage process in the method of the present invention;

[0020] Figure 2 It is a schematic diagram of the message grouping sending process in the method of the present invention;

[0021] Figure 3 It is a schematic diagram related to message recording in the method of the present invention;

[0022] Figure 4 It is a schematic diagram of the message management function in the method of the present invention. DETAILED DESCRIPTION

[0023] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0024] The present invention provides a message sending implementation method based on an asynchronous thread pool: after a message arrives at a message entry and is filtered by an interceptor, the message is partitioned using a factory mode, and an asynchronous thread pool is started for the partitioned message, and different sending platforms are called via a message queue to send the message.

[0025] At present, the main messages are mainly divided into station letters, short messages and mails. When the message arrives at the message entrance, it will first pass through the interceptor, and then the factory pattern (Factory Pattern) will be used to distinguish the message. After packaging, the asynchronous thread pool is started to call different sending platforms via the message queue to send messages. Wherein the method of the present invention combines the asynchronous thread pool with rabbitMq, the high timeliness and availability of the message queue can be maximized, the rabbitMQ bottom layer uses AMQP, i.e. AdvancedMessage Queuing Protocol, and the advanced message queue protocol. The message entrance forms an interceptor+factory pattern classification, and the actual sending project introduces the asynchronous thread pool+message queue, which realizes the opening and closing principle of software development, and is convenient for locating the sending problem. The situation that the message queue is blocked will not be caused, and the message loss rate is greatly reduced. The system has good mobility, and the interceptor and factory pattern can be increased in combination with its own needs. The message entrance and the sending component use different databases respectively, and the core part is in the sending component. The data will call the mail platform OTRS and the SMS platform respectively after the message queue, and the sending result can be recorded in detail after calling other platforms, and the message sending record is finally managed through the graphical interface.

[0026] The method of the present invention can use the architecture of microservices to separate the various modules of the project. For example, the eureka registration center is used to separate the message entry and the actual sending part, and Apollo is used to realize the unified management of the configuration file, which can ensure the real-time performance of message sending.

[0027] In some embodiments of the method of the present invention, AOP (Aspect-Oriented Programming) is used for the control and interception of message sending permissions. Multiple interceptors are used in the message sending process and are sorted in order of priority. Multiple interceptors are encapsulated into independent receivers and added to the responsibility chain, which well achieves the effect of layer-by-layer filtering and is very friendly to the subsequent addition of interceptors. For example, the message system switch with the highest priority is placed in the first layer of the responsibility chain, that is, a downward chain is created for the message sending request in the initial stage. If the message system is turned on and the conditions are met, it continues to filter downward. After that, it is determined whether the message recipient is added to the whitelist. If the conditions are met, it is executed downward until all interceptors are passed, thereby enhancing the flexibility of assigning responsibilities to objects. Responsibilities can be dynamically added or deleted by changing the members in the chain or adjusting the order of the interceptors.

[0028] After the message passes through the interceptor, the factory pattern will be used to distinguish the messages, package them, and call the interfaces of the sending components respectively.

[0029] In other embodiments of the present invention, the call of the message content can be decoupled through the message queue. However, for different message sending methods, the difference is basically the use of the tool class. The factory pattern can separate the creation and use process of the object. Therefore, even in the two scenarios of email and text message, the creation and sending of the object can be unified, reducing a lot of code duplication. This decoupling method also meets the design principles of Java. If the subsequent sending business logic changes, there is no need to find all the creation processes to modify them one by one. You only need to change the specified factory, which reduces the maintenance cost. In addition, because the factory pattern manages the creation logic of the object, the later optimization does not need to know the specific creation process, just use it, reducing the user's errors caused by the creation logic.

[0030] In factory mode, the asynchronous thread pool is started according to the scheduled task, the sending frequency and the amount of messages sent are controlled, and rabbitMQ is combined to call the mail platform OTRS and the SMS platform to distinguish and send messages. When sending mail, the SMTP mail server can be used, the javaEmailSender tool class is used to create a mail sending object, the SMTP protocol is applied, and the relevant parameters are configured to control the mail properties. The javaEmailSender component supports the SMTP protocol very well. Many commonly used mailboxes have their own SMTP servers, such as NetEase mailbox is smtp.163.com, and QQ mailbox is smtp.qq.com. When using, it is necessary to initialize the encoding format, port number, and permission control parameters. Many mailboxes do not open the SMTP service by default, and need to be manually set. The main reason for the use of the SMTP server in the present invention is because it is very stable relative to other mail servers, and it is very compatible with SpringBoot. When calling parameters, focus on the outbox, inbox, and sent content, which is convenient for subsequent function expansion.

[0031] Message sending and delivery have strict requirements on real-time performance, and require threads to shorten the response time as much as possible. For example, users need to send emails to employees in a department. If the time interval between the emails received by each of these employees is too large, for some urgent emails, the first person who receives it may have a time interval of several hours with the last person who receives it, so the last person who receives the email will not have enough time to process it. In this scenario, when starting the asynchronous thread pool, the present invention adjusts the corePoolSize and maxPoolSize of the thread pool to handle the buffer concurrency problem. The use of the thread pool can greatly shorten the response time of the email sending interface. At the same time, for the synchronization logic of the status in the sending records of a large number of emails and text messages, the present invention focuses on accurately recording the sending status and the actual sending failure reasons. Subsequent users can quickly locate the problem through page information. For example, when a user sends text messages with different contents to thousands of users by manually sending messages, the content of the text messages will also be different due to the difference in the transmission parameters when the recipients have different contact information. The use of the thread pool can speed up the processing of such large tasks, improve the system throughput, and focus on using limited resources to process more callback tasks per unit time as much as possible, update the sending status in real time, and improve the user experience. Users can log in to the message center through a graphical interface to view their received messages, handle the navigation bars of all messages and unread messages separately, count the main categories of message types, and display the total number and unread number in a list.

[0032] Administrators can log in to the message management system to add, delete and modify message types, configure templates for each message type, and use the sending records to view all messages sent through the message center, with detailed records of message sending time and recipient contact information. The whitelist and system options mainly cooperate with the interceptor of the message center to provide it with an operational page. At the same time, the SMS provider can be switched in the graphical interface system options.

[0033] In addition to the method of the present invention, the present invention also provides a message sending implementation system based on an asynchronous thread pool, including a filtering module, a partitioning module and a sending module.

[0034] The filtering module uses the interceptor to filter the message when it arrives at the message entry. The partitioning module uses the factory mode to partition the message. For the partitioned message, the sending module starts the asynchronous thread pool and calls different sending platforms through the message queue to send the message.

[0035] The information interaction, execution process and other contents between the modules in the above-mentioned system are based on the same concept as the embodiment of the method of the present invention. For the specific contents, please refer to the description in the embodiment of the method of the present invention, and no further description is given here.

[0036] At the same time, the present invention also provides a message sending implementation device based on an asynchronous thread pool, comprising at least one memory and at least one processor;

[0037] The at least one memory is used to store a machine-readable program;

[0038] The at least one processor is used to call the machine-readable program to execute the message sending implementation method based on the asynchronous thread pool.

[0039] The information interaction of the processor in the above-mentioned device, the process of executing the readable program, etc., are based on the same concept as the embodiment of the method of the present invention. The specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.

[0040] It should be noted that not all steps and modules in the above-mentioned processes and systems and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.

[0041] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.

Claims

1. A message sending implementation method based on an asynchronous thread pool, characterized in that When the message arrives at the message entrance, multiple interceptors are used, and the responsibility chain pattern is used to implement the interceptors to sort by priority to filter the message. Multiple interceptors are encapsulated into independent receivers and added to the responsibility chain. The responsibility chain is a chain of downward responsibility created based on the message sending request in the initial stage. The interceptor with the highest priority is placed in the first layer of the responsibility chain. Messages that meet the conditions continue to be filtered by the next layer of interceptors until they pass through all interceptors. The members in the responsibility chain are changed or the order of the interceptors is adjusted to dynamically add or delete the responsibility chain. After the message passes through the interceptor, the factory mode is used to partition the message. In the factory mode, the asynchronous thread pool is started according to the scheduled task to control the sending frequency and the amount of messages sent. In combination with rabbitMQ, the mail platform OTRS and the SMS platform are called respectively to differentiate and send messages.

2. According to the method for implementing message sending based on asynchronous thread pool in claim 1, it is characterized by: The number of threads in the asynchronous thread pool is started based on the blocking threshold of the message queue.

3. A message sending implementation method based on an asynchronous thread pool according to claim 1 or 2, characterized in that Coordinate buffered concurrent operations by adjusting corePoolSize and maxPoolSize within the asynchronous thread pool.

4. A message sending implementation system based on an asynchronous thread pool, characterized in that Including filtering module, partitioning module and sending module, The filtering module uses interceptors to filter messages when they arrive at the message entry. The filtering module uses multiple interceptors and uses the responsibility chain mode to implement interceptors sorting by priority to filter messages. Multiple interceptors are encapsulated into independent receivers and added to the responsibility chain. The responsibility chain is a chain of downward responsibility created based on the message sending request in the initial stage. The interceptor with the highest priority is placed in the first layer of the responsibility chain. Messages that meet the conditions continue to be filtered by the next layer of interceptors until they pass through all interceptors. Changing the members in the responsibility chain or mobilizing the order of interceptors can realize dynamic addition or deletion of responsibility chains. After the message passes through the interceptor, the partitioning module uses the factory mode to partition the message. In the factory mode, the asynchronous thread pool is started according to the scheduled task to control the sending frequency and the amount of messages sent. In combination with rabbitMQ, the email platform OTRS and the SMS platform are called respectively to differentiate and send messages.

5. A message sending implementation device based on an asynchronous thread pool, characterized in that comprising at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is used to call the machine-readable program to execute the message sending implementation method based on an asynchronous thread pool as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Message sending method and device

    CN105430070A

  • Distributed data synchronization method, device and equipment and readable storage medium

    CN110502583A