Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered 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 identification of the received message;
step S102: determining a corresponding function realization unit according to the message identifier;
step S103: and calling the function realizing unit to process the message.
For step S101, the message identification may be determined according to the source of the message (which may also be referred to as the data source or the message producer side), i.e. the message identification is a message used to distinguish between different data source productions. There is a unique message identification for each data source. Specifically, the message identifier may be flexibly configured according to the application scenario, for example, may be a character string, a number, or a combination of a character string and a number, which is not limited herein.
In an alternative embodiment, the method further comprises:
Determining attribute information of the message;
Based on the message identification and the attribute information, a message hash table is generated.
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 (come time), and number of message arrivals (count), and may also include message legitimacy (legal). The freight bill is a non-circulation bill issued by a carrier, which proves that the freight contract and the freight are taken over or loaded, carried and air transported by the carrier, and the carrier ensures that the freight is delivered to a designated receiver, and the freight bill number is a unique identification code of the freight bill and is usually composed of numbers and letters. Each attribute has an attribute value, e.g., CREATE TIME for a message has a value of "2018-1-2," indicating that the message was created on 2018, 1, 2.
The Hash table (also called a Hash table) is a data structure that is directly accessed according to a key value (key value), and it accesses a record by mapping the key value to a location in the table, so as to speed up the search. This mapping function is called a hash function and the array storing the records is called a hash table.
The hash table may be cached in a database (e.g., redis database) to facilitate subsequent queries and analysis. As a specific example, as shown in fig. 2, the message identification may be used as a key, and the attribute information as a value. Where true indicates that the message is legitimate and false indicates that the message is not legitimate.
For step S102, in the present embodiment, the message processing procedure is abstracted into a plurality of individual function implementation units, that is, the message processing procedure is split into a plurality of individual function implementation units, each of which implements one message processing function. In practical application, the realized function of the function realizing 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 realizing unit in advance, and when a message is subsequently received, the corresponding function realizing unit can be determined according to the message identifier of the message.
In alternative embodiments, a functional identification (e.g., a string, number, or combination thereof) or number may be utilized to distinguish between different functional implementation units. Furthermore, a map type (map provides a more general element storage method, and a map set class is used for storing element pairs, called a key and a value, wherein each key is mapped to a value) can be constructed by taking a message identifier as a key and a function identifier or a number as a value, so that after the function implementation unit is analyzed, processing logic in the function implementation unit is dynamically loaded, and the purpose that codes of the function implementation unit can be run randomly only once analyzed is achieved.
For step S103, in an alternative embodiment, invoking the function implementing unit to process the message comprises:
Determining semantic keywords in the function implementation unit;
and processing the message according to the semantic keywords and the attribute information.
Specifically, the semantic keywords represent specific logic actions, and when the program analysis tool parses the semantic keywords, the specific logic actions are executed.
As a specific example, the semantic keywords may be as shown in table 1 below:
table 1:
| semantic keywords | Semantic keyword usage scenarios |
| if | Judging |
| comed | For indicating that a message has arrived |
| > | Size comparison |
| < | Size comparison |
| . | Representing attributes of a current message |
| [] | Representing attributes of cached messages |
After the program analysis tool is started, each character of the codes of the function realization unit is read in sequence, notes and blanks are filtered, and the following judgment is made according to semantic keywords of the function realization unit:
1. If the semantic keyword is if, the first character except for the blank is judged to be a left bracket (namely a character "("), and after a plurality of characters, the first character is judged to be a right bracket (namely a character ")"), and if the character string in the bracket does not comprise ">", "<", "=" and "heat, the first character is judged to be a Boolean input, and the first character is analyzed by using a java language reflection technology. The java reflection mechanism is in an operation state, and for any one class, all the attributes and methods of the class can be known; any method and attribute of any object can be called, and the functions of dynamically acquiring information and dynamically calling the object method are called a java language reflection mechanism.
2. If the semantic key is comed, judging whether the message in the database cache has arrived or not, and checking that the current character string mode is as follows: and comed, if the count >0 corresponding to the message identifier of the current list number is obtained from the database, the message in the cache is indicated to come, the true is returned, and otherwise, the false is returned.
3. If the semantic keyword is ">" or "<", judging the character string mode before and after the semantic keyword: message attributes or message identifications message attributes.
4. Reading the content in the symbol "{ }" which is service processing content, and executing a preset early warning function and a preset service operation function by using java reflection analysis.
Specifically, in actual production, network interruption and message backlog both have an effect on 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 the message A1 of the data source a and the message B1 of the data source B are received. As a specific example, the message corresponding to the data source a is identified as waybill _a, and the message corresponding to the data source B is identified as waybill _b, and the code of the first function implementation unit is as follows:
wherein comed is a predefined semantic key that represents that this message has been received. The meaning of this code is: after both messages come, the two messages are processed for the next flow.
For the functions of the first function implementation unit, in the prior art, it is generally required to add message processing logic in the message processing of the data source a and add message processing logic in the message processing of the data source B, so as to cause redundancy of services, while the first function implementation unit of the embodiment of the present invention does not need to add message processing logic in the message processing of the data source a and the data source B, only needs to buffer the first-in message, and processes the message when the later message arrives, so as to avoid redundancy of services.
The second function implementation unit is applied to the situation that the same data source reissues the message, that is, for the same waybill, after receiving the message of the data source C, the message of the data source C is received again. 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:
Wherein, ". 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 code is: and if the creation time of the current message is longer 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 message supplementing operation, that is, for the same waybill, a message of a previous data source is received, for example, in a logistics system, a pick-up message of a certain waybill is received (that is, the waybill is picked up), and a weighing message of the waybill is received (that is, a station operating the waybill performs 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 throwing operation, and" waybill _d.waybillstate= 13 "represents a weighing operation. The meaning of this code is: and if the weighing information is received after the weighing information is put into the process, the weighing information is processed, and the next flow is carried out.
In order to enable the message processing method to seamlessly cut into the message processing system, java annotation can be customized, message identification is assigned to a method for processing business in the processing system as a default value, a message interceptor is developed to intercept the message, and a function realization unit is utilized to process the message. The java annotation is some meta information added in the code and used for analyzing and using some tools in compiling and running, has the functions of explanation and configuration, does not affect the actual logic of the code and only has an auxiliary effect.
According to the message processing method of the embodiment of the invention, corresponding function realizing units are determined according to the message identification of the received message; the technical means of calling the function realizing unit to process the message is adopted, so that the technical problem that the prior art violates the principle of variability in a program is solved, the encapsulation principle of variability in the program is met, the message processing flow is simplified, the development process is simplified, and the technical effects of convenience, rapidness, stability and reliability in message processing are achieved.
In an alternative embodiment, the method further comprises:
generating a message identification chain based on the messages with the same operation list number;
when the message identification chain forms a closed loop, the message identification chain is deleted.
Specifically, whether the message identification chain forms a closed loop or not 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 identification chain formed by message identifications of the N messages is a closed loop, and when the message identification chain forms a closed loop, it indicates that all operations have been completed on a waybill corresponding to the message identification chain. As a specific example, in a logistics system, the business involves bill generation, weighing, distribution, and consignment, and the like, and then a 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, deleting the message identification chain can release the cache space of the database, and the utilization rate of the database is improved.
In an alternative embodiment, the method further comprises:
determining whether the current message is abnormal or not according to the preset sequence of message identification;
If yes, outputting early warning information.
In practical applications, messages generated by multiple data sources have a chronological order. Determining whether the current message is abnormal according to the preset sequence of message identification can comprise:
judging whether the message identification of the currently received message is consistent with the preset sequence of the message identification according to the current message identification chain, and if so, determining that the message is normal; if not, determining that the message is abnormal. When the message is abnormal, early warning information can be sent to the staff in the modes of mail, short message 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, and early warning information is sent to the staff.
Fig. 3 is a schematic diagram of main modules of a message processing apparatus 300 according to an embodiment of the present invention, and as shown in fig. 3, the apparatus 300 includes:
A message identification determining module 301, configured to determine a message identification of a received message;
A function implementation unit determining module 302, configured to determine a corresponding function implementation unit according to the message identifier;
and the message processing module 303 is configured to invoke the function implementation unit to process the message.
Optionally, the message identification determining module 301 is further configured to: the message identification of the message is determined based on the source of the message.
Optionally, the apparatus further includes an attribute information determining module configured to: determining attribute information of the message; based on the message identification and the attribute information, a message hash table is generated.
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 keywords and the attribute information.
Optionally, the attribute information includes at least one of: message creation time, order number, message arrival time, and message arrival times.
Optionally, the apparatus further comprises an identification chain module for: generating a message identification chain based on the messages with the same operation list number; when the message identification chain forms a closed loop, the message identification chain is deleted.
Optionally, the device further comprises an early warning module for: determining whether the current message is abnormal or not according to the preset sequence of message identification; if yes, outputting early warning information.
According to the message processing device provided by the embodiment of the invention, the corresponding function realization units are determined according to the message identification of the received message, so that the message is processed, the technical problem of the rule against the variability in the program in the prior art is solved, the message processing flow is simplified, the development process is simplified, and the message processing is convenient, quick, 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. Technical details not described in detail in this embodiment may be found in the methods provided in the embodiments of the present invention.
Fig. 4 illustrates an exemplary system architecture 400 to which a message processing method or message processing apparatus of an embodiment 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 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc., may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server providing support for shopping-type websites browsed by the user using the terminal devices 401, 402, 403. The background management server can analyze and other processing on the received data such as the product information inquiry request and the like, and feed back processing results (such as target push information and product information) to the terminal equipment.
It should be noted that, the message processing method provided in 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, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501, which 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 required for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other through 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 section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; 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 drive 510 is also connected to the I/O interface 505 as needed. 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 needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to 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 shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this document, 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, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. 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 flowcharts 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 involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, 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 constitute a limitation on the unit itself in some cases, and for example, the transmitting module may also be described as "a module that transmits 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 present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include:
Determining a message identification of the received message;
Determining a corresponding function realization unit according to the message identifier;
And calling the function realizing unit to process the message.
According to the technical scheme of the embodiment of the invention, the corresponding function realization units are determined according to the message identification of the received message, so that the message is processed, the technical problem of the rule against the variability in the program in the prior art is solved, the message processing flow is simplified, the development process is simplified, and the message processing is convenient, quick, stable and reliable.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.