Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, article, or apparatus.
The technical solution of the present invention will be described in detail with specific examples. Several of the following embodiments may be combined with each other and some details of the same or similar concepts or processes may not be repeated in some embodiments.
The embodiment of the application provides a message processing method, which is applied to a message processing scene based on a message queue. The method can reduce the pressure of processing equipment and improve the message processing efficiency.
The message processing system applied in the embodiment of the application comprises: the system comprises a generating device, an MQ server, a processing device and a storage device;
the generating device is used for generating a message, and when the message is generated, the environment identifier configured for the environment is acquired according to the environment where the message is located, and the message carries the environment identifier.
And the messages generated by each generating device are stored in the MQ server through the message queue, and the messages generated by each generating device are sequentially stored in the message queue according to the sequence of the generation.
The message queue is a communication mode between applications, and a message can be returned immediately after being sent, and a message system is provided to ensure reliable delivery of information.
The processing equipment acquires the message needing to be primarily processed by the equipment from the message queue according to a preset rule; and after the message is acquired, only the environment identifier is analyzed and stored in the storage device.
The storage device is used for storing the mapping relation between the message and the environment identifier.
The processing equipment configures an environment identifier and processing logic corresponding to the environment identifier; the message is used for indicating the processing of the message corresponding to the environment identification; when the corresponding environment identifier is processed, starting a timing task aiming at the environment identifier;
here, the timed task is similar to an alarm clock, i.e. the corresponding task is executed at a set time.
The processing logic for different environment identification settings may be the same or different.
The processing equipment monitors whether a timing task corresponding to the configured environment identifier is started or not;
and when the starting of the timing task is monitored, acquiring a message corresponding to the environment identifier in the database of the storage equipment for logic processing.
In the embodiment of the present application, the implementation of the warehousing operation and the logic processing may be implemented by a processing device, or may be implemented by a warehousing device and a logic processing device, respectively.
The following describes in detail a process of implementing message processing in the embodiment of the present application with reference to the drawings.
Example one
Referring to fig. 1, fig. 1 is a schematic view illustrating a message processing flow in a first embodiment of the present application. The method comprises the following specific steps:
step 101, monitoring messages in a message queue according to a preset rule; the preset rules cause each processing device to listen for different messages.
In the embodiment of the application, the preset rule may be that the processing device polls and monitors the messages in the message queue; when polling the message, one message can be polled at a time, or a plurality of messages can be polled; some processing devices may also be selected to poll for messages, which is not limited in this embodiment of the present application.
The preset rule is an example in the embodiment of the present application, and is not limited to the limit of the preset rule.
Here, each message in the message queue carries an environment identifier.
The environment identifier is a unique identifier of the environment where the generating device is located, such as a production environment: pro; pre-foaming environment 1: pre 1; pre-emergence environment 2: pre2, etc.
And 102, when the message is monitored, analyzing the environment identifier carried in the message, and storing the environment identifier and the message in a storage device in a correlation manner.
The step is realized by storing the environment identifier and the message in the storage device in an associated manner, rather than determining whether the environment identifier corresponds to the environment identifier corresponding to the processing device, to determine whether to perform logic processing on the message.
103, when monitoring that the timing task corresponding to the environment identifier configured by the processing device is started, acquiring a message corresponding to the environment identifier in the storage device to perform logic processing.
And monitoring whether a timing task corresponding to the configured environment identifier is started or not, and processing the message corresponding to the environment identifier in the storage equipment when monitoring that the timing task corresponding to the environment identifier configured by the processing equipment is started.
In the embodiment of the application, each processing device monitors the messages in the message queue according to a preset rule, and the preset rule enables each processing device not to repeatedly acquire the messages in the message queue, and after the messages in the message queue are acquired, the message processing is realized by adopting a mode of first falling from a library and then processing. The method can reduce the pressure of processing equipment and improve the message processing efficiency.
Example two
Referring to fig. 2, fig. 2 is a schematic view illustrating a message processing flow in the second embodiment of the present application. The method comprises the following specific steps:
step 201, monitoring messages in a message queue according to a preset rule; the preset rules cause each processing device to listen for different messages.
In the embodiment of the application, the preset rule may be that the processing device polls and monitors the messages in the message queue; when polling the message, one message can be polled at a time, or a plurality of messages can be polled; some processing devices may also be selected to poll for messages, which is not limited in this embodiment of the present application.
The preset rule is an example in the embodiment of the present application, and is not limited to the limit of the preset rule.
Here, each message in the message queue carries an environment identifier.
The environment identifier is a unique identifier of the environment where the generating device is located, such as a production environment: pro; pre-foaming environment 1: pre 1; pre-emergence environment 2: pre2, etc.
Step 202, when a message is monitored, analyzing an environment identifier carried in the message, storing the environment identifier and the message in a storage device in an associated manner, and storing the state of the message in an associated manner as a to-be-processed state and creating time.
Referring to fig. 3, fig. 3 is a schematic diagram of an association relationship for storing a message in a storage device in the embodiment of the present application.
In fig. 3, the message body may be a message with a stripped environment identifier, or may be a received message; the state of the message can use 0 to represent the pending state, 1 to represent the in-process state, and 2 to represent the message processing completion state, and the specific implementation is not limited; the environment identification and the creation time can be described by using specific fields.
The step is realized by storing the environment identifier, the message, the state and the creation time in the storage device in an associated manner, rather than determining whether the environment identifier corresponds to the environment identifier corresponding to the processing device, to determine whether to perform logic processing on the message.
And step 203, monitoring whether a timing task corresponding to the configured environment identifier is started.
And 204, when monitoring that the timing task corresponding to the environment identifier configured by the processing device is started, acquiring the message of which the state corresponding to the environment identifier in the storage device is the to-be-processed state according to the sequence of the creation time, and performing logic processing.
And monitoring whether a timing task corresponding to the configured environment identifier is started or not, and processing the message corresponding to the environment identifier in the storage equipment when monitoring that the timing task corresponding to the environment identifier configured by the processing equipment is started.
Step 205, when the message is acquired for logic processing, updating the state corresponding to the message to a processing state.
Step 206, when the logic processing of the message is completed, updating the state corresponding to the message to a processing completed state.
In the embodiment of the application, each processing device monitors the messages in the message queue according to a preset rule, and the preset rule enables each processing device not to repeatedly acquire the messages in the message queue, after the messages in the message queue are acquired, the message processing is realized by adopting a mode of first database dropping and then processing, and the state of the messages and the database dropping time are maintained in the storage device, so that the messages are reasonably processed according to the state of the messages. The method can reduce the pressure of processing equipment and improve the message processing efficiency.
Based on the same inventive concept, the embodiment of the application also provides a message processing device. Referring to fig. 4, fig. 4 is a schematic structural diagram of a message processing apparatus in the embodiment of the present application. The device comprises: aconfiguration unit 401, afirst listening unit 402, afirst processing unit 403, asecond listening unit 404 and asecond processing unit 405;
aconfiguration unit 401, configured to configure preset rules and timing tasks; wherein the preset rules cause each processing device to listen to different messages;
afirst monitoring unit 402, configured to monitor messages in the message queue according to a preset rule of theconfiguration unit 401;
afirst processing unit 403, configured to, when thefirst monitoring unit 402 monitors a message, parse an environment identifier carried in the message, and store the environment identifier and the message in a storage device in an associated manner;
asecond monitoring unit 404, configured to monitor whether a timing task configured by theconfiguration unit 401 corresponding to the environment identifier configured by the processing device is started;
thesecond processing unit 405 is configured to, when thesecond monitoring unit 404 monitors that the timing task corresponding to the environment identifier configured in the processing device is started, acquire a message corresponding to the environment identifier in the storage device and perform logic processing.
Preferably, the first and second electrodes are formed of a metal,
thefirst processing unit 403, further configured to, when storing the environment identifier in association with the message in the storage device, associate and store a state of the message and a creation time; wherein, the corresponding state of the message is a state to be processed when the message is stored; the creation time is the time stored in the storage device;
thesecond processing unit 405 is specifically configured to, when obtaining the message corresponding to the environment identifier in the storage device for logic processing, obtain the message in the storage device whose state corresponding to the environment identifier is the to-be-processed state according to the sequence of creation time, and perform logic processing.
Preferably, the first and second electrodes are formed of a metal,
asecond processing unit 405, configured to, when the message is acquired to perform logic processing, update a state corresponding to the message in a storage device to a processing state; and when the logic processing of the message is completed, updating the state corresponding to the message into a processing completed state in the storage device.
Preferably, the first and second electrodes are formed of a metal,
theconfiguration unit 401 is further configured to start a corresponding timing task when the configured timing task is due.
The units of the above embodiments may be integrated into one body, or may be separately deployed; may be combined into one unit or further divided into a plurality of sub-units.
In another embodiment, an electronic device is also provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the message processing method when executing the program.
In another embodiment, a computer readable storage medium is also provided, having stored thereon computer instructions, which when executed by a processor, may implement the steps in the message processing method.
Fig. 5 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention. As shown in fig. 5, the electronic device may include: a Processor (Processor)510, a communication Interface (Communications Interface)520, a Memory (Memory)530 and acommunication bus 540, wherein theProcessor 510, thecommunication Interface 520 and theMemory 530 communicate with each other via thecommunication bus 540.Processor 510 may call logic instructions inmemory 530 to perform the following method:
monitoring the messages in the message queue according to a preset rule; the preset rules cause each processing device to monitor different messages;
when a message is monitored, analyzing an environment identifier carried in the message, and storing the environment identifier and the message in a storage device in a correlation manner;
and when monitoring that the timing task corresponding to the environment identifier configured by the processing equipment is started, acquiring a message corresponding to the environment identifier in the storage equipment for logic processing.
Furthermore, the logic instructions in thememory 530 may be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.