CN107317742B - Message processing method and system, computer readable storage medium - Google Patents
Message processing method and system, computer readable storage medium Download PDFInfo
- Publication number
- CN107317742B CN107317742B CN201610533589.0A CN201610533589A CN107317742B CN 107317742 B CN107317742 B CN 107317742B CN 201610533589 A CN201610533589 A CN 201610533589A CN 107317742 B CN107317742 B CN 107317742B
- Authority
- CN
- China
- Prior art keywords
- message
- general
- processing
- type
- processor
- 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.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/06—Message adaptation to terminal or network requirements
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/06—Message adaptation to terminal or network requirements
- H04L51/066—Format adaptation, e.g. format conversion or compression
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/21—Monitoring or handling of messages
- H04L51/226—Delivery according to priorities
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention provides a message processing method and a system, the method comprises the steps of firstly converting a message to be sent at a sending end to obtain a universal message, then sending the universal message to a receiving end, and finally selecting a message processor on a message processing chain to process message contents according to the message type in the universal message. The invention converts different types of messages into general messages without designing a complete processing process for each message, thereby avoiding the function repetition and reducing the code redundancy; in addition, when a new message type appears, a message processor can be added to a message processing chain to process the general message of the type, so that the message processing chain has good expansibility.
Description
Technical Field
The present invention relates to the field of computers, and in particular, to a message processing method and system, a computer system, and a computer-readable storage medium.
Background
A Message Queue (MQ) is a method of communicating applications to applications. Since the message queue provides a loosely coupled connection method for application integration through message communication, the use is frequent in the system architecture.
In the actual operation process of the system, the situation that a plurality of people develop a plurality of messages often exists, a plurality of universal places exist in each message processing, on the other hand, the message processing lacks uniform planning, and the later maintenance is difficult.
As shown in fig. 1, in the message processing method in the prior art, a complete processing procedure needs to be designed for each message (message a and message B), such as steps of message acquisition, data verification, log recording, and the like, which results in multiple repeated functions and redundant codes, and meanwhile, the message processing flow is not controlled, the difference is large, the maintainability is poor, and in addition, multiple functions need to be implemented for newly adding a message, and the expansibility is poor.
Disclosure of Invention
Technical problem to be solved
The invention aims to provide a message processing method and a message processing system, which can uniformly process different types of messages and have good expansibility.
(II) technical scheme
The invention provides a message processing method, which is used for processing a message sent from a sending end to a receiving end, and comprises the following steps:
s1, converting a message to be sent by a sending end to obtain a general message, wherein the general message comprises the message content and the message type of the message to be sent;
s2, sending the general message to a receiving end;
and S3, processing the message content in the general message according to the message type in the general message.
The invention also provides a message processing system for processing the message sent from a sending end to a receiving end, the system includes:
the message conversion unit is used for converting a message to be sent by a sending end to obtain a general message, wherein the general message comprises the message content and the message type of the message to be sent;
the message sending unit is used for sending the general message to the receiving end;
and the message processing unit is used for processing the message content in the general message according to the message type in the general message.
The present invention also provides a computer system comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to perform the message processing method as described above based on instructions stored in the memory.
The present invention also provides a computer readable storage medium storing computer instructions which, when executed by a processor, implement a message processing method as described above.
(III) advantageous effects
The invention converts different types of messages into general messages without designing a complete processing process for each message, thereby avoiding the function repetition and reducing the code redundancy; in addition, when a new message type appears, a message processor can be added to a message processing chain to process the general message of the type, so that the message processing chain has good expansibility.
Drawings
Fig. 1 is a flow chart of a prior art message processing method.
Fig. 2 is a flowchart of a message processing method provided by the present invention.
Fig. 3 is a flow diagram illustrating message processing by which an embodiment of the invention may be practiced.
Fig. 4 is a schematic diagram of message conversion in an embodiment of the invention.
Fig. 5 is a diagram illustrating conversion of serialized data into a generic message in an embodiment of the invention.
Fig. 6 is a flow diagram of processing a generic message in an embodiment of the invention.
Detailed Description
The invention provides a message processing method and a system, the method comprises the steps of firstly converting a message to be sent at a sending end to obtain a universal message, then sending the universal message to a receiving end, and finally selecting a message processor on a message processing chain to process message contents according to the message type in the universal message. The invention converts different types of messages into general messages without designing a complete processing process for each message, thereby avoiding the function repetition and reducing the code redundancy; in addition, when a new message type appears, a message processor can be added to a message processing chain to process the general message of the type, so that the message processing chain has good expansibility.
Fig. 2 is a flowchart of a message processing method provided by the present invention, and as shown in fig. 2, the message processing method includes:
s1, converting a message to be sent by a sending end to obtain a general message, wherein the general message comprises the message content and the message type of the message to be sent; the sending end and the receiving end communicate in a message mode, and the sending end and the receiving end can be a client and a server. When a message is converted, a generic message object may be created that has multiple members, i.e., message content and message type.
S2, sending the general message to a receiving end;
and S3, processing the message content in the general message according to the message type in the general message.
In order to facilitate the storage of the message according to an embodiment of the present invention, step S1 further includes: the general message is serialized to obtain serialized data of the general message, wherein the serialized data can be JSON data, XML data, binary data and the like, and the serialized data is stored in a message queue, the general message is stored in the message queue in the form of the serialized data because the message needs to be transmitted and understood between heterogeneous systems, the message queue can provide message caching capacity, and when the message is sent in step S2, the serialized data in the message queue is firstly sent to a receiving end, and the serialized data is subjected to deserialization in the receiving end to obtain the corresponding general message.
According to an embodiment of the present invention, before the step S3 processes the message, the method further includes: and performing data verification and log recording on the general message, wherein the data verification and the log recording are used for ensuring the integrity and the validity of the message and analyzing various characteristics of message processing.
According to an embodiment of the present invention, step S3 includes: according to the message type in the general message, a message processor corresponding to the message type is selected to process the message content in the general message, wherein the message processor is an abstract logic unit in a framework and used for analyzing the message and processing the message, the message processor of the specific type is specified to process the message of the specific type, and the message processor can be realized by inheriting the JAVA subclass of the abstract processor.
According to one embodiment of the invention, a plurality of message processors corresponding to different message types are linearly stored in a message processing chain, and the message processors corresponding to the message types are acquired by traversing the message processors in the message processing chain, wherein the message processing chain can be realized by a responsibility chain design mode.
According to an embodiment of the present invention, the general message further includes redundant information, where the redundant information may be a sender IP, a sender name, a sending time, and the like, and in step S3, if there is no message processor corresponding to the message type, the general message is backed up according to the redundant information of the general message, and the backup is to restore the unprocessed message so as to reprocess the unprocessed message.
According to one embodiment of the invention, after the backup of the general message is carried out, the message processor corresponding to the message type in the general message is added to the message processing chain, so that the new type of message can be processed only by adding the message processor, and the method has good expansibility.
The present invention also provides a message processing system, including:
the message conversion unit is used for converting a message to be sent by a sending end to obtain a general message, wherein the general message comprises the message content and the message type of the message to be sent;
the message sending unit is used for sending the general message to the receiving end;
and the message processing unit is used for processing the message content in the general message according to the message type in the general message.
According to an embodiment of the present invention, the message conversion unit performs a serialization process on the general message to obtain a serialization data of the general message, and stores the serialization data in a message queue.
According to an embodiment of the present invention, the message sending unit sends the serialized data in the message queue to the receiving end, and performs deserialization processing on the serialized data to obtain the corresponding general message.
According to an embodiment of the present invention, the message processing system further includes: the data verification unit is used for performing data verification on the general message; and the log recording unit is used for performing log recording on the general message.
According to one embodiment of the present invention, the message processing unit selects a message processor corresponding to the message type according to the message type in the general message, so as to process the message content in the general message.
According to one embodiment of the invention, a plurality of message processors corresponding to different message types are stored linearly on a message processing chain, and the message processors corresponding to the message types are acquired by traversing the message processors on the message processing chain.
According to an embodiment of the present invention, the general message further includes redundant information, and the message processing unit backs up the general message according to the redundant information of the general message when there is no message processor corresponding to the message type.
According to one embodiment of the invention, after the message processing unit backs up the general message, a message processor corresponding to the message type in the general message is added to the message processing chain.
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to specific embodiments and the accompanying drawings.
Fig. 3 is a schematic flow chart of message processing according to an embodiment of the present invention, and as shown in fig. 3, when a client (a sending end) sends multiple different types of messages (a message a and a message B) to a server (a receiving end), it is only necessary to convert the message a and the message B into a unified general message and send the unified general message to the server without designing a complete processing procedure for each message, and the server verifies and logs the general message and then selects different message processors to process the general message.
Fig. 4 is a schematic diagram of message conversion in an embodiment of the present invention, as shown in fig. 4, when a client (a sending end) sends a message to a server (a receiving end), the message to be sent is encapsulated into a general message, where the general message includes a message type, a message content, and redundant information of the message to be sent, the redundant information includes a client IP, a client name, sending time, and the like, and then the general message is serialized to obtain serialized data in a JSON/XML/binary form, and the serialized data is stored in a message queue.
Fig. 5 is a schematic diagram of converting serialized data into a general message in the embodiment of the present invention, and as shown in fig. 5, when a general message is sent to a server, a message queue first sends the stored serialized data to the server, and the server performs deserialization on the serialized data to obtain a corresponding general message. After obtaining the general message, the server performs corresponding processing on the general message, such as data verification and log recording, and then performs message processing.
Fig. 6 is a flowchart of processing a general message in the embodiment of the present invention, where, as shown in fig. 6, a plurality of message processors are mounted on a message processing chain, and the general message traverses each message processor in turn on the message processing chain according to its own message type until a corresponding message processor is found, a message processor a and a message processor B are shown in fig. 6, which respectively correspond to processing the message a and the message B shown in fig. 3. In addition, if there is a new message C to be processed, only one message processor C needs to be added to the message processing chain, so that the new message processor C does not affect the previous message processor a and message processor B at all. As also shown in fig. 6, if a message does not have a corresponding message handler in the message handling chain, the message is backed up.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the present invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (16)
1. A message processing method for processing a message sent from a sender to a receiver, the method comprising:
s1, converting the message to be sent from the sending end to obtain a general message, wherein the general message comprises the message content and the message type of the message to be sent;
s2, sending the general message to the receiving end;
s3, processing the message content in the general message according to the message type in the general message; the step S3 includes: selecting a message processor corresponding to the message type according to the message type in the general message so as to process the message content in the general message; and if the message processor corresponding to the message type does not exist, adding the message processor corresponding to the message type in the general message.
2. The message processing method according to claim 1, wherein the step S1 further comprises: and carrying out serialization processing on the general message to obtain serialization data of the general message, and storing the serialization data in a message queue.
3. The message processing method according to claim 2, wherein the step S2 includes: and sending the serialized data in the message queue to the receiving end, and performing deserialization processing on the serialized data to obtain a corresponding universal message.
4. The message processing method according to claim 1, wherein the step S3 is preceded by: and performing data verification and log recording on the general message.
5. The message processing method according to claim 1, wherein a plurality of message handlers corresponding to different message types are stored linearly in a message processing chain, and the message handler corresponding to the message type is obtained by traversing the message handlers in the message processing chain.
6. The message processing method according to claim 5, wherein the general message further includes redundant information, and in step S3, if there is no message handler corresponding to the message type, the general message is backed up according to the redundant information of the general message.
7. The message processing method according to claim 6, wherein after the backup of the general message, a message processor corresponding to a message type in the general message is added to the message processing chain.
8. A message processing system for processing a message sent from a sender to a receiver, the system comprising:
a message conversion unit, configured to convert a message to be sent by the sending end to obtain a general message, where the general message includes a message content and a message type of the message to be sent;
the message sending unit is used for sending the general message to the receiving end;
the message processing unit is used for processing the message content in the general message according to the message type in the general message; the message processing unit selects a message processor corresponding to the message type according to the message type in the general message so as to process the message content in the general message; and when the message processor corresponding to the message type does not exist, the message processing unit adds the message processor corresponding to the message type in the general message.
9. The message processing system of claim 8, wherein the message transformation unit serializes the generic message to obtain serialized data of the generic message, and stores the serialized data in a message queue.
10. The message processing system according to claim 9, wherein the message sending unit sends the serialized data in the message queue to the receiving end, and performs deserialization processing on the serialized data to obtain a corresponding general message.
11. The message processing system of claim 8, further comprising:
the data verification unit is used for performing data verification on the general message;
and the log recording unit is used for performing log recording on the general message.
12. The message processing system of claim 8, wherein a plurality of message processors corresponding to different message types are stored linearly in a message processing chain, and the message processor corresponding to the message type is obtained by traversing the message processors in the message processing chain.
13. The message processing system according to claim 12, wherein the general message further includes redundant information, and the message processing unit backs up the general message according to the redundant information of the general message when there is no message processor corresponding to the message type.
14. The message processing system according to claim 13, wherein the message processing unit adds a message handler corresponding to a message type in the general message to the message processing chain after backing up the general message.
15. A computer system, comprising:
a memory; and
a processor coupled to the memory, wherein the processor is configured to perform the message processing method of any of claims 1 to 7 based on instructions stored in the memory.
16. A computer-readable storage medium storing computer instructions which, when executed by a processor, implement the message processing method of any one of claims 1 to 7.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610269606 | 2016-04-27 | ||
CN2016102696064 | 2016-04-27 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107317742A CN107317742A (en) | 2017-11-03 |
CN107317742B true CN107317742B (en) | 2020-08-14 |
Family
ID=60184466
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610533589.0A Active CN107317742B (en) | 2016-04-27 | 2016-07-07 | Message processing method and system, computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107317742B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110147285A (en) * | 2018-02-13 | 2019-08-20 | 北京京东尚科信息技术有限公司 | Message treatment method and device based on message queue |
CN110674004A (en) * | 2019-08-28 | 2020-01-10 | 北京奇艺世纪科技有限公司 | Queue message recording method, system, electronic equipment and storage medium |
CN112395114B (en) * | 2020-12-07 | 2021-05-07 | 震坤行网络技术(南京)有限公司 | Method, computing device, and computer-readable storage medium for processing messages |
CN113434311B (en) * | 2021-06-28 | 2023-01-31 | 平安科技(深圳)有限公司 | Service data interaction method, device, equipment and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103077246A (en) * | 2013-01-18 | 2013-05-01 | 国网电力科学研究院 | Netty-based large screen visualization platform data push system |
CN103905521A (en) * | 2012-12-31 | 2014-07-02 | 中国移动通信集团公司 | Information processing system and method for network service |
CN104462121A (en) * | 2013-09-18 | 2015-03-25 | 腾讯科技(深圳)有限公司 | Data processing method, device and system |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8364745B2 (en) * | 2009-11-24 | 2013-01-29 | International Business Machines Corporation | Service oriented architecture enterprise service bus with universal ports |
-
2016
- 2016-07-07 CN CN201610533589.0A patent/CN107317742B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103905521A (en) * | 2012-12-31 | 2014-07-02 | 中国移动通信集团公司 | Information processing system and method for network service |
CN103077246A (en) * | 2013-01-18 | 2013-05-01 | 国网电力科学研究院 | Netty-based large screen visualization platform data push system |
CN104462121A (en) * | 2013-09-18 | 2015-03-25 | 腾讯科技(深圳)有限公司 | Data processing method, device and system |
Also Published As
Publication number | Publication date |
---|---|
CN107317742A (en) | 2017-11-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107317742B (en) | Message processing method and system, computer readable storage medium | |
US9454589B2 (en) | Providing messages for a Java message service | |
CN110943911B (en) | High-efficiency data transmission method for Internet of things based on protobuf | |
CN111124653A (en) | Delayed message processing method, system, device and storage medium | |
CN113900810A (en) | Distributed graph processing method, system and storage medium | |
CN111371898B (en) | Message monitoring method, device, equipment and storage medium | |
CN103297453A (en) | Method, browser end and system for achieving instant communication | |
CN111897662A (en) | Offset processing method and device, electronic equipment and computer readable storage medium | |
US10938633B2 (en) | Facilitating resilient and fault tolerant asynchronous messaging | |
CN105607606B (en) | A kind of data acquisition device and method based on double mainboard frameworks | |
US8387070B2 (en) | Object request broker | |
CN113297163B (en) | Inquiry transfer system, method, device, equipment and medium based on block chain | |
CN113014618A (en) | Message processing method and system and electronic equipment | |
US8752071B2 (en) | Identifying subscriber data while processing publisher event in transaction | |
CN103997509A (en) | Service oriented architecture-based service processing method and apparatus | |
CN107688978B (en) | Method and device for detecting repeated order information | |
CN111190607B (en) | Task plugin processing method and device, task scheduling server and storage medium | |
US20160162559A1 (en) | System and method for providing instant query | |
US20120124234A1 (en) | Reliable message transfer | |
US11650963B2 (en) | Storing serialized structured data generically in a standardized serialized data structure | |
CN111917572B (en) | Transaction request processing method and device, electronic equipment and readable storage medium | |
KR101739825B1 (en) | Data processing system and computer readable recording medium applying the same | |
CN114064391A (en) | Distributed alarm or event information processing method and device | |
KR101739829B1 (en) | Data processing method and computer readable recording medium applying the same | |
Albassam et al. | Variable recovery and adaptation connectors for dynamic software product lines |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |