CN112084047A - Message sending implementation method based on asynchronous thread pool - Google Patents

Message sending implementation method based on asynchronous thread pool Download PDF

Info

Publication number
CN112084047A
CN112084047A CN202010958817.5A CN202010958817A CN112084047A CN 112084047 A CN112084047 A CN 112084047A CN 202010958817 A CN202010958817 A CN 202010958817A CN 112084047 A CN112084047 A CN 112084047A
Authority
CN
China
Prior art keywords
message
sending
thread pool
asynchronous thread
queue
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010958817.5A
Other languages
Chinese (zh)
Inventor
刘洋
颜亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Cloud Information Technology Co Ltd
Original Assignee
Inspur Cloud Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Cloud Information Technology Co Ltd filed Critical Inspur Cloud Information Technology Co Ltd
Priority to CN202010958817.5A priority Critical patent/CN112084047A/en
Publication of CN112084047A publication Critical patent/CN112084047A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Abstract

The invention discloses a message sending implementation method based on an asynchronous thread pool, relating to the technical field of message processing; the method is utilized to partition the message by a factory mode after the message is filtered by an interceptor when the message reaches a message inlet, and to start an asynchronous thread pool for the partitioned message and call different sending platforms through a message queue to send the message; the method separates message storage and message sending, combines an asynchronous thread pool and a message queue in order to ensure the real-time performance and the accuracy rate of the message sending, ensures that the message sending only needs to pay attention to the interaction with the message queue, realizes good portability, furthest exerts the advantages of the message queue and reduces the probability of queue blocking.

Description

