Embodiment
For making the object, technical solutions and advantages of the present invention clearer, below in conjunction with execution mode and accompanying drawing, the present invention is described in further details.At this, exemplary embodiment of the present invention and explanation thereof are used for explaining the present invention, but not as a limitation of the invention.
The embodiment of the present invention provides a kind of account to open message treatment method and system more, and below in conjunction with accompanying drawing, the present invention is described in detail.
Embodiment mono-
Fig. 1 is that the embodiment of the present invention is opened the Organization Chart of message handling system more with account.As shown in Figure 1, this system comprises three parts: data center (Data Center, DC), message forwarder (Message Broker, MB) and load equalizer (Load Balance, LB).Data center connects application system (APP) and message forwarder; Message forwarder connection data center, load equalizer and client; Load equalizer connection message transponder and client.
Data center, receive the message that application system sends to target account, according to described message, obtain target account information, detect and whether have at least two clients to use described target account information to log in simultaneously, if at least two clients are used described target account information to log in, at least two clients described in described message being sent to simultaneously simultaneously.
In embodiments of the present invention, data center mainly realizes the functions such as User Status management and data routing distribution.Message forwarder informs by timing heartbeat message and upgrades current online account state, and data center safeguards the online account state of whole system; Application system (App) produces message and is sent to data center, if data need storage, data center stores this message so, then by message distribution, gives corresponding message forwarder.If message forwarder sends successfully reminder-data center so and deletes this message.
Message load mode has one to one and two kinds of one-to-manies.Such as replying message, be man-to-man load mode, broadcast and subscribed message are the load mode of one-to-many.Wherein, the message of one-to-many can be divided into two large classes: directed and nondirectional.Knowing for sure is that the message definition that sends which user's one-to-many to is directed message, and the indefinite message of knowing the one-to-many that need to send which user to is for nondirectional.According to above definition, broadcast system message is defined as nondirectional; If the message of user's issue has been subscribed to by many people, this message is directed so.
In the present embodiment, system only can be stored the deferred information of the one-to-many of man-to-man deferred information and orientation, nondirectional off-line broadcast is not generally deposited, but have except the off-line broadcast of certain life cycle, for example: the off-line broadcast of sending to the login user in certain hour section can be stored, until life cycle finish after by deleted.
In embodiments of the present invention, message forwarder receives the described message that data center sends, at least two clients described in described message is sent to.Message forwarder upgrades the current presence of account, and the current presence of account is informed to described data center; Described data center safeguards the current presence of account in whole system, so that the interface of inquiry account state to be provided, and according to the current presence of the account in system, the message from described application system is processed.When user logins, message forwarder is according to user's session id(session identification) to certificate server, verify, be verified so and just set up and the communicating by letter of this user, otherwise refuse this user, login.
In embodiments of the present invention, load equalizer is according to the loading condition of link circuit condition and message forwarder, for client is distributed corresponding message forwarder, specifically, load equalizer connects with the client of login first, according to the loading condition of link circuit condition and message forwarder, it is the message forwarder of client optimal scheme; And when the message forwarder having distributed breaks down, for client is redistributed message forwarder.Message forwarder is registered to load equalizer, and regularly circulates a notice of the load of himself.Client can send and obtain message forwarder request to load equalizer, and load equalizer can select a message forwarder to reply to client, and then client communicates with corresponding message forwarder.
Alternatively, described system also comprises: what connect a plurality of data centers in different machine rooms acts on behalf of trustship module; Described data center, also for being synchronized to other machine room by the deferred information of storage by the described trustship module of acting on behalf of; When the current presence of user changes, notify the described trustship module of acting on behalf of to carry out User Status renewal.Between data center, by acting on behalf of trustship module (Proxy) docking, to complete data cross-system, process.In real network application, data center can be divided into two of telecommunications and Netcoms, uses respectively two-server, keeps more than 2,000,000 client of total amount and can continue to expand.
Alternatively, in the present embodiment, between App and DC, adopt the character string type communication protocol based on TCP, be similar to http agreement, be divided into message header and message body.Message header and message body are used CRLF(new line, carriage return/line feed) cut apart.Field name in message header and value are used space to cut apart, and use CRLF to cut apart between field.Except App and DC, other communication protocol is binary signaling agreement.Wherein communicating by letter between Message Broker and DC and Load balance is based on TCP host-host protocol, and the communication relevant with client is all based on UDP host-host protocol.When using UDP host-host protocol, need to consider reliability, when data-bag lost, need to retransmit, and (be greater than 512 bytes) when packet is larger, just need subpackage.
Alternatively, in the present embodiment, the heartbeat packet of client size is 16+46=62Byte.Suppose that 100 general-purpose families sent heartbeat packet every 30 seconds, Message Broker holds total utilized bandwidth to be approximately 62Mbyte/30s*8=16.5Mbit/s so.The communication data of message forwarder and client all adopts certain cryptographic algorithm to be encrypted, as: AES.
The message realization method that account is opened more:
With unit room, consider, data store organisation design is as follows:
1) storage organization on Data Center
The data that Data Center need to store mainly contain deferred information data and online user's information.Wherein deferred information data be persistent storage on hard disk, and online user's information is stored on internal memory.The ID of definition message recipient is usrid, and sender of the message's ID is sndrid, and the content representation of message is content, and every a piece of news has the unique numbering uid of the overall situation simultaneously, and expired time expire.The UUID that wherein uid can be generated by Data Center represents, or is generated by application program.If message is to write multiserver by application program more, should generate uid by application program so.
Storage is intended to realize with TC database.Deferred information data acquisition is stored with B+ tree database, minute two database file storages, a storage index, storage entity data.Design as follows:
Index structure:
Solid data storage organization:
uid1 |
content1 |
uid2 |
content2 |
uidN |
contentN |
Online user's information is stored with hashmap, because needs are supported user Duo Kai, allows same usrid to sign in on many machines of a plurality of machine rooms, stores so every ip address and port that machine is corresponding.Therefore design stores structure is as follows:
2) storage organization on Message Broker
Message Broker need to maintain user connection information, is stored to internal memory.Owing to may user using an account, in many places, login simultaneously, the client of each login is used session to represent so, each session have one No. id.Be that each client connects a corresponding sessionid, be designated as sid, each usrid may corresponding a plurality of sid so.Its " connection " address of each client storage, is designated as sockaddr.Design stores structure is as follows:
When a client exits, the information of deleting corresponding session, after all session of a usrid exit, deletes the information of this usrid so, and notifies Data Center change User Status.Data center deletes the corresponding informance of this usrid and this Message Broker, when the corresponding relation of usrid and Message Broker is sky, represents that so this user is off-line, deletes online user's information that this usrid is corresponding.
User's subscription list: every class application message can be used a specific ID to represent, represents with id, when user has subscribed to such message, and so can be by message push to user.Each ID may have many users to subscribe to, therefore have a user list userlist storage organization as follows corresponding to this ID:
id1 |
userlist1 |
id2 |
userlist2 |
idN |
userlistN |
In another embodiment of the present invention, data center is unified storage and backup using described message as deferred information when target account off-line, and according to the request of described message forwarder, to described message forwarder, sends corresponding deferred information; When message forwarder is used the login of target account in client, the request of obtaining deferred information to the initiation of described data center, receives the deferred information that described data center returns, and described deferred information is sent to corresponding client.Message forwarder successfully send described deferred information to client after, to described data center, return successfully and to send notice; The deferred information that success sends, according to the described notice that successfully sends, is deleted by data center.
The same account that the embodiment of the present invention provides is opened message handling system more can allow many clients using same account simultaneously to log in be subject to the message that application system is issued target account simultaneously, guarantees that user can not miss message, has improved user's experience.
Deferred information processing procedure: first user logins the Broker to Message, then Message Broker sends the deferred information request of obtaining respective user to Data center; Then whether DC inquiry there is the deferred information of respective user, carries out so next step, otherwise finish this operating process if existed; DC is pushed to corresponding Message Broker by deferred information, then Message Broker sends to corresponding user again, if sent successfully, Message Broker notice DC deletes the corresponding deferred information of storage and finishes this operating process so, otherwise does not delete deferred information and finish this process.
Embodiment bis-
Same account based on previous embodiment is opened message handling system more, and the embodiment of the present invention also provides a kind of account to open message treatment method more.Fig. 2 is that a kind of account that the embodiment of the present invention provides is opened message treatment method flow chart more, and Fig. 3 is the process chart of the transmission deferred information that provides of the embodiment of the present invention, and as shown in Figures 2 and 3, described method comprises:
S201, data center receives the message that application system sends to target account, and whether detect described target account has at least two clients to use simultaneously, and described data center is for the current presence of maintenance system account.
S202, when described target account has at least two clients to use simultaneously, data center determines at least two at least two message forwarders that clients difference is corresponding with described.
S203, described at least two message forwarders are transmitted to the message that sends to target account respectively at least two described clients.
In embodiments of the present invention, data center can be sent to message forwarder by described message, at least two clients described in by described message forwarder, described message being sent to.
In embodiments of the present invention, described message forwarder upgrades the current presence of account, and the current presence of account is informed to described data center; Described data center safeguards the current presence of account in whole system, so that the interface of inquiry account state to be provided, and according to the current presence of the account in system, the message from described application system is processed.
In another embodiment of the present invention, described method also comprises:
Load equalizer is according to the loading condition of link circuit condition and message forwarder, for client is distributed corresponding message forwarder.Specifically, load equalizer connects with the client of login first, according to the loading condition of link circuit condition and message forwarder, is the message forwarder of client optimal scheme; And when the message forwarder having distributed breaks down, for client is redistributed message forwarder.
In another embodiment of the present invention, described method also comprises:
If target account off-line, data center's unified storage and backup using described message as deferred information;
When client is used the login of target account, the message forwarder corresponding with described client initiated the request of obtaining deferred information to described data center;
Described data center, according to the request of described message forwarder, sends corresponding deferred information to described message forwarder;
Described message forwarder receives the deferred information that described data center returns, and described deferred information is sent to corresponding client.
In another embodiment of the present invention, described method also comprises:
Successfully send described deferred information to client after, described message forwarder returns successfully and to send notice to described data center;
The deferred information that success sends, according to the described notice that successfully sends, is deleted by described data center.
The account of the embodiment of the present invention opens message treatment method more and system has following characteristics:
1, can allow many clients using same account simultaneously to log in be subject to the message that application system is issued target account simultaneously, guarantee that user can not miss message, improve user's experience;
2, message, by data center's centralized and unified management, is convenient to backup and prevents loss of data;
3, data center can expand, and between data center, by Proxy trustship module, is docked;
4, user's link classification, first login user or carried out the reallocation of message forwarder by load equalizer with the user of message forwarder connection failure, message forwarder only connects and pushes deferred information to user for maintenance customer's network; Particularly, load equalizer is for connecting with the user of login for the first time, for user selects the message forwarder of link optimum, meanwhile, when message forwarder goes wrong, for user's message forwarder of reallocating is set up link.
The deferred information of the embodiment of the present invention focuses on method and system, by deferred information is carried out to unified management and backup, has avoided the drawback that in prior art, deferred information disperses storage to bring, and has promoted user's experience.
Above-described embodiment; object of the present invention, technical scheme and beneficial effect are further described; institute is understood that; the foregoing is only the specific embodiment of the present invention; the protection range being not intended to limit the present invention; within the spirit and principles in the present invention all, any modification of making, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.