The content of the invention
The present invention provides a kind of acquisition methods of business, device, storage medium and computer equipment, to solve existing skill
In art business upon execution, the problems such as the repetitive schedule or scheduling conflict of appearance.
In order to solve the above technical problems, on the one hand, the present invention provides a kind of acquisition methods of business, including:It obtains predetermined
The corresponding modulus value of business;Detect in predetermined server list the list number corresponding server identification number identical with modulus value whether with
Local server identification number is identical;In the case where server identification number is identical with local server identification number, predetermined industry is obtained
Business.
Further, the corresponding modulus value of intended service is obtained, including:Obtain the business serial number of intended service and current place
In the quantity of the Servers-all of working condition;The quantity of business serial number and server is subjected to modulo operation, is determined predetermined
The corresponding modulus value of business.
Further, before the quantity for obtaining the Servers-all for being currently at working condition, further include:Establish with
The connection of ZooKeeper;The information for the server being connected with ZooKeeper is obtained, wherein, information includes at least server name
With server identification number;Predetermined server list is established according to the quantity of information and the server being connected with ZooKeeper.
Further, after establishing predetermined server list according to the quantity of information and the server being connected with ZooKeeper,
It further includes:Whether the quantity for detecting the server being connected with ZooKeeper changes;In the case where the quantity of server changes,
Predetermined server list is changed according to the quantity of server after change.
Further, whether the quantity for the server that detection is connected with ZooKeeper changes, including:Detect ZooKeeper
In whether there is sensing node;In the case of there are sensing node, child node is established under sensing node, wherein, child node
Value be local server identification number;The state of sensing node is monitored, wherein, the state of sensing node includes:In sensing node
Lower increase or deletion child node.
Further, detect in ZooKeeper with the presence or absence of after sensing node, further include:There is no sensing nodes
In the case of, sensing node is created, and child node is established under sensing node.
On the other hand, the present invention also provides a kind of acquisition device of business, which is characterized in that including:First acquisition module,
For obtaining the corresponding modulus value of intended service;Detection module, for detecting list identical with modulus value in predetermined server list
Whether number corresponding server identification number is identical with local server identification number;Second acquisition module, in server identification
In the case of number identical with local server identification number, intended service is obtained.
Further, the first acquisition module is specifically used for:It obtains the business serial number of intended service and is currently at work
The quantity of the Servers-all of state;The quantity of business serial number and server is subjected to modulo operation, determines current business pair
The modulus value answered.
Further, the first acquisition module is specifically used for:It establishes with distributed application program coordination service ZooKeeper's
Connection;The information for the server being connected with ZooKeeper is obtained, wherein, information includes at least server name and server mark
Knowledge number;Predetermined server list is established according to the quantity of information and the server being connected with ZooKeeper.
Further, the first acquisition module is specifically used for:Whether the quantity for detecting the server being connected with ZooKeeper changes
Become;In the case where the quantity of server changes, predetermined server list is changed according to the quantity of server after change.
Further, the first acquisition module is specifically used for:It detects and whether there is sensing node in ZooKeeper;Feel existing
In the case of knowing node, child node is established under sensing node, wherein, the value of child node is local server identification number;It monitors
The state of sensing node, wherein, the state of sensing node includes:Increase under sensing node or delete child node.
Further, the first acquisition module is specifically used for:In the case of there is no sensing node, sensing node is created, and
Child node is established under sensing node.
On the other hand, the present invention also provides a kind of storage medium, computer program is stored on storage medium, program is located
Reason device realizes the acquisition methods of above-mentioned business when performing.
On the other hand, the present invention also provides a kind of computer equipments, which is characterized in that including memory, processor and deposits
The computer program that can be run on a memory and on a processor is stored up, processor realizes obtaining for above-mentioned business when performing program
Take method.
The present invention is different by the business serial number of different business, calculates the corresponding modulus value of business serial number, and according to
Modulus value determines that intended service should actually belong to which server is handled, and server is made only to need to obtain oneself and should locate
The intended service of reason is not in multiple tasks on different server while handles the situation of same business, solves existing
There is in technology business upon execution, the problems such as the repetitive schedule or scheduling conflict of appearance.
Specific embodiment
In order to solve to solve in the prior art business upon execution, the problems such as the repetitive schedule or scheduling conflict of appearance, this
Invention provides the acquisition methods and storage medium of a kind of business, below in conjunction with attached drawing and embodiment, to the present invention into traveling
One step is described in detail.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, this hair is not limited
It is bright.
The first embodiment of the present invention provides a kind of acquisition methods of business, and flow chart is as shown in Fig. 2, specifically include
Step S201 to S203:
S201 determines the corresponding modulus value of intended service;
S202, detect in predetermined server list the list number corresponding server identification number identical with modulus value whether with from
Body server identification number is identical;
S203 in the case where server identification number is identical with local server identification number, obtains intended service.
The subject of implementation of the business obtaining method provided in first embodiment of the invention is each server in cluster.Respectively
The business serial number of a business is unique, and the business serial number of the subsequent next business of current business is the industry in current business
Business serial number numerically adds 1, to ensure the continuous and unique of business serial number.
Server is when obtaining the corresponding modulus value of intended service, business serial number that can first by obtaining intended service
And the quantity of the Servers-all of working condition is currently at, then by the business serial number of intended service and the number of server
Amount carries out modulo operation, to determine the corresponding modulus value of intended service.Preferably due in the task of acquisition, in cluster each just
The calculating of the corresponding modulus value of carry out business is required in the server of work, and the actual number of services obtained of server may be only
Have the part in all business, therefore many unnecessary calculating can be caused, thus can also arrange one it is pre- for calculating
Determine the computing device of the corresponding modulus value of business, the corresponding magnitude calculation of all business is responsible for by the computing device, server only needs
The result of calculation of modulus value is directly acquired from the computing device, unnecessary calculating is eliminated, further improves industry
The efficiency that business obtains.
Server obtains the business serial number of intended service in the corresponding modulus value of the definite intended service of needs itself, and
And server can obtain the working condition of other servers in this cluster and be currently at the Servers-all of working condition
Quantity.Modulo operation is then carried out to business serial number according to the quantitative value, i.e. business serial number is as dividend X, currently
The quantitative value of in running order Servers-all is divisor Y, calculates maximum integer business and remainder, and the remainder is
The value range of modulus value mod, mod are [0, N-1].Server obtains the predetermined server list preserved, is preserved in the list
The server identification number of current all in running order servers, according to mod, obtain in predetermined server list with mod
The corresponding server identification number of identical list number, and judge the server identification number and the server identification number of itself whether phase
Together, when the server identification number is identical with the server identification number of itself, server determines that the intended service should be by certainly
Oneself is handled, and is obtained the intended service and handled, and ensure that a business is only handled by a server, will not
There are multiple servers while handle a business.
The present embodiment is different by the corresponding modulus value of business serial number of different business, and determines predetermined industry according to modulus value
Which server pragmatic border, which should belong to, is handled, and server is made only to need to obtain the intended service that oneself should be handled, no
It is present with multiple tasks on different server while handles the situation of same business, solves business in the prior art and holding
During row, the problems such as the repetitive schedule or scheduling conflict of appearance.Also, the business obtaining method principle letter of the proposition of the present embodiment
It is single, it can extend or optimize, autgmentability higher according to the different demands of user.
Server should start first before the quantity for the Servers-all for being currently at working condition obtain
ZooKeeper simultaneously establishes the connection between server and ZooKeeper, and after successful connection, acquisition is currently connected with ZooKeeper
Servers-all information, including at least the corresponding server identification number of server name and its of Servers-all, and root
Predetermined server list is established according to the information of acquisition and the quantity for the server being connected with ZooKeeper, to Servers-all
When identification number is arranged, can in order it be arranged or according to server according to the numerical values recited of server identification number
The time order and function order that the corresponding server of identification number is connected to ZooKeeper is arranged.It will be appreciated that preset service
The list number of device list is arranged since 0, and the corresponding content of each list number includes at least server identifier, can also include
Other attributes on server that the title or system of server are set.Further, establish predetermined server list it
Afterwards, whether the quantity of pair server being connected with ZooKeeper changes progress detection in real time or separated in time detection,
In the case that the quantity of server changes, predetermined server list is changed according to the quantity of server after change.It is understood that
It is the predetermined server list for having their own to create in the Servers-all being connected with ZooKeeper, and the row of list content
Row rule is identical, ensures that Servers-all is identical according to the result that business serial number judges, is not in conflict.Such as:Institute
Have in the predetermined server list of server, list number is that the corresponding contents of A are the server identification number that value is 0001, works as clothes
During the mod=A that business device calculates, which is obtained by the server that server identification number is 0001 and is handled.
In the present embodiment, server is by detecting the child node number under sensing node present in ZooKeeper, really
The quantity of the fixed server being connected with ZooKeeper.After server is connected with ZooKeeper, detects and whether deposited in ZooKeeper
In sensing node, if there are sensing node, created under the sensing node can with the child node of representative server itself,
In, the value of child node is local server identification number;If there is no sensing node, creating one, routinely node is perceptually
Node, name can be/timer, and establish after creation under/timer can with the child node of representative server itself,
In, the value of child node is similarly local server identification number;After establishing child node, the state of sensing node, sensing node are monitored
State include:Increase under sensing node or delete child node, when the state of sensing node changes, ZooKeeper
To server sending node Status Change message, message includes the specific situation of change of sensing node state, such as increases son section
During point, the information such as title, value of increased child node, which child node delete is during deletion child node, the value of the child node
It is how many, server to be facilitated to change the content of predetermined server list in real time.Also, working as can be with processing business
When number of servers changes, the specific business and number of services of other server process can also change, and pass through
The establishment of sensing node and the monitoring to sensing node, the ability that server is made to possess dynamic capacity-expanding make entire distribution
System work is more flexible.Preferably, the number for the server that computing device determines to be connected with ZooKeeper also by sensing node
Amount, but computing device can not establish child node under sensing node, and it can only monitor the state of sensing node, to obtain calculating mould
It is worth corresponding information.
The second embodiment of the present invention provides a kind of acquisition device of business, and structure diagram is as shown in figure 3, main
Including:First acquisition module 301,302 and second acquisition module 303 of detection module, wherein, the first acquisition module 301 is used for
Obtain the corresponding modulus value of intended service;Detection module 302 is used to detect list number identical with modulus value in predetermined server list
Whether corresponding server identification number is identical with local server identification number;Second acquisition module 303 is used in server identification
In the case of number identical with local server identification number, intended service is obtained.
On each server of the installation of the business acquisition device provided in second embodiment of the invention in the cluster.It is each
The business serial number of business is unique, and the business serial number of the subsequent next business of current business is the business in current business
Serial number numerically adds 1, to ensure the continuous and unique of business serial number.
Acquisition device can be obtained pre- in the corresponding modulus value of acquisition intended service by the first acquisition module 301 first
The quantity of the business serial number for determining business and the Servers-all for being currently at working condition, then by the business of intended service
The quantity of serial number and server carries out modulo operation, to determine the corresponding modulus value of intended service.Preferably due to appoint obtaining
During business, each server to work is required for the calculating of the corresponding modulus value of carry out business in cluster, and server is actual obtains
The number of services taken may only have the part in all business, therefore can cause many unnecessary calculating, so can be with
Arrangement one is responsible for the corresponding mould of all business for calculating the computing device of the corresponding modulus value of intended service by the computing device
Value calculates, and acquisition device only needs to directly acquire the result of calculation of modulus value from the computing device by the first acquisition module 301
, unnecessary calculating is eliminated, further improves the efficiency of business acquisition.
First acquisition module 301 obtains the business of intended service in the corresponding modulus value of the definite intended service of needs itself
Serial number, and the first acquisition module 301 can obtain the working condition of other servers in this cluster and be currently at work
Make the quantity of the Servers-all of state.Modulo operation, i.e. business flowing water are then carried out to business serial number according to the quantitative value
Number be used as dividend X, be currently at the quantitative value of Servers-all of working condition as divisor Y, calculate maximum integer business with
And remainder, and the remainder is modulus value mod, the value range of mod is [0, N-1].Detection module 302 obtains the default of preservation
Server list preserves the server identification number of current all in running order servers in the list, according to mod,
The corresponding server identification number of list number identical with mod in predetermined server list is obtained, and judges the server identification number
It is whether identical with the server identification number of itself, when the server identification number is identical with the server identification number of itself, detection
Module 302 determines that the intended service should be handled by oneself, and passes through the second acquisition module 303 and obtain the intended service
It is handled, ensure that a business is only handled by a server, there is no multiple servers to handle one simultaneously
The situation of business.
The present embodiment is different by the corresponding modulus value of business serial number of different business, and determines predetermined industry according to modulus value
Which server pragmatic border, which should belong to, is handled, and server is made only to need to obtain the intended service that oneself should be handled, no
It is present with multiple tasks on different server while handles the situation of same business, solves business in the prior art and holding
During row, the problems such as the repetitive schedule or scheduling conflict of appearance.Also, the business obtaining method principle letter of the proposition of the present embodiment
It is single, it can extend or optimize, autgmentability higher according to the different demands of user.
First acquisition module 301 is before the quantity for the Servers-all for being currently at working condition obtain, first
ZooKeeper should be started and establish the connection between server and ZooKeeper, after successful connection, obtain currently with
The information of the Servers-all of ZooKeeper connections can include server name service corresponding with its of Servers-all
Device identification number, and predetermined server list is established according to the information of acquisition and the quantity for the server being connected with ZooKeeper,
When arranging Servers-all identification number, can in order be arranged according to the numerical values recited of server identification number or
The time order and function order that person is connected to ZooKeeper according to the corresponding server of server identification number is arranged.It is understood that
, the list number of predetermined server list arranges since 0, and the corresponding content of each list number is identified including at least server
Number, other attributes on server that the title of server or system are set can also be included.Further, establishing in advance
If after server list, whether the quantity of pair server being connected with ZooKeeper, which changes progress, is detected or is spaced in real time
Certain time detects, and in the case where the quantity of server changes, predetermined server is changed according to the quantity of server after change
List.It will be appreciated that the predetermined server row for thering is their own to create in the Servers-all being connected with ZooKeeper
Table, and the queueing discipline of list content is identical, ensures that Servers-all is identical according to the result that business serial number judges, will not go out
Now conflict.Such as:In the predetermined server list of Servers-all, list number is that the corresponding contents of A are that value is 0001
As the mod=A that server calculates, the business is obtained by the server that server identification number is 0001 for server identification number
It is handled.
In the present embodiment, the first acquisition module 301 is saved by the son detected under sensing node present in ZooKeeper
Point number determines the quantity for the server being connected with ZooKeeper.After server is connected with ZooKeeper, detection
With the presence or absence of sensing node in ZooKeeper, if there are sensing nodes, being created under the sensing node can be with representative server
The child node of itself, wherein, the value of child node is local server identification number;If there is no sensing nodes, one is created often
Rule property node perceptually node, name can be/timer, and established under/timer can represent service after creation
The child node of device itself, wherein, the value of child node is similarly local server identification number;After establishing child node, monitor and perceive section
The state of point, the state of sensing node include:Increase under sensing node or delete child node, when the state of sensing node occurs
During variation, ZooKeeper includes the specific variation of sensing node state to server sending node Status Change message, message
Situation, when such as increasing child node, the information such as title, value of increased child node, which sub- section delete is during deletion child node
Point, the value of the child node is how many, server to be facilitated to change the content of predetermined server list in real time.Also,
When can be changed with the number of servers of processing business, the specific business and number of services of other server process
It can change, the establishment by sensing node and the monitoring to sensing node make server possess the energy of dynamic capacity-expanding
Power makes entire distributed system work more flexible.Preferably, computing device determines to connect with ZooKeeper also by sensing node
The quantity of the server connect, but computing device can not establish child node under sensing node, and it can only monitor the shape of sensing node
State calculates the corresponding information of modulus value to obtain.
Through the above description of the embodiments, those skilled in the art can be understood that according to above-mentioned implementation
The method of example can add the mode of required general hardware platform to realize by software, naturally it is also possible to by hardware, but it is very much
In the case of the former be more preferably embodiment.Based on such understanding, technical scheme is substantially in other words to existing
The part that technology contributes can be embodied in the form of software product, which is stored in a storage
In medium (such as ROM/RAM, magnetic disc, CD), used including some instructions so that a station terminal equipment (can be mobile phone, calculate
Machine, server or network equipment etc.) method that performs each embodiment of the present invention.
The third embodiment of the present invention additionally provides a kind of storage medium, is stored with computer program.Optionally, in this reality
It applies in example, following steps is realized when computer program is executed by processor:
S31 determines the corresponding modulus value of intended service;
S32, detect in predetermined server list the list number corresponding server identification number identical with modulus value whether with from
Body server identification number is identical;
S33 in the case where server identification number is identical with local server identification number, obtains intended service.
On each server of the storage medium installation provided in third embodiment of the invention in the cluster.Each business
Business serial number is unique, and the business serial number of the subsequent next business of current business is the business serial number in current business
Numerically plus 1, to ensure the continuous and unique of business serial number.
Optionally, computer program is specific real when being executed by processor the step of the corresponding modulus value of definite intended service
Existing following steps:The quantity of the business serial number for obtaining intended service and the Servers-all for being currently at working condition;It will
The quantity of business serial number and server carries out modulo operation, determines the corresponding modulus value of intended service.Preferably due to it is obtaining
During task, each server to work is required for the calculating of the corresponding modulus value of carry out business in cluster, and server is actual
The number of services of acquisition may only have the part in all business, therefore can cause many unnecessary calculating, so may be used also
With one computing device for being used to calculate the corresponding modulus value of intended service of arrangement, it is corresponding that all business are responsible for by the computing device
Magnitude calculation, server are only needed to directly acquire the result of calculation of modulus value from the computing device, eliminated unnecessary
It calculates, further improves the efficiency of business acquisition.
Computer program be executed by processor obtain be currently at working condition Servers-all quantity the step of
Before, following steps are also executed by processor:Establish the connection with ZooKeeper;Obtain the service being connected with ZooKeeper
The information of device, wherein, information includes at least server name and server identification number;It is connected according to information and with ZooKeeper
The quantity of server establish predetermined server list.Further, computer program be executed by processor according to information and with
The quantity of the server of ZooKeeper connections is established after predetermined server list, is also executed by processor following steps:Detection
Whether the quantity for the server being connected with ZooKeeper changes;In the case where the quantity of server changes, according to being taken after change
The quantity modification predetermined server list of business device.
It will be appreciated that computer program is being executed by processor the number for the server that detection is connected with ZooKeeper
When measuring the step whether changed, step is implemented as follows:It detects and whether there is sensing node in ZooKeeper;Feel existing
In the case of knowing node, child node is established under sensing node, wherein, the value of child node is local server identification number;It monitors
The state of sensing node, wherein, the state of sensing node includes:Increase under sensing node or delete child node.Preferably, count
Calculation machine program is also executed by processor following after being executed by processor in detection ZooKeeper with the presence or absence of sensing node
Step:In the case of there is no sensing node, sensing node is created, and child node is established under sensing node.
The present embodiment is different by the corresponding modulus value of business serial number of different business, and determines predetermined industry according to modulus value
Which server pragmatic border, which should belong to, is handled, and server is made only to need to obtain the intended service that oneself should be handled, no
It is present with multiple tasks on different server while handles the situation of same business, solves business in the prior art and holding
During row, the problems such as the repetitive schedule or scheduling conflict of appearance.Also, the business obtaining method principle letter of the proposition of the present embodiment
It is single, it can extend or optimize, autgmentability higher according to the different demands of user.
Optionally, in the present embodiment, above-mentioned storage medium can include but is not limited to:USB flash disk, read-only memory (ROM,
Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disc or
The various media that can store program code such as CD.Optionally, in the present embodiment, processor has been deposited according in storage medium
The program code of storage performs the method and step of above-described embodiment record.Optionally, the specific example in the present embodiment may be referred to
Example described in above-described embodiment and optional embodiment, details are not described herein for the present embodiment.Obviously, the technology of this field
Personnel should be understood that each module of the above-mentioned present invention or each step can be realized with general computing device, they can be with
It concentrates on single computing device or is distributed on the network that multiple computing devices are formed, optionally, they can be used
The program code that computing device can perform is realized, it is thus possible to be stored in storage device by computing device to hold
Row, and in some cases, it can be with the steps shown or described are performed in an order that is different from the one herein or divides them
Each integrated circuit modules are not fabricated to or multiple modules in them or step are fabricated to single integrated circuit module
It realizes.It to be combined in this way, the present invention is not limited to any specific hardware and softwares.
Fourth embodiment of the invention provides a kind of computer equipment, including memory, processor and is stored in memory
Computer program that is upper and can running on a processor, realizes what is provided in first embodiment of the invention when processor performs program
Business obtaining method, in this not go into detail, and it realizes process.
Although for example purpose, the preferred embodiment of the present invention is had been disclosed for, those skilled in the art will recognize
Various improvement, increase and substitution are also possible, and therefore, the scope of the present invention should be not limited to above-described embodiment.