A kind of implementation method of message Push Service and systemTechnical field
The present invention relates to internet arena, particularly a kind of implementation method of message Push Service and system.
Background technology
Continuous development along with the Internet; Client and service end transmission of messages are more and more general, in order better to improve user experience, improve the real-time of message; Usually can be when client represents; Information and data to changing are carried out the partial update conversion, avoid refreshing or the request again of total data of overall page, and the design of message Push Service system and realization just become more and more important.
The messenger service pattern of internet arena main flow is that client is according to certain time interval at present; Service end is carried out polling request, data pull is represented to the client line asynchronous of going forward side by side, this kind mode realizes simply; But also have the following shortcoming and defect: 1) poll services of client can cause the lasting pressure to service end; Be that the service end service ability is limited, responding ability descends, to the peak value difficulty of request; 2) polling request of client can cause the decline of client performance, like the continuous poll services end of cell-phone customer terminal, can cause the increase of power consumption and network traffics, also can cause the influence of overall performance simultaneously to the more weak terminal of performance; 3) real-time of message has certain influence, because of poll needs month blanking time of agreement poll, blanking time therebetween, any message that newly arrives can not received and handle to client, can impact user experience; 4) non real-time polled async request also can cause the puzzlement of Network Transmission, may have no message therebetween twice polling interval, causes the waste of request; Simultaneously, the message of a large amount of accumulations possibly arranged also in phase blanking time, in next client-requested, once obtain, give the Network Transmission build-up of pressure.
Summary of the invention
Provided by the invention, at a certain time interval service end is carried out the problem that polling request causes to solve.
The invention provides a kind of implementation method of message Push Service, comprising:
Step 1, the message stores that PUSH message formation receiver module will push is in message queue;
Step 2, push the said formation of logic processing module poll and with message stores in the state-storage module in the pairing Key-Value key-value pair of user;
Step 3, behind user's logging on client, client is initiated the Push Service request to the long communication module that connects;
Step 4, long connection communication module are set up and are kept with the long of client and be connected, and write state of user to state-storage module;
Step 5; Whether the long communication module inquiry state-storage module that connects has message to be pushed to the user; If the long communication module message that then taking-ups needs to push from state-storage module that connects is sent to client, and keep the connection status with client and state-storage module; Otherwise long connection communication module is kept with the long of client and is connected.
In one example, in the step 1, the message that PUSH message formation receiver module will push stores in the message queue at random.
In one example, in the step 2, push logic processing module and cease to the sequential read cancellation in the message queue according to message stores; Push the state adjustment thread resources of logic processing module according to message queue.
In one example, in the step 2, state-storage module is a key assignments with user's identifier, and key assignments is write by the long communication module that connects; The message of the value that key-value pair is answered for needing to push, this message writes by pushing logic processing module.
In one example, in the step 3, the long communication module that connects adopts based on http protocol.
The invention provides a kind of realization system of message Push Service, comprising:
PUSH message formation receiver module, the message stores that is used for needs are pushed is to message queue;
Push logic processing module, be used for the said message queue of poll and with message stores in the pairing Key-Value key-value pair of state-storage module user;
The long communication module that connects is used for behind user's logging on client, receives client and initiates the Push Service request to the long communication module that connects; Set up and keep with the long of client and be connected, and write state of user to state-storage module; Whether the inquiry state-storage module has message to be pushed to the user; When having message to be pushed to the user, the message that taking-up need to push from state-storage module is sent to client, and keeps the connection status with client and state-storage module; When not having message to be pushed to the user, keep with the long of client and be connected.
In one example, PUSH message formation receiver module is used for storing the data that needs push into message queue at random.
In one example, push logic processing module, be used for according to the sequential read cancellation breath of message stores to message queue; Push logic processing module, be used for state adjustment thread resources according to message queue.
In one example, state-storage module comprises key-value pair, and key-value pair is a key assignments with user's identifier, and key assignments is write by the long communication module that connects; The message of the value that key-value pair is answered for needing to push, this message writes by pushing logic processing module.
In one example, the long communication module that connects adopts based on http protocol.
The beneficial effect of the embodiment of the invention is: change the clients poll request into client and be connected with the length that service end is carried out network communication, can carry out the deployment of a plurality of instances, each instance can be shared client-requested visit pressure, has improved the availability of system.
Description of drawings
Fig. 1 is a message Push Service system schematic of the present invention;
Fig. 2 is a message Push Service method flow diagram of the present invention.
Embodiment
For making the object of the invention, technical scheme and advantage clearer, embodiment of the present invention is done to describe in detail further below in conjunction with accompanying drawing.
Referring to Fig. 1, be the message Push Service system schematic that the embodiment of the invention provides, this system is divided into following several module:
PUSH message formation receiver module: this module mainly is made up of message queue, is used for receiving the message that need push from each external system.Utilize message queue to write the buffering of pressure peak, and can carry out asynchronous read and write operation, the flexibility that improves system.Aspect availability, this module adopts random write to a plurality of formation instances, and the mode of sequential read had both guaranteed the high availability of this module, had also avoided the maintenance cost of complicated architectures.
Push logic processing module: this module mainly adopts the thread pool technology; Be used for reading the PUSH message information in the message queue; With the key assignments form of this information, according to self-defining extendible structural data storage organization, the asynchronous state-storage module that stores into ID.This module can be carried out the increase and decrease of thread resources automatically according to the state of message queue, and it is busy both can to have avoided the concurrent peak value of message to handle, can reduce again size of message when very little to the waste of main frame thread resources etc.This module existence not can carry out the distributed deployment of many instances simultaneously, carries out load balancing etc. and improves system availability.
State-storage module: this module is the high speed key-value pair buffer memory engine of realizing voluntarily; Function is for being key assignments with the ID; Storage is in requisition for the structural data of the message that pushes; The key assignments ID of this module is written as the long communication module that connects and safeguards, the propelling movement logic processing module that is written as of the pairing value of key assignments writes maintenance.The user profile that storage engines is safeguarded also is the online user, and it is nonsensical carrying out the message propelling movement for non-online user on the business.The persistence information of deferred information can be safeguarded in other memory module.This module can be carried out strategies such as consistency Hash according to the characteristics of key assignments storage engines, carries out the deployment of many instances, both can reduce single instance system bottleneck, can improve the availability of system again.
The long communication module that connects: this module is based on http protocol; The inner long Connection Service of HTTP based on formation and the realization of message trigger mechanism; When the user reached the standard grade, when receiving user's Push Service interface requests of client transmission, this module was kept with the HTTP of client is long and is connected; User's ID and other information write state memory modules will be asked simultaneously, quasi real time communication will be kept subsequently always with state-storage module.When finding to have new information to push, then from state-storage module, take out the message that desire pushes, be pushed to client simultaneously, if the information that need not push, then keep long the connection always and do not carry out data communication.This module adopts http protocol simultaneously, be convenient to client realize with front end based on the strategies such as agreement distribution of HTTP Proxy, can carry out the deployment of a plurality of instances, each instance can be shared client-requested visit pressure, can high the availability of system.
The workflow of concrete request response is as shown in Figure 2:
Step 10, PUSH message formation receiver module receive the data that need propelling movement in real time and mix and deposit in the formation.
Step 11 pushes the logic processing module snoop queue, and data set is dressed up the structural data of propelling movement, asynchronous storing in the state-storage module in the pairing key-value pair of this ID.
Step 12, the client login is reached the standard grade, and initiates interface requests to Push Service;
Step 13, the long communication module that connects is received client-requested, sets up and keep with the long of client to be connected, and writes information such as state of user simultaneously to state-storage module.
Step 14, long connection communication module is kept always and is inquired whether state-storage module has latest news to be pushed to this user, if there is not latest news, execution instep 15 is if having new information, execution instep 16.
Step 15, long connection communication module then can be kept with the long of client and be connected, and do not carry out data interaction, also can keep the inquiry state with state-storage module simultaneously.
Step 16, the structured message data that taking-up need to push from state-storage module return to client, continue to keep the linking status with client and state-storage module then.
The above is merely preferred embodiment of the present invention, is not to be used to limit protection scope of the present invention.All any modifications of within spirit of the present invention and principle, being done, be equal to replacement, improvement etc., the for example change of module title or replacement all is included in protection scope of the present invention.