Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a message processing method according to an embodiment of the present invention, as shown in fig. 1, the method includes:
step S101: determining a message identifier of a received message;
step S102: determining a corresponding function realization unit according to the message identifier;
step S103: and calling the function implementation unit to process the message.
For step S101, the message identifier may be determined according to the source (also referred to as data source or message producer) of the message, i.e. the message identifier is used to distinguish the messages produced by different data sources. For each data source there is a unique message identification associated with it. Specifically, the message identifier may be flexibly configured according to an application scenario, and may be, for example, a character string, a number, or a combination of a character string and a number, which is not limited herein.
In an optional embodiment, the method further comprises:
determining attribute information of the message;
and generating a message hash table based on the message identification and the attribute information.
As a specific example, the attribute information may be flexibly set according to an application scenario and a service requirement, and may include at least one of the following: message creation time (create time), waybill number (waybill number), message arrival time (com time), and message arrival number (count), and may also include message validity (legacy). The waybill refers to a non-negotiable document issued by a carrier to prove that a cargo transportation contract and cargo are taken over or loaded onto a ship, a vehicle and air by the carrier, and the carrier guarantees that the cargo is handed to a designated receiver, and the waybill number is a unique identification code of the waybill and generally consists of numbers and letters. Each attribute has an attribute value, e.g., the value of the create time of a message is "2018-1-2", which means that the message was created on day 1, month 2 in 2018.
The Hash table (also called Hash table) is a data structure directly accessed according to a key value (key value), and it is used to access a record by mapping the key value to a position in the table, so as to speed up the lookup. This mapping function is called a hash function and the array in which the records are stored is called a hash table.
The hash table may be cached in a database (e.g., a redis database) to facilitate subsequent queries and analysis. As a specific example, as shown in fig. 2, the message identifier may be used as a key and the attribute information may be used as a value. Where true indicates that the message is legitimate and false indicates that the message is illegitimate.
For step S102, in this embodiment, the message processing procedure is abstracted into a plurality of separate function implementation units, that is, the message processing program is split into a plurality of separate function implementation units, and each function implementation unit implements a message processing function. In practical application, the implemented function of the function implementing unit has a specific relation with the data source, so that the message identifier determined according to the data source can be associated with the function implementing unit in advance, and when a message is received subsequently, the corresponding function implementing unit can be determined according to the message identifier of the message.
In alternative embodiments, function identifiers (e.g., strings, numbers, or combinations thereof) or numbers may be used to distinguish between different function implementing units. Further, the message identifier may be used as a key, the function identifier or the number may be used as a value, a map type may be constructed (a map provides a more general element storage method, a map set class is used to store element pairs, which are called as a "key" and a "value", where each key is mapped to a value) to be used for subsequently and rapidly invoking the function implementation unit, after the function implementation unit completes parsing, the dynamic bedstead processing class dynamically loads the processing logic in the function implementation unit, and the purpose that the code of the function implementation unit can be arbitrarily run only once parsed is achieved.
For step S103, in an optional embodiment, invoking the function implementation unit to process the message includes:
determining semantic keywords in the function implementation unit;
and processing the message according to the semantic keyword and the attribute information.
Specifically, the semantic keywords represent specific logical actions, and after the program analysis tool parses the semantic keywords, the specific logical actions are executed.
As a specific example, the semantic keyword may be as shown in table 1 below:
table 1:
| semantic keywords | Semantic keyword usage scenarios |
| if | Judgment of |
| comed | For indicating that a message has come |
| > | Size comparison |
| < | Size comparison |
| . | Attributes representing a current message |
| [] | Attributes representing cached messages |
After a program analysis tool is started, reading each character of the code of the function realization unit in sequence, filtering out comments and blanks, and judging according to semantic keywords of the function realization unit as follows:
1. if the semantic keyword is if, the first character except the empty lattice at the back is judged to be a left bracket (namely a character "("), and a character right bracket (namely a character ")" is arranged after a plurality of characters), if the character string in the bracket does not comprise ">", "<", "═ and &" and the like, the input is judged to be Boolean type input, and the input is analyzed by a java language reflection technology. Wherein, the java reflection mechanism is in a running state, and all attributes and methods of any class can be known; for any object, any method and attribute thereof can be called, and the function of dynamically acquiring information and dynamically calling the object method is called as a reflection mechanism of java language.
2. If the semantic keyword is combed, judging whether the message comes in the database cache, and checking that the current character string mode is as follows: and combed, if the count >0 corresponding to the message identifier of the current waybill number is obtained from the database, the message in the cache comes, and true is returned, otherwise false is returned.
3. If the semantic keyword is ">" or "<", judging the front and back character string modes of the semantic keyword: message attribute or message identification [ message attribute ].
4. Reading the content in the symbol "{ }", wherein the content is service processing content, and performing analysis on a preset early warning function and a preset service operation function by using java reflection.
Specifically, in actual production, the interruption of the network and the backlog of the message both affect the arrival time of the message, but the production time of the message is determined, so three message function implementation units can be set:
the first function implementation unit is applied to the case that the service determination requires the support of the messages of two data sources, for example, for the same waybill, the processing of the related service can be performed only after receiving the message a1 of the data source a and the message B1 of the data source B. As a specific example, the message identifier corresponding to the data source a is waybill _ a, and the message identifier corresponding to the data source B is waybill _ B, then the code of the first function implementation unit is as follows:
where, quote is a predefined semantic keyword that represents that the message has been received. The meaning of this piece of code is: and after the two messages arrive, processing the two messages and carrying out the next flow.
For the function of the first function implementation unit, in the prior art, it is usually necessary to add a message processing logic in the message processing of the data source a and a message processing logic in the message processing of the data source B, so as to cause service redundancy.
The second function implementation unit is applied to the case of reissuing a message from the same data source, that is, for the same waybill, after receiving the message from the data source C, the second function implementation unit receives the message from the data source C. For example, if the message identifier corresponding to the data source C is waybill _ C, the code of the second function implementation unit is as follows:
where ". createtime" represents the creation time of the current message, "[ createtime ]" represents the creation time of the message that has been stored in the database, the meaning of this piece of code is: and if the creation time of the current message is greater than that of the previous message, processing the current message and carrying out the next flow.
The third function implementing unit is applied to the case of supplementary message operation, that is, for the same waybill, a message of a previous data source is received, for example, in a logistics system, a transfer message of a certain waybill is received (that is, the waybill has completed transfer), and a weighing message of the waybill is received (that is, a certain station operating the waybill has performed weighing operation again). For example, if the message identifier corresponding to the data source D is waybill _ D, the code of the third function implementation unit is as follows:
if(waybill_d.comed&&waybill_d.[waybillstate]==150)
{if(waybill_d.waybillstate==13)
{}
}
where "waybill _ d. [ waybillstate ] ═ 150" represents a pass operation, and "waybill _ d. [ waybillstate ] -. 13" represents a weighing operation. The meaning of this piece of code is: and if the weighing information is properly received, processing the weighing information and carrying out the next process.
In order to enable the message processing method of the embodiment of the invention to be seamlessly switched into the message processing system, java annotation can be customized, the message identifier is used as a default value to be assigned to a method for processing services in the processing system, a message interceptor is developed to intercept messages, and the messages are processed by utilizing the function implementation unit. The java annotation is some meta-information attached to the code, is used for some tools to perform parsing and use during compiling and running, plays a role in description and configuration, and the annotation does not influence the actual logic of the code and only plays an auxiliary role.
The message processing method of the embodiment of the invention determines the corresponding function realization unit according to the message identification of the received message; the technical means for processing the message by calling the function implementation unit overcomes the technical problem that the prior art violates the principle of variability in the program, thereby achieving the technical effects of conforming to the principle of variability packaging in the program, simplifying the message processing flow, simplifying the development process and enabling the message processing to be convenient, rapid, stable and reliable.
In an optional embodiment, the method further comprises:
generating a message identification chain based on the messages with the same waybill number;
and when the message identification chain forms a closed loop, deleting the message identification chain.
Specifically, the determination of whether the message identifier chain forms a closed loop may be flexibly set according to an application scenario, for example, N data sources (N is an integer greater than or equal to 1) are involved in a certain service, when messages of all the data sources are received, that is, when N messages are received, the message identifier chain formed by the message identifiers of the N messages is a closed loop, and when the message identifier chain forms a closed loop, it indicates that the waybill corresponding to the message identifier chain has completed all operations. As a specific example, in a logistics system, the business involves waybill generation, weighing, distribution, and due delivery, etc., and the message identification chain generated by the messages generated by the above operations is a closed loop.
When the message identification chain forms a closed loop, the cache space of the database can be released by deleting the message identification chain, and the utilization rate of the database is improved.
In an optional embodiment, the method further comprises:
determining whether the current message is abnormal or not according to the preset sequence of the message identifiers;
if yes, outputting early warning information.
In practical application, messages generated by a plurality of data sources have a chronological order. Determining whether the current message is abnormal according to a preset sequence of message identifiers may include:
judging whether the sequence of the message identifier of the currently received message is consistent with the preset sequence of the message identifier or not according to the current message identifier chain, and if so, determining that the message is normal; and if the message is inconsistent, determining that the message is abnormal. When the message is abnormal, the early warning information can be sent to the staff in the modes of mails, short messages and the like. As a specific example, an early warning function may be set in the function implementation unit, and once the message is found to be abnormal, the early warning function is called to send early warning information to the staff.
Fig. 3 is a schematic diagram of main blocks of a message processing apparatus 300 according to an embodiment of the present invention, as shown in fig. 3, the apparatus 300 including:
a message identifier determining module 301, configured to determine a message identifier of a received message;
a function implementation unit determining module 302, configured to determine a corresponding function implementation unit according to the message identifier;
a message processing module 303, configured to invoke the function implementation unit to process the message.
Optionally, the message identifier determining module 301 is further configured to: and determining the message identification of the message according to the source of the message.
Optionally, the apparatus further includes an attribute information determination module, configured to: determining attribute information of the message; and generating a message hash table based on the message identification and the attribute information.
Optionally, the message processing module 303 is further configured to: determining semantic keywords in the function implementation unit; and processing the message according to the semantic keyword and the attribute information.
Optionally, the attribute information includes at least one of: message creation time, waybill number, message arrival time, and message arrival times.
Optionally, the apparatus further comprises an identification chain module configured to: generating a message identification chain based on the messages with the same waybill number; and when the message identification chain forms a closed loop, deleting the message identification chain.
Optionally, the apparatus further comprises an early warning module configured to: determining whether the current message is abnormal or not according to the preset sequence of the message identifiers; if yes, outputting early warning information.
The message processing device of the embodiment of the invention determines the corresponding function implementation unit according to the message identifier of the received message, thereby processing the message, overcoming the technical problem of the prior art that the principle of resisting the variability in the program is violated, simplifying the message processing flow, simplifying the development process, and enabling the message processing to be convenient, rapid, stable and reliable.
The device can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
Fig. 4 shows an exemplary system architecture 400 to which the message processing method or the message processing apparatus of the embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that the message processing method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the message processing apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not in some cases constitute a limitation on the unit itself, and for example, the sending module may also be described as a "module that sends a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
determining a message identifier of a received message;
determining a corresponding function realization unit according to the message identifier;
and calling the function implementation unit to process the message.
According to the technical scheme of the embodiment of the invention, the corresponding function implementation unit is determined according to the message identifier of the received message, so that the message is processed, the technical problem that the prior art violates the principle of variability in a program is solved, the message processing flow is simplified, the development process is simplified, and the message processing is convenient, rapid, stable and reliable.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.