Specific embodiment
To keep the purposes, technical schemes and advantages of the embodiment of the present application clearer, below in conjunction with the embodiment of the present application
In attached drawing, the technical scheme in the embodiment of the application is clearly and completely described, it is clear that described embodiment is
Some embodiments of the present application, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art
Every other embodiment obtained without making creative work, shall fall in the protection scope of this application.
To be further explained below in conjunction with attached drawing with specific embodiment convenient for the understanding to the embodiment of the present application
Bright, embodiment does not constitute the restriction to the embodiment of the present application.
Fig. 1 is that service message provided by the embodiments of the present application sends system architecture schematic diagram, includes database in the system
Server 101, operation system 102, service message sending device 103 and configuration center 104, wherein database server 101
Service is provided for the application of operation system 102, above-mentioned service is specifically as follows insertion, update, inquiry or deletes service, Ke Yitong
It crosses SQL statement and executes corresponding operation to realize above-mentioned service, operation system 102 can be for one or multiple, in Fig. 1
The number of operation system 102 is merely illustrative, and not as the restriction to it, it is matching for operation system 102 according to configuration center 104
Corresponding service message can be sent to operation system by the title of the class for the service message set, service message sending device 103
102.In the embodiment of the present application, the operation information of database will can be recorded in database journal, be specifically as follows
Binlog database journal periodically parses Binlog database journal by Binlog resolver, generates databases comparison event,
Databases comparison event includes aforesaid operations information, it is subsequent can be according to aforesaid operations information structuring service message.It is above-mentioned
Binlog database journal and Binlog resolver can integrate in service message sending device 103.
Fig. 2 is the service message sending method flow chart that the embodiment of the present application one provides, and the executing subject of the method can
Think the special equipment for executing the method, or the existing network equipment, for example, database server, such as Fig. 2 institute
Show, the method specifically includes:
Step 201, the operation information of database will be recorded in database journal, the database includes the first table
Lattice.
Wherein, described to be recorded in database journal to the operation information of database, the database includes the first table
Lattice can specifically include: when the first field in the first table to database carries out the first operation, obtain to database
Operation information, the operation information include the title of first table, the action name of first operation, described the
The field values of the field name of one field and first field;The operation information is recorded in Binlog database journal
In.
Step 202, the database journal is parsed, databases comparison event is generated, the databases comparison event includes
The operation information includes the title of first table in the operation information.
Wherein, the parsing database journal, generates databases comparison event, can specifically include: is pre- when reaching
If when the moment, parsing the database journal, databases comparison event is generated.
Step 203, when the title of the title of first table and the second table for operation system configuration
When identical, the databases comparison event is monitored.
It is wherein, described when the title of first table is identical as the title of the second table configured for operation system,
The databases comparison event is monitored, can specifically include: when title and for operation system configuration of first table
When the title of two tables is identical or part is identical, the databases comparison event is monitored.
Step 204, the operation information is extracted from the databases comparison event, and constructs service message.
Wherein, described to extract the operation information from the databases comparison event, and service message is constructed, specifically may be used
When including: that the action name operated when described first is identical as the action name that second configured for operation system operates, from
The operation information is extracted in the databases comparison event;The field of first field is filtered out from the operation information
Numerical value;The title of class is parsed according to the title of first table;Utilize the field of first field filtered out
Numerical value fills the attribute of the class, to construct business model;The action name and the business mould that described first is operated
Type is assembled into service message.
In the embodiment of the present application, it is described first operation or second operation can specifically include: insertion operation, update operation,
Inquiry operation or delete operation.
Step 205, the service message is sent to the operation system, to the operation system according to the business
Message statistics business change situation.
Wherein, described that the service message is sent to the operation system, it can specifically include: according to for the business
The service message is sent to the operation system by the title of the class of system configuration.
In service message sending method provided by the present application, database journal will be recorded in the operation information of database
In, by parsing database journal, databases comparison event is generated, when the list name for the first table for including in database journal
When with being referred to as that the title of the second table of operation system configuration is identical, monitored data library altering event, from databases comparison
Extraction operation information in event, and service message is constructed, service message is sent to operation system, to operation system according to industry
Business message statistics business change situation.Therefore the embodiment of the present application is recorded by the operation information to database, from
And monitored data library is changed, and can more accurately confirm generation databases comparison, also, since database generally includes multiple tables
According to title come monitored data library altering event more targetedly correspondingly, transmission business can be improved in lattice
The accuracy of message.
Service message sending method is introduced in more detail below by the embodiment of the present application two.
Fig. 3 is the service message sending method flow chart that the embodiment of the present application two provides, and the executing subject of the method can
Think the special equipment for executing the method, or the existing network equipment, for example, database server, such as Fig. 3 institute
Show, the method specifically includes:
Step 301, it when the first field in the first table to database carries out the first operation, obtains to database
Operation information.
The operation information includes the title of first table, the action name of first operation, described the
The field values of the field name of one field and first field.
Step 302, the operation information is recorded in Binlog database journal.
For example, needing user to first pass through operation layer construction number when user is inserted into (insert) operation to database
According to, will relevant operation to above-mentioned insertion operation is recorded in Binlog database journal then by insertion of data into data library
Information.Physical record form can use following sentence:
Insert into goods(goods_type,price)values("clothes",50.0);
Wherein, Insert is the action name of the first operation;Goods is the title of the first table;goods_type
It is the field name of the first field with price;Clothes and 50.0 is the field values of the first field.
Step 303, when reaching predetermined time, the database journal is parsed, generates databases comparison event.
The databases comparison event includes the operation information, includes the table of first table in the operation information
Lattice title.
In the embodiment of the present application, can not real time parsing database journal parse the data when reaching predetermined time
Library log, to save system processing resources.
Binlog database journal can specifically be parsed by Binlog resolver, to parse Binlog number
According to the operation information of library log recording, and the databases comparison event including the operation information is generated, passes through monitoring data library
Altering event can know the title, field name and field values of the table changed in database.
Step 304, when the title of the title of first table and the second table for operation system configuration
When identical or part is identical, the databases comparison event is monitored.
Since database generally includes multiple tables, database altering event can be supervised by title
It listens.Also, the capacity of every table is limited, so a point table point library is often occurred that, according to title to data
It includes: to divide table corresponding databases comparison the corresponding table of the title and the table that library altering event, which monitor,
Event is monitored.For example, when title be goods table exist divide table when, then can by regular expression come
It is monitored, concrete form can be " goods-.* ", can thus listen to all goods tables and its divide table corresponding
Databases comparison event.
Step 305, the action name and the action name of the second operation for operation system configuration when first operation
When identical, the operation information is extracted from the databases comparison event.
Since operation system is not usually database caused by all operations (action) carried out to user to database
Change it is interested, it is and only interested in databases comparison caused by one of or several operations, therefore can be business system
The action name under unified central planning for setting the second operation, specifically can be in operation system reservation business message, by the second operation of user's selection
Action name, i.e., selection user for which operation it is interested, mentioned from the databases comparison event according to action name
The operation information is taken, the operation information extracted can be made more accurate, correspondingly, be sent to the service message of operation system more
It is accurate to add.
Step 306, the field values of first field are filtered out from the operation information.
It after the field values for filtering out the first field, can be stored with Map type, for example, form shown in table one.
Table one
The type of merchandise |
Book |
Price (unit: member) |
40 |
Step 307, the title of class is parsed according to the title of first table;Utilize described first filtered out
The field values of field fill the attribute of the class, to construct business model.
Corresponding class is configured for operation system in advance, each class corresponds to a kind of business model, and business model is made of attribute,
Business model specifically can be as shown in Table 2.
Table two
Wherein, commodity are the title of class, and the type of merchandise and price are the attribute of class, and the type of merchandise is String type variable,
Price is double type variable.
When constructing business model, higher customization can be carried out with script, specifically may be implemented by script following
Treatment process: first parsing the title of class (class) according to the title of the first table, for example, when saying when the first table
When title is goods, according to preset rules, the title goods of class is parsed, is then filtered according to step 306
Field values out, field values storage form here are Map, fill the attribute inside business model, such as can be simple
With the field values of goodstype go filling Goods class inside goodsType attribute, with being filled for price
Price inside Goods class, to realize that height, can be more flexible to business system with property and customization by script
System sends service message, to meet the needs of operation system.
Step 308, the action name that described first operates is assembled into service message with the business model.
In the embodiment of the present application, it is described first operation or second operation can specifically include: insertion operation, update operation,
Inquiry operation or delete operation.
Step 309, according to the title of the class configured for the operation system, the service message is sent to the business
System.
The service message can be sent according to the title of the class configured for the operation system in the embodiment of the present application
It according to the title for being the class that the operation system configures and can also be the business system further to the operation system
The service message is sent to the operation system by the action name under unified central planning set.Wherein, the title of class must have, behaviour
It is that optionally, when operation system subscribing service message, the change that can choose to which class is interesting as title, can also selects
It selects and is interested in which operation, default is that operation system is all interesting to all operations.
By above-mentioned treatment process it is found that in the service message sending method that the embodiment of the present application two provides, according to list name
Title listen to databases comparison event after, can also according to action name from databases comparison event extraction operation information, into
One step improves the accuracy for sending service message.
Accordingly with above-mentioned service message sending method, it sends and fills the embodiment of the present application also provides a kind of service message
It sets, is illustrated in figure 4 service message sending device structure chart provided by the embodiments of the present application, the service message sending device packet
It includes: recording unit 401, resolution unit 402, monitoring unit 403, service message structural unit 404 and service message transmission unit
405;
The recording unit 401, for will be recorded in database journal to the operation information of database, the database
Including the first table;
The resolution unit 402 generates database for parsing the 401 recorded data library log of recording unit
Altering event, the databases comparison event include the operation information, include first table in the operation information
Title;
The monitoring unit 403, for when the resolution unit 402 generate databases comparison event in include described in
When the title of first table is identical as the title of the second table configured for operation system, monitors the database and become
More event;
The service message structural unit 404, the databases comparison thing for being listened to from the monitoring unit 403
The operation information is extracted in part, and constructs service message;
The service message transmission unit 405, the business for constructing the service message structural unit 404 disappear
Breath is sent to the operation system, to the operation system according to the service message statistical service alteration.
Preferably, the recording unit 401 specifically includes: obtaining subelement and record subelement;
The acquisition subelement, for obtaining when the first field in the first table to database carries out the first operation
The operation information to database is taken, the operation information includes the behaviour of the title of first table, first operation
Make the field values of title, the field name of first field and first field;
The record subelement, the operation information for obtaining the acquisition subelement are recorded in Binlog data
In the log of library.
Preferably, the resolution unit 402 is specifically used for: when reaching predetermined time, parsing 401 institute of recording unit
The database journal of record generates databases comparison event, and the databases comparison event includes the operation information, the behaviour
Make the title in information including first table.
Preferably, the monitoring unit 403 is specifically used for: when the databases comparison event that the resolution unit 402 generates
In include first table title it is identical with the title of the second table configured for operation system or
When part is identical, the databases comparison event is monitored.
More preferably, the service message structural unit 404 specifically includes: operation information extracts subelement, field values mistake
Filter unit, parsing subunit, business model building subelement and service message assemble subelement;
The operation information extracts subelement, for working as the action name of first operation and being operation system configuration
When the action name of second operation is identical, the operation information is extracted from the databases comparison event;
The field values filter subelement, for extracting in the extracted operation information of subelement from the operation information
Filter out the field values of first field;
The parsing subunit, for parsing the title of class according to the title of first table;
The business model constructs subelement, described first for being filtered out using field values filtering subelement
The field values of field fill the attribute of the class, to construct business model;
The service message assembles subelement, and the action name and the business model for operating described first assemble
At service message.
More preferably, first operation or the second operation include: insertion operation, update operation, inquiry operation or delete behaviour
Make.
More preferably, the service message transmission unit 405 is specifically used for: according to the name of the class configured for the operation system
Claim, the service message is sent to the operation system.
Professional should further appreciate that, described in conjunction with the examples disclosed in the embodiments of the present disclosure
Object and algorithm steps, can be realized with electronic hardware, computer software, or a combination of the two, hard in order to clearly demonstrate
The interchangeability of part and software generally describes each exemplary composition and step according to function in the above description.
These functions are implemented in hardware or software actually, the specific application and design constraint depending on technical solution.
Professional technician can use different methods to achieve the described function each specific application, but this realization
It is not considered that exceeding scope of the present application.
The step of method described in conjunction with the examples disclosed in this document or algorithm, can be executed with hardware, processor
The combination of software module or the two is implemented.Software module can be placed in random access memory (RAM), memory, read-only memory
(ROM), electrically programmable ROM, electrically erasable ROM, register, hard disk, moveable magnetic disc, CD-ROM or technical field
In any other form of storage medium well known to interior.
Above-described specific embodiment has carried out further the purpose of the application, technical scheme and beneficial effects
It is described in detail, it should be understood that being not used to limit the application the foregoing is merely the specific embodiment of the application
Protection scope, within the spirit and principles of this application, any modification, equivalent substitution, improvement and etc. done should all include
Within the scope of protection of this application.