Message sending implementation method based on asynchronous thread pool
Technical Field
The invention discloses an implementation method, relates to the technical field of message processing, and particularly relates to a message sending implementation method based on an asynchronous thread pool.
Background
With the development of information technology, various distributed message queues are layered endlessly, most of the message queues are combined with a distributed framework to meet the basic principle of asynchronous sending, but because the bottom layer of the distributed message is based on the propagation of UDP and TCP protocols of a network, the network belongs to the most uncontrollable factor in the information technology, the message may not reach a target for various reasons, the transmission of the network is difficult to control, and the network communication quality is difficult to estimate.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a message sending implementation method based on an asynchronous thread pool, which ensures the stability of message sending, solves the problem of message queue blocking, separates a message inlet from message sending, can adapt to different product environments and different service scenes, has the characteristics of no loss of message records and no blocking of message sending, and is convenient for positioning the problem of sending failure.
The specific scheme provided by the invention is as follows:
a message sending implementation method based on an asynchronous thread pool comprises the following steps: after the message reaches the message inlet and is filtered by the interceptor, the message is partitioned by using a factory mode, and different sending platforms are called by a message queue to send the message by starting an asynchronous thread pool for the partitioned message.
Preferably, in the method for implementing message sending based on the asynchronous thread pool, the interceptors are sorted according to priority by using a chain of responsibility mode.
Preferably, the filtering process in the method for implementing message sending based on the asynchronous thread pool comprises:
the interceptor with the highest priority is placed at the first layer of the responsibility chain, and the messages meeting the conditions continue to be filtered by the next layer of filter until all the interceptors are passed.
Preferably, in the method for implementing message sending based on the asynchronous thread pool, message filtering is dynamically adjusted by changing a chain of responsibility or invoking an order of interceptors.
Preferably, in the method for implementing message sending based on the asynchronous thread pool, the number of threads in the asynchronous thread pool is set according to a blocking threshold of a message queue.
Preferably, in the method for implementing message sending based on the asynchronous thread pool, the concurrent buffering operation is coordinated by adjusting corePoolSize and maxPoolSize in the asynchronous thread pool.
A message sending implementation system based on an asynchronous thread pool comprises a filtering module, a partitioning module and a sending module,
the filtering module filters the message by using the interceptor when the message reaches the message inlet, the partitioning module partitions the message by using a factory mode, and the message sending module starts an asynchronous thread pool after partitioning and calls different sending platforms to send the message through a message queue.
A message sending realizing device based on an asynchronous thread pool comprises at least one memory and at least one processor;
the at least one memory to store a machine readable program;
the at least one processor is configured to invoke the machine readable program to execute the asynchronous thread pool-based message sending implementation method.
The invention has the advantages that:
the invention provides a method for realizing message sending based on an asynchronous thread pool, which uses an interceptor and a factory mode to act on a message inlet to separate message storage and message sending, and combines the asynchronous thread pool and the message queue according to the characteristics of the message queue and the using scene of a distributed framework in order to ensure the real-time performance and the accuracy of the message sending, so that the message sending only needs to pay attention to the interaction with the message queue, good portability is realized, the advantages of the message queue are exerted to the greatest extent, and the probability of queue blocking is reduced.
Drawings
FIG. 1 is a schematic diagram of a message filtering and storing process in the method of the present invention;
FIG. 2 is a diagram illustrating a message packet transmission process in the method of the present invention;
FIG. 3 is a diagram illustrating message record correlation in the method of the present invention;
fig. 4 is a schematic diagram of the message management function in the method of the present invention.
Detailed Description
The present invention is further described below in conjunction with the following figures and specific examples so that those skilled in the art may better understand the present invention and practice it, but the examples are not intended to limit the present invention.
The invention provides a message sending implementation method based on an asynchronous thread pool, which comprises the following steps: after the message reaches the message inlet and is filtered by the interceptor, the message is partitioned by using a factory mode, and different sending platforms are called by a message queue to send the message by starting an asynchronous thread pool for the partitioned message.
At present, main messages are mainly divided into in-station messages, short messages and mails, when the messages arrive at a message inlet, the messages pass through an interceptor, then are distinguished by using a Factory Pattern (Factory Pattern), and after being packaged, an asynchronous thread pool is started to call different sending platforms through a message queue to send the messages. In the method, the asynchronous thread pool and the rabbitMq are combined, so that the high timeliness and the availability of the message queue can be maximally exerted, the bottom layer of the rabbitMQ uses AMQP, namely Advanced Message Queuing Protocol, an interceptor and factory mode classification are formed at a Message inlet, an asynchronous thread pool and a Message queue are introduced into an actual sending project, the switching principle of software development is realized, the problem of sending is conveniently positioned, the condition of Message queue blockage is not caused, the Message loss rate is greatly reduced, the system mobility is good, the interceptor and the factory mode can be added by combining the self requirement, the message inlet and the sending component respectively use different databases, the core part respectively calls an e-mail platform OTRS and a short message platform after the data passes through the message queue in the sending component, and after other platforms can be called, the sending result is recorded in detail, and finally the message sending record is managed through a graphical interface.
The method can use the micro-service architecture to isolate each module of the project, for example, an eureka registration center is used to separate a message inlet from an actual sending part, and Apollo is used to realize the unified management of configuration files, thereby ensuring the real-time property of message sending.
In some embodiments of the method of the present invention, AOP (Aspect-organized Programming) is used for controlling and intercepting the message sending authority, the message sending process uses a plurality of interceptors, the interceptors are sorted according to the priority in sequence, and are encapsulated into independent receivers to be added into a responsibility chain, so that the effect of filtering layer by layer is well achieved, the interceptors are friendly to subsequent addition, such as a message system switch with the highest priority, and are placed in the first layer of the responsibility chain, that is, a downward-passing chain is created for the message sending request in the initial stage, if the message system is started, the condition is met, the downward filtering is continued, and then whether the message receiver is added into a white list is judged, the condition is met, the downward execution is performed until the flexibility of assigning responsibility to the object is enhanced through all the interceptors, and by changing the members in the chain or the order of transferring the interceptors, while dynamically adding or removing responsibility.
After the message passes through the interceptor, the message is distinguished by using a Factory Pattern (Factory Pattern), and the interfaces of the sending components are respectively called after the message is packaged.
In other embodiments of the present invention, the call to the message content can be decoupled through the message queue, however, for different message sending modes, the difference is basically the use of the tool class. The factory mode can just separate the creation and use processes of the objects, so that even in two scenes of mails and short messages, the objects can be uniformly created and sent, and a large amount of code repetition is reduced. The decoupling mode simultaneously meets the design principle of java, if the subsequent service logic is sent to change, all the creating processes do not need to be found to be modified one by one, only the appointed factory needs to be changed, the maintenance cost is reduced, in addition, because the factory mode manages the creating logic of the object, the later optimization does not need to know the specific creating process, only the use is needed, and the errors caused by the creating logic of a user are reduced.
In a factory mode, an asynchronous thread pool is started according to a timing task, the sending frequency and the message sending quantity are controlled, and a mail platform OTRS and a short message platform are respectively called to carry out differentiated sending of messages by combining with a rabbitMQ. When sending the mail, the SMTP mail server can be used for creating a mail sending object by using a javaEmaiSender tool class, and an SMTP protocol is applied to configure relevant parameters to control the mail attribute. The Java email sender component well supports the SMTP protocol, a plurality of common mailboxes have the SMTP server of the user, for example, the network mailbox is smtp.163.com, the QQ mailbox is smtp.qq. com, when the SMTP server is used, parameters such as an encoding format, a port number, authority control and the like need to be initialized, and a plurality of mailboxes do not start the SMTP service by default and need to be set manually by the user.
The message sending and delivery have strict requirements on real-time performance, the thread is required to shorten the response time as much as possible, for example, a user needs to send a mail group to employees in a department, if the time interval of the mail received by each employee is too large, for some emergency mails, the time interval between the first received person and the last received person may reach several hours, then the processing time of the last person receiving the mail is insufficient, in this scene, when the asynchronous thread pool is started, the corePoolSize and maxPoolSize of the thread pool are adjusted to process the buffering and sending problems, and the thread pool can greatly shorten the response time of the mail sending interface. Meanwhile, for the synchronous logic of the states in the sending records of a large number of mails and short messages, the method focuses on accurately recording the sending states and the actual sending failure reasons, and the subsequent users can quickly locate the problems through page information, for example, the users send the short messages with different contents to thousands of users through manual message sending, and under the condition that the contact ways of the recipients are different, the contents of the short messages are different due to differences in transmission, the thread pool is used to accelerate the processing of large tasks, the throughput of the system is improved, more callback tasks are processed in unit time as much as possible by using limited resources, the sending states are updated in real time, and the user experience is improved. A user can check own received messages through a graphical interface management login message center, the navigation bars of all messages and unread messages are processed independently, the types of the messages are counted and classified, and all the messages and the unread messages are displayed in a list.
The administrator can log in the message management system to add, delete and modify message types, configure templates for each message type, check all messages sent by the message center by using the sending records, record the message sending time and the contact way of the addressees in detail, and provide an operable page for the interceptors of the message center by mainly matching the white list and system options, and can manage the system options and switch short message providers on a graphical interface.
Besides the method of the invention, the invention also provides a message sending realization system based on the asynchronous thread pool, which comprises a filtering module, a partitioning module and a sending module,
the filtering module filters the message by using the interceptor when the message reaches the message inlet, the partitioning module partitions the message by using a factory mode, and the message sending module starts an asynchronous thread pool after partitioning and calls different sending platforms to send the message through a message queue.
The information interaction, execution process and other contents between the modules in the system are based on the same concept as the method embodiment of the present invention, and specific contents can be referred to the description in the method embodiment of the present invention, and are not described herein again.
The invention also provides a device for realizing message sending based on the asynchronous thread pool, which comprises at least one memory and at least one processor;
the at least one memory to store a machine readable program;
the at least one processor is configured to invoke the machine readable program to execute the asynchronous thread pool-based message sending implementation method.
The information interaction of the processor in the device, the process of executing the readable program, and the like are based on the same concept as the method embodiment of the present invention, and specific contents may refer to the description in the method embodiment of the present invention, and are not described herein again.
It should be noted that not all steps and modules in the above flows and system and device structures are necessary, and some steps or modules may be omitted according to actual needs. The execution order of the steps is not fixed and can be adjusted as required. The system structure described in the above embodiments may 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 a plurality of physical entities, or some components in a plurality of independent devices may be implemented together.
The above-mentioned embodiments are merely preferred embodiments for fully illustrating the present invention, and the scope of the present invention is not limited thereto. The equivalent substitution or change made by the technical personnel in the technical field on the basis of the invention is all within the protection scope of the invention. The protection scope of the invention is subject to the claims.

Claims (8)

1. A method for realizing message sending based on asynchronous thread pool is characterized in that a message is partitioned by a factory mode after the message reaches a message inlet and is filtered by an interceptor, and the asynchronous thread pool is started for the partitioned message to call different sending platforms to send the message through a message queue.
2. The method as claimed in claim 1, wherein the interceptors are sorted according to priority using a chain of responsibility model.
3. The method for implementing message sending based on asynchronous thread pool as claimed in claim 1 or 2, wherein the filtering process:
the interceptor with the highest priority is placed at the first layer of the responsibility chain, and the messages meeting the conditions continue to be filtered by the next layer of filter until all the interceptors are passed.
4. The method as claimed in claim 3, wherein the message filtering is dynamically adjusted by changing the chain of responsibility or invoking the order of interceptors.
5. The method as claimed in claim 4, wherein the number of threads in the asynchronous thread pool is set according to a blocking threshold of the message queue.
6. The method of claim 1 or 5, wherein the concurrent operations of buffering are coordinated by adjusting corePoolSize and maxPoolSize in the asynchronous thread pool.
7. A message sending implementation system based on an asynchronous thread pool is characterized by comprising a filtering module, a partitioning module and a sending module,
the filtering module filters the message by using the interceptor when the message reaches the message inlet, the partitioning module partitions the message by using a factory mode, and the message sending module starts an asynchronous thread pool after partitioning and calls different sending platforms to send the message through a message queue.
8. A message sending realizing device based on an asynchronous thread pool is characterized by comprising at least one memory and at least one processor;
the at least one memory to store a machine readable program;
the at least one processor, configured to invoke the machine readable program, to execute the asynchronous thread pool based message sending implementation method of any one of claims 1 to 6.
CN202010958817.5A 2020-09-14 2020-09-14 Message sending implementation method based on asynchronous thread pool Pending CN112084047A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010958817.5A CN112084047A (en) 2020-09-14 2020-09-14 Message sending implementation method based on asynchronous thread pool

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010958817.5A CN112084047A (en) 2020-09-14 2020-09-14 Message sending implementation method based on asynchronous thread pool

Publications (1)

Publication Number Publication Date
CN112084047A true CN112084047A (en) 2020-12-15

Family

ID=73736996

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010958817.5A Pending CN112084047A (en) 2020-09-14 2020-09-14 Message sending implementation method based on asynchronous thread pool

Country Status (1)

Country Link
CN (1) CN112084047A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112632032A (en) * 2020-12-18 2021-04-09 华人运通(上海)云计算科技有限公司 Data migration method and device, storage medium and terminal equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112632032A (en) * 2020-12-18 2021-04-09 华人运通(上海)云计算科技有限公司 Data migration method and device, storage medium and terminal equipment
CN112632032B (en) * 2020-12-18 2022-12-27 华人运通(上海)云计算科技有限公司 Data migration method and device, storage medium and terminal equipment

Similar Documents

Publication Publication Date Title
US6941341B2 (en) Method and apparatus for balancing distributed applications
US20030182464A1 (en) Management of message queues
US8719780B2 (en) Application server with a protocol-neutral programming model for developing telecommunications-based applications
CN106375241B (en) Batch data processing method, front-end system, host and batch data processing system
US20040139166A1 (en) Method and system to communicate messages in a computer network
US8488448B2 (en) System and method for message sequencing in a broadband gateway
CN101207522B (en) Method and apparatus for implementation of collocation task scheduling
EP2047360A2 (en) Configurable document server
US20170085512A1 (en) Generating message envelopes for heterogeneous events
CN101702735A (en) TCP service device and method
US20060168014A1 (en) Highly extendable message filtering daemon for a network appliance
US20220075658A1 (en) Hierarchical scheduler
JP2004531839A (en) Unified messaging with separate media component storage
CN115086250B (en) Network target range distributed flow generation system and method
CN110727507B (en) Message processing method and device, computer equipment and storage medium
CN112084047A (en) Message sending implementation method based on asynchronous thread pool
US20090193095A1 (en) Using message content to group messages
CN113296917B (en) Multi-service system service event subscription scheduling method, electronic device and storage medium
EP2979196B1 (en) System and method for network provisioning
CN110929130B (en) Public security level audit data query method based on distributed scheduling
CN111475315A (en) Server and subscription notification push control and execution method
CN112769639A (en) Method and device for parallel issuing configuration information
CN1320473C (en) Method and apparatus for multicast support
CN116405547A (en) Message pushing method and device, processor, electronic equipment and storage medium
US20050114524A1 (en) System and method for distributed modeling of real time systems

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination