CN102890631B - Method based on persistent message queue transmission message and massage transmission device - Google Patents

Method based on persistent message queue transmission message and massage transmission device Download PDF

Info

Publication number
CN102890631B
CN102890631B CN201210340047.3A CN201210340047A CN102890631B CN 102890631 B CN102890631 B CN 102890631B CN 201210340047 A CN201210340047 A CN 201210340047A CN 102890631 B CN102890631 B CN 102890631B
Authority
CN
China
Prior art keywords
message
vernier
transmitted
confirmation
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201210340047.3A
Other languages
Chinese (zh)
Other versions
CN102890631A (en
Inventor
汤晓刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sina Technology China Co Ltd
Original Assignee
Sina Technology China Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sina Technology China Co Ltd filed Critical Sina Technology China Co Ltd
Priority to CN201210340047.3A priority Critical patent/CN102890631B/en
Publication of CN102890631A publication Critical patent/CN102890631A/en
Application granted granted Critical
Publication of CN102890631B publication Critical patent/CN102890631B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a kind of method based on persistent message queue transmission message and massage transmission device.The method includes: receive message to be transmitted, arranges vernier information for message to be transmitted, and the message arranging vernier information is write message queue;According to the current vernier confirmation updating storage, obtain current message to be transmitted, from message queue, read current message to be transmitted, be transmitted;Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored vernier confirmation.The application present invention, can improve Message Processing efficiency.

Description

Method based on persistent message queue transmission message and massage transmission device
Technical field
The present invention relates to the information transmission technology, particularly relate to a kind of based on persistent message queue transmission message Method and massage transmission device.
Background technology
Persistent message queue (mcq, MemcacheQ) is that the employing of SINA company exploitation is distributed The queue product of increasing income of Message Queuing Services, for the message queue of lightweight.In MemcacheQ, Bottom uses transaction-safe type table type (BDB, Berkeley DB) to carry out message storage, passes through The add method of Memcache agreement and get method, write message queue and respectively from disappearing by message Reading message in breath queue, wherein,
In the add method of Memcache agreement, message format is:
add(key)(flg)(expire)(datalen)\r\n(data)\r\n;
Return value: STORED/UNSTORED.
In the get method of Memcache agreement, message format is:
get key[key1…]\r\n
Return value: VALUE (key) (flg) (datalen) r n (data) r n.
Wherein, key word (key) is queued name, and data and the get method of the write of add method obtain Data be message content, labelling (flg) parameter is used for representing that this message is the need of compression, time limit (expire) parameter represents the effective time of this message, and datalen is data length.At message queue In, labelling (flg) parameter and time limit (expire) parameter can be dropped.
Fig. 1 is existing method flow schematic diagram based on persistent message queue transmission message.See Fig. 1, This flow process includes:
Step 101, message sends service logic and passes through Memcache add method, by message to be transmitted Write message queue;
In this step, message sends service logic and utilizes supertext pretreatment (PHP, Hypertext Preprocessor) language development.By increase (add) method of Memcache agreement, by message Write message queue, message queue is persistent message queue MemcacheQ.
Step 102, message processing service logic passes through Memcache get method, from message queue Read message to be transmitted to be transmitted;
In this step, message processing service logic utilizes PHP language development, according to disappearing of obtaining in advance Breath subscription information, obtains the message of each client subscription, generates configuration file, by Memcache get Method, actively initiates request to message queue, sequentially reads the message in message queue, according to configuration File, obtains the purpose client-side information that this message needs to send, is transmitted, by each client The message received is processed by application program.
Message queue, based on request-reply mode, receives the request that message processing service logic sends, should Answer message processing service logic, message is exported.
Step 103, it is complete that message queue confirms that message reads, and deletes this message in message queue.
In this step, message queue, based on request-reply mode, after message is read, triggers automatically This message is deleted from message queue.
From above-mentioned, existing method based on persistent message queue transmission message, due to message team Arrange based on request-reply mode, thus, message is once read out by message processing service logic, i.e. From message queue, directly delete the message of this reading.So, if message processing service logical AND is objective Transmission channel between the end of family is abnormal, or the application program of client occurs abnormal, such as, applies journey Sequence has been received by message, but is not yet successfully processed this message so that application program is not yet successfully processed This message, and message queue cannot learn whether application program is successfully processed acquired message, will Can cause this information drop-out, follow-up cannot continue from message queue, obtain this message and process, make Become the message cannot normal process so that Message Processing efficiency reduces.
Summary of the invention
Embodiments of the invention provide a kind of method based on persistent message queue transmission message, improve Message Processing efficiency.
Embodiments of the invention also provide for a kind of massage transmission device based on persistent message queue, carry High Message Processing efficiency.
For reaching above-mentioned purpose, the one that the embodiment of the present invention provides is transmitted based on persistent message queue The method of message, including:
Receive message to be transmitted, vernier information is set for message to be transmitted, and will vernier information be set Message write message queue;
According to the current vernier confirmation updating storage, obtain current message to be transmitted, from message team Row read current message to be transmitted, is transmitted;
Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored Vernier confirmation.
Wherein, described vernier information be set for message to be transmitted include:
Judge whether currently received message to be transmitted is the Article 1 message received, if it is, for connecing The message to be transmitted distribution vernier serial number received, and record the vernier sequence number information of distribution;If no It is that the vernier serial number of record is added up, cumulative vernier serial number is set for message to be transmitted, The vernier sequence number information that record is cumulative.
Wherein, described vernier information be set for message to be transmitted include:
Judge whether message queue exists the message of write, if it does not, to be transmitted for receive Message distribution vernier serial number;If it does, currently written into the vernier of message in acquisition message queue Sequence number information, adds up to the vernier serial number obtained, arranges cumulative trip for message to be transmitted Mark serial number.
Wherein, the message utilizing supertext pretreatment language development sends and treats described in service logic reception Transmission message.
Wherein, described by arrange vernier information message write message queue include:
Message sends service logic and passes through Memcache add method, will arrange the message of vernier serial number Write message queue.
Wherein, described after for message to be transmitted, vernier information is set, will the message of vernier information be set Before write message queue, farther include:
The message to be transmitted received is classified, message type information is set for message to be transmitted.
Wherein, described basis currently updates the vernier confirmation of storage, obtains current message to be transmitted Including:
If the current vernier confirmation updating storage be sky, by Memcache get method, from Message queue reads message to be transmitted foremost;
If currently having updated the vernier confirmation of storage not for empty, by true for the vernier updating storage The vernier serial number recognizing information corresponding adds up, by Memcache get method, from message queue The message to be transmitted that the cumulative vernier serial number of middle reading is corresponding.
Wherein, described from message queue, read current message to be transmitted, be transmitted including:
Pre-set and store the purpose client-side information that message to be transmitted needs to send, generate message Configuration file;
From message queue, read current message to be transmitted, obtain the configuration literary composition of this current message to be transmitted Part;
Purpose client-side information according to comprising in configuration file is transmitted.
Wherein, described method farther includes:
The vernier confirmation of storage is classified, true with the vernier that client receives for mark storage Recognize information.
Wherein, described after reading current message to be transmitted from message queue, obtain this and currently treat Before the configuration file of transmission message, farther include:
If current message to be transmitted is positioned in message queue foremost, perform to obtain this most to be transmitted The step of the configuration file of message;
If current message to be transmitted is not positioned in message queue foremost, according to current renewal storage Client belonging to vernier confirmation, sends current message to be transmitted to described vernier confirmation Affiliated client.
Wherein, described method farther includes:
After a message has been sent, timing is carried out;
If being not received by the vernier confirmation letter that client returns in the timing time pre-set Breath, retransmits message to be transmitted corresponding for currently stored vernier confirmation.
Wherein, described after a message has been sent, receive according to send message current to be transmitted return trip Before mark confirmation, farther include:
The client storage carrying out Message Processing processes the vernier confirmation that successful message is corresponding;
Receive message, obtain the vernier serial number received in message, it is judged that the vernier serial number in message With the vernier serial number comprised in the vernier confirmation of storage;
If the vernier serial number in message is identical with the vernier serial number of storage, or, in message Vernier serial number differs two or more and adds up unit with the vernier serial number of storage, abandons this message, to Message processing service logic returns the vernier confirmation of storage;
If the vernier serial number in message is more than one cumulative unit of vernier serial number of storage, process This message, after processing successfully, updates the vernier confirmation of storage, to message processing service logic Return the vernier confirmation updating storage.
Wherein, described method farther includes:
Confirming to have been received by the vernier confirmation that in message profile, each client returns, deletion disappears This message in breath queue.
A kind of massage transmission device based on persistent message queue, this device includes: message sends industry Business logic module and message processing service logic module, wherein,
Message sends business logic modules, is used for receiving message to be transmitted, arranges trip for message to be transmitted Mark information, and the message arranging vernier information is write message queue;
Message processing service logic module, for according to the current vernier confirmation updating storage, obtaining Take current message to be transmitted, from message queue, read current message to be transmitted, be transmitted;
Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored Vernier confirmation.
Described message processing service logic module is further used for confirmation and has been received by message profile The vernier confirmation that each client returns, deletes this message in message queue.
Described message processing service logic module includes: memory element, updating block, transmission message obtain Take unit and transmitting element, wherein,
Memory element, is used for storing vernier confirmation;
Updating block, for receiving the vernier confirmation returned according to the message current to be transmitted sent, Update the vernier confirmation of storage in memory element, to transmission message retrieval unit output trigger message;
Transmission message retrieval unit, is used for receiving trigger message, and the vernier according to current renewal storage is true Recognize information, obtain current message to be transmitted, from message queue, read current message to be transmitted, output To transmitting element;
Transmitting element, for obtaining the configuration file of the message current to be transmitted of reception, according to configuration literary composition The purpose client-side information comprised in part is transmitted.
Described message processing service logic module farther includes:
Timing unit, after sending message at transmitting element, carries out timing;
If in the timing time pre-set, monitor updating block and be not received by client and return The vernier confirmation returned, triggers transmission message retrieval unit by currently stored vernier confirmation pair The message to be transmitted answered retransmits.
Described message processing service logic module farther includes:
Judging unit, transmits the message current to be transmitted whether position that message retrieval unit obtains for judging In message queue foremost, if it is, trigger transmitting element according to the purpose comprised in configuration file Client-side information is transmitted;Otherwise, trigger transmitting element to confirm according to the current vernier updating storage Client belonging to information, sends current message to be transmitted to the visitor belonging to described vernier confirmation Family end.
As seen from the above technical solution, the one that the embodiment of the present invention provides is based on persistent message queue The method of transmission message and massage transmission device, receive message to be transmitted, arrange trip for message to be transmitted Mark information, and the message arranging vernier information is write message queue;According to the current trip updating storage Mark confirmation, obtains current message to be transmitted, reads current message to be transmitted from message queue, It is transmitted;Receive the vernier confirmation returned according to the message current to be transmitted sent, update and work as The vernier confirmation of front storage.So, by introducing message vernier information, it is read in message After, do not trigger and delete the flow process of this message in message queue, and the message arranging transmission is successfully being located After reason, return corresponding vernier confirmation, according to the vernier confirmation returned, determine that next is treated Transmission message, it is to avoid communication path is abnormal, or the application program of client is not yet being successfully processed this Occur abnormal during message, the follow-up problem that this message will be caused to cannot be carried out normal process, improve Message Processing efficiency.
Accompanying drawing explanation
In order to be illustrated more clearly that the embodiment of the present invention or technical scheme of the prior art, below by right In embodiment or description of the prior art, the required accompanying drawing used is briefly described.It should be evident that Accompanying drawing in below describing is only some embodiments of the present invention, for those of ordinary skill in the art For, it is also possible to other embodiment and accompanying drawing thereof is obtained according to these accompanying drawing illustrated embodiments.
Fig. 1 is existing method flow schematic diagram based on persistent message queue transmission message.
Fig. 2 is embodiment of the present invention method flow schematic diagram based on persistent message queue transmission message.
Fig. 3 is that embodiment of the present invention method idiographic flow based on persistent message queue transmission message shows It is intended to.
Fig. 4 is the service logic schematic flow sheet of embodiment of the present invention message sending end.
Fig. 5 is the service logic schematic flow sheet of embodiment of the present invention Message Processing end.
Fig. 6 is embodiment of the present invention massage transmission device based on persistent message queue structural representation.
Detailed description of the invention
Below with reference to accompanying drawing, the technical scheme of various embodiments of the present invention is carried out clear, complete retouching State, it is clear that described embodiment is only a part of embodiment of the present invention rather than whole Embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art are not making creativeness All other embodiments obtained by the premise of work, broadly fall into the scope that the present invention is protected.
Existing method based on persistent message queue transmission message, owing to message queue should based on request Answer mode, after message is read by message processing service logic, will the message of this reading directly from disappearing Breath queue is deleted, thus, if communication path is abnormal, or the application program of client is not yet becoming Occur abnormal when merit processes this message, follow-up this message will be caused to cannot be carried out normal process so that Message Processing efficiency reduces.
Further, current message processing service logic, use the PHP journey of an endless loop Sequence, uses the get method of Memcache agreement, continuously attempts to the message queue from mcq in the circulating cycle Middle acquisition message, carries out message transmission, but PHP program circulates execution for a long time after getting message, will Collapse may be caused, or, when business changes, and restarts message processing program temporarily, Will result in information drop-out.So, higher to data security requirement in the business using message queue In the case of, service exception not only results in the efficiency of execution business to be reduced, and also reduces the industry of user Business is experienced, and the reliability of message transmission reduces.
In the embodiment of the present invention, it is considered to the message in message queue is arranged vernier, is read in message After, processing, if do not received, the vernier confirmation that the application program of this message returns, not deleting This message, and the application program self processing message also stores the vernier information processing successful message, According to the vernier information comprised in the vernier information stored and reception message, carry out vernier exchange and process The message received, thus, exchange based on vernier, it is proposed that a kind of method of message reliable delivery.Tool For body, message sends service logic and still uses the add method of mcq to write in message queue to disappear Breath, but introduce message vernier (id), the message of write is marked, i.e. message sends service logic Receive the message issued from the webserver, distribute one for this message in advance and certainly increase id, such as, Can send, according to message, the order of message that service logic receives be allocated, id from the beginning of 1, It is 64 unsigned longs to the maximum.The message carrying vernier information is write message queue.So, By message id, can be with this message of a labelling absolute position in current message queue;For disappearing Breath queue, is arranged on after message read, does not trigger and delete the flow process of this message in message queue, And according to the vernier confirmation of the application program return processing this message received, active push disappears Lower a piece of news in breath queue.
It is preferred that the embodiment of the present invention is applied in asynchronous submission system.
Fig. 2 is embodiment of the present invention method flow schematic diagram based on persistent message queue transmission message. Seeing Fig. 2, this flow process includes:
Step 201, receives message to be transmitted, arranges vernier information for message to be transmitted, and will arrange trip The message write message queue of mark information;
In this step, it is preferred that sent service logic by message to receive message to be transmitted, wherein, disappear Breath sends service logic and utilizes supertext pretreatment language development, and message queue is persistent message team Row MemcacheQ, message to be transmitted can Shi Ge operator according to the needs of migration efficiency, by fortune Battalion's business's server issues.
In the embodiment of the present invention, vernier information is vernier serial number.Certainly, in actual application, vernier Information can also be other information, as long as ensureing that the vernier information arranged for each message is different As long as i.e. can uniquely identify message.
Arrange vernier information for message to be transmitted to include:
Judge whether currently received message to be transmitted is the Article 1 message received, if it is, for connecing The message to be transmitted distribution vernier serial number received, and record the vernier sequence number information of distribution;If no It is that the vernier serial number of record is added up, cumulative vernier serial number is set for message to be transmitted, The vernier sequence number information that record is cumulative.
In this step, message sends service logic and judges whether the message to be transmitted received is that Article 1 disappears Breath, if it is, initial vernier serial number is distributed to this message, and records the vernier sequence of this distribution Number information, receives new information if follow-up, then carried out by the vernier serial number of the previous message received Cumulative, as the vernier serial number of current newly received message.Such as, vernier serial number is sequentially added by 1, If the initial vernier Serial No. 1 that the Article 1 message arranged is corresponding, then the message of receipt of subsequent is corresponding Vernier serial number, be sequentially 2,3,4 ....
It is preferred that in the embodiment of the present invention, vernier serial number uses 64 unsigned long characters to enter Row record.
Certainly, in actual application, arranging vernier information for message to be transmitted can also include:
Judge whether message queue exists the message of write, if it does not, to be transmitted for receive Message distribution vernier serial number;If it does, currently written into the vernier of message in acquisition message queue Sequence number information, adds up to the vernier serial number obtained, arranges cumulative trip for message to be transmitted Mark serial number.
In this step, utilizing message in message queue is sequentially write the feature according to FIFO, The message write at first is positioned at message queue position earlier above, thus, message sends service logic and is connecing When receiving message to be transmitted, whether query messages queue has the message of write, if it did not, show The message to be transmitted being currently received is Article 1 message;If message queue has the message of write, Then can be according to the vernier sequence number information carried in the message of the last time write, for being currently received Message to be transmitted corresponding vernier serial number is set.
The message arranging vernier information is write message queue include:
Message sends service logic and passes through Memcache add method, will arrange the message of vernier serial number Write message queue.
In this step, utilize the message of PHP language development to send service logic, pass through Memcache Increase (add) method of agreement, writes message queue by the message being provided with vernier serial number MemcacheQ。
So, follow-up in, according to vernier serial number, can easily determine corresponding the disappearing of vernier serial number Breath position in message queue.
In the embodiment of the present invention, it is also possible to message queue is identified, such as, message queue is used Title uniquely identifies message queue.
Further, after vernier information is set for message to be transmitted, will the message of vernier information be set Before write message queue, farther include:
The message to be transmitted received is classified, message type information is set for message to be transmitted.
In this step, it is also possible to according to the message category strategy pre-set, the message received is carried out Classification, and the message type information of classification is carried in the message.
Step 202, according to the current vernier confirmation updating storage, obtains current message to be transmitted, From message queue, read current message to be transmitted, be transmitted;
In this step, message processing service logic the message in message queue is read.
According to the current vernier confirmation updating storage, obtain current message to be transmitted and include:
If the current vernier confirmation updating storage be sky, by Memcache get method, from Message queue reads message to be transmitted foremost;
In this step, the application program pre-setting client is receiving message, and successfully locates After reason, need to return vernier confirmation, true to update the vernier of storage in message processing service logic Recognize message, and after confirming to update, trigger the step performing to obtain current message to be transmitted.If worked as The front vernier confirmation updating storage is empty, shows that not reading message from message queue carries out sending out Send.
If currently having updated the vernier confirmation of storage not for empty, by true for the vernier updating storage The vernier serial number recognizing information corresponding adds up, by Memcache get method, from message queue The message to be transmitted that the cumulative vernier serial number of middle reading is corresponding.
In this step, message processing service logic is set from message queue, reads message, through sending, After being received by the application program of client and be successfully processed, return trip to message processing service logic Mark confirmation, vernier confirmation is the confirmation to the vernier serial number carried in message, at message After reason service logic receives vernier confirmation, store, show that the application program of client becomes Merit has processed this message, can carry out the process of next message.
From message queue, read current message to be transmitted, be transmitted including:
Pre-set and store the purpose client-side information that message to be transmitted needs to send, generate message Configuration file;
From message queue, read current message to be transmitted, obtain the configuration literary composition of this current message to be transmitted Part;
Purpose client-side information according to comprising in configuration file is transmitted.
In this step, message processing service logic utilizes PHP language development, according to disappearing of obtaining in advance Breath subscription information, such as, the information that carrier server issues, obtain each client subscribing to message Information, as purpose client, generates configuration file, the most to be transmitted reading from message queue After message, according to the configuration file of this message, obtain the purpose client-side information that this message needs to send, It is transmitted, finally by the application program of each client, the message received is processed.
It is preferred that in actual application, due to the message in queue, according to the letter comprised in configuration file Breath, may send to a client, it is also possible to sending to multiple clients, each client is connecing After receiving message, the speed that processes due to it also differs, thus, the vernier confirmation of return is also And asynchronous, process demand to meet this differentiation of each client, return in each client After vernier confirmation, can ensure that timely receiving lower a piece of news processes, the method is all right Farther include:
The vernier confirmation of storage is classified, true with the vernier that client receives for mark storage Recognize information.
So, after reading current message to be transmitted from message queue, this is obtained the most to be transmitted Before the configuration file of message, farther include:
If current message to be transmitted is positioned in queue foremost, perform to obtain this current message to be transmitted The step of configuration file;
If current message to be transmitted is not positioned in queue foremost, according to the current vernier updating storage Client belonging to confirmation, sends current message to be transmitted to belonging to described vernier confirmation Client.
In this step, after receiving the vernier confirmation that a certain client returns, true according to vernier Recognize the client-side information carried in information, update the vernier confirmation being mark with client of storage, And send next message to this client.
In actual application, if message processing service logic does not connect in the timing time pre-set Receive the vernier confirmation that client returns, then currently stored vernier confirmation cannot be carried out Update, it is believed that be that the message sent occurs in that exception, need to resend message.Thus, The method farther includes:
After a message has been sent, timing is carried out;
If being not received by the vernier confirmation letter that client returns in the timing time pre-set Breath, retransmits message to be transmitted corresponding for currently stored vernier confirmation.
In this step, message processing service logic after a message has been sent, logical due between client Letter is abnormal, or, after the application program of client receives message, during processing message by In exception, or, after the application program of client receives message, after being successfully processed message, return Migrate and mark confirmation, due to the communication abnormality between message processing service logic, all will make message Process service logic and do not receive vernier confirmation.
Step 203, receives the vernier confirmation returned according to the message current to be transmitted sent, and updates Currently stored vernier confirmation.
In this step, the application program of client after receiving message and message be successfully processed, Return the vernier confirmation carrying client-side information to message processing service logic, receive vernier After confirmation, according to the client-side information carried in vernier confirmation, update with client for mark Know the vernier confirmation of storage.In the updated, execution step 202 is automatically triggered, with to this client Send next message.In this manner it is achieved that actively read message from message queue, thus realize to The purpose of client active push message.
It is preferred that in order to effectively prevent message processing service logic send message time, in message Vernier information is modified, and causes message processing service logic to confirm at the vernier returned according to client When information carries out the transmission of lower a piece of news, may leak through or repeat to send message, such as, if will Vernier serial number in message reduces, then cause repeating to send;If by the vernier serial number in message Increase, then cause some message leaking through in message queue.Thus, in the embodiment of the present invention, sending out After sending message, before receiving according to the vernier confirmation of the message current to be transmitted return sent, enter One step includes:
The client storage carrying out Message Processing processes the vernier confirmation that successful message is corresponding;
Receive message, obtain the vernier serial number received in message, it is judged that the vernier serial number in message With the vernier serial number comprised in the vernier confirmation of storage;
If the vernier serial number in message is identical with the vernier serial number of storage, or, in message Vernier serial number differs two or more and adds up unit with the vernier serial number of storage, abandons this message, to Message processing service logic returns the vernier confirmation of storage;
In this step, if the vernier serial number in message is identical with the vernier serial number of storage, show The last vernier confirmation returned to message processing service logic of this client does not successfully arrive at and disappears Breath processes service logic, and message processing service logic has retransmitted this message after timing time-out, and this disappears Breath is successfully processed by client, and have recorded the successful vernier confirmation of process.
If it is cumulative single that the vernier serial number in message differs two or more with the vernier serial number of storage Position, shows at message processing service logic, is changed the message sent, will cause message Can not sequentially process, it is then desired to notification message processes service logic, the most successful from client After the message processed, the most sequentially send message.
If the vernier serial number in message is more than one cumulative unit of vernier serial number of storage, process This message, after processing successfully, updates the vernier confirmation of storage, to message processing service logic Return the vernier confirmation updating storage.
So, in the message sent, vernier information, client are carried by message processing service logic Processing after success message, storing the vernier information of this message, client is by the message that will receive Vernier information compares with the vernier information self stored, it is achieved with the trip of message processing service logic Mark exchange, it is ensured that message processes in strict accordance with order.
In actual application, the method can further include:
Step 204, confirms to have been received by the vernier confirmation letter that in message profile, each client returns Breath, deletes this message in message queue.
Fig. 3 is that embodiment of the present invention method idiographic flow based on persistent message queue transmission message shows It is intended to.Seeing Fig. 3, this flow process includes:
Step 301, message sends service logic and passes through Memcache add method, by message to be transmitted Send to message sink end;
In this step, message sends service logic and uses PHP language development, during message read-write, Including for write message message sink end and for message read message sending end.
Step 302, message is write persistence disk and stores by message sink end;
In this step, persistence disk is message queue.
Step 303, message sending end reads message from persistence disk;
In this step, message sending end, according to currently stored vernier confirmation, reads message.
Step 304, the message of reading is pushed to message processing service logic by message sending end;
In this step, message sending end determines according to the vernier confirmation of message profile or reception The purpose client that message sends.
Step 305, message processing service logic sends message, and receives vernier confirmation, and output is extremely Message sending end.
In this step, message sending end records the vernier information of currently transmitted the last item message, Message Processing end (application program of client) also can record the vernier information processing successful message.
When there is the message needing to send in message queue, message is read in by message sending end from disk Internal memory (mcpost protocol realization use linux kernel provide sendfile mechanism, directly by message from Kernel is sent to network, it is not necessary to read in internal memory), and message is sent by message processing service logic To Message Processing end, Message Processing end, after having received message, processes, until message is correctly located Manage complete, just can record the vernier information of this message and send response (POSTED).
In the embodiment of the present invention, after user revises the vernier information of message sending end without authorization, transmission disappears After breath, Message Processing end is by checking the vernier value of information in current message and the local vernier recorded Whether the value of information mates, if it does not match, return the vernier value of information that this locality is recorded, message is sent out The vernier value of information that sending end then can be returned according to Message Processing end, calculates message offset and searches correspondence Message be transmitted, this process is referred to as vernier exchange process.
When carrying out message transmission, it is also possible to carry the type information of message further, and check, In the embodiment of the present invention, the agreement of use can be self-defining internal agreement, and employing is similar to The Extended Protocol of Memcache agreement;And can support http agreement, and can according to application need into Row Extended Protocol is developed.For example, its form can be:
post(key)(qname)(last)(curr)(datalen)\r\n(data)\r\n
Return value: POSTED or carry out nearest (last) value of vernier exchange, i.e. carries in message The vernier value of information.
Fig. 4 is the service logic schematic flow sheet of embodiment of the present invention message sending end.See Fig. 4, should Flow process includes:
Step 401, reads the current vernier confirmation updated;
Step 402, according to the current vernier confirmation updated, calculates current message to be transmitted and reads in Internal memory;
Step 403, sends message;
Step 404, timing, it is judged that whether receive response in the timing time pre-set, if It is, it is judged that the vernier confirmation carried in response is return value or vernier exchange, if returning Value, performs step 405;If vernier exchange, perform step 406;Otherwise, step 407 is performed;
In this step, return value is POSTED.
Step 405, is updated to return value by the vernier confirmation of storage, returns and performs step 402;
Step 406, is updated to vernier crossing-over value by the vernier confirmation of storage, returns and performs step 402;
Step 407, time-out is retransmitted message, is returned and perform step 403.
Fig. 5 is the service logic schematic flow sheet of embodiment of the present invention Message Processing end.See Fig. 5, should Flow process includes:
Step 501, Message Processing end receives message;
Step 502, checks that the vernier value of information that the vernier value of information in current message and this locality are recorded is No coupling, if do not mated, performs step 503, if it does, perform step 504;
This step carries out vernier inspection.
Step 503, carries out vernier exchange, returns the vernier value of information that this locality is recorded;
Step 504, carries out Message Processing, it is judged that Message Processing is the most successful, if it is, perform step 505, otherwise, perform step 506;
Step 505, returns response, carries the successful return value (POSTED) of process;
Step 506, Message Processing failure, terminates flow process.
From above-mentioned, the method based on persistent message queue transmission message of the embodiment of the present invention, By introduce message vernier information, after message is read, do not trigger deletion message queue in this disappears The flow process of breath, and the message of transmission is set after being successfully processed, return corresponding vernier confirmation, According to the vernier confirmation returned, determine next message to be transmitted, do not receiving vernier confirmation letter During breath, retransmit message, it is to avoid communication path is abnormal, or the application program of client is the most successful Occur abnormal when processing this message, the follow-up problem that this message will be caused to cannot be carried out normal process, Improve Message Processing efficiency;Further, vernier exchanging mechanism is used, compared to traditional message Transmission method, vernier exchanging mechanism can ensure that the whole transfer process of message has tighter affairs Property, prevent message sending end from arbitrarily distorting message id, and ensure that the operation layer data of Message Processing end are tight Lattice process in order, prevent information drop-out, improve the reliability of message transmission, also improve use The business experience at family.
Fig. 6 is embodiment of the present invention massage transmission device based on persistent message queue structural representation. Seeing Fig. 6, this massage transmission device includes: message sends business logic modules and message processing service Logic module, wherein,
Message sends business logic modules, is used for receiving message to be transmitted, arranges trip for message to be transmitted Mark information, and the message arranging vernier information is write message queue;
In the embodiment of the present invention, vernier information is set for message to be transmitted and may is that
Judge whether currently received message to be transmitted is the Article 1 message received, if it is, for connecing The message to be transmitted distribution vernier serial number received, and record the vernier sequence number information of distribution;If no It is that the vernier serial number of record is added up, cumulative vernier serial number is set for message to be transmitted, The vernier sequence number information that record is cumulative.
For message to be transmitted, vernier information is set it may also is that
Judge whether message queue exists the message of write, if it does not, to be transmitted for receive Message distribution vernier serial number;If it does, currently written into the vernier of message in acquisition message queue Sequence number information, adds up to the vernier serial number obtained, arranges cumulative trip for message to be transmitted Mark serial number.
Message processing service logic module, for according to the current vernier confirmation updating storage, obtaining Take current message to be transmitted, from message queue, read current message to be transmitted, be transmitted;
Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored Vernier confirmation.
It is preferred that message processing service logic module is further used for confirmation has been received by message arrangement literary composition The vernier confirmation that in part, each client returns, deletes this message in message queue.
Wherein,
Message processing service logic module includes: memory element, updating block, transmission message obtain single Unit and transmitting element (not shown), wherein,
Memory element, is used for storing vernier confirmation;
Updating block, for receiving the vernier confirmation returned according to the message current to be transmitted sent, Update the vernier confirmation of storage in memory element, to transmission message retrieval unit output trigger message;
Transmission message retrieval unit, is used for receiving trigger message, and the vernier according to current renewal storage is true Recognize information, obtain current message to be transmitted, from message queue, read current message to be transmitted, output To transmitting element;
Transmitting element, for obtaining the configuration file of the message current to be transmitted of reception, according to configuration literary composition The purpose client-side information comprised in part is transmitted.
In the embodiment of the present invention, in transmitting element, pre-set and store joining of each message to be transmitted Put file, in configuration file, be configured with the purpose client-side information that message to be transmitted needs to send.
It is preferred that message processing service logic module farther includes:
Timing unit, after sending message at transmitting element, carries out timing;
If in the timing time pre-set, monitor updating block and be not received by client and return The vernier confirmation returned, triggers transmission message retrieval unit by currently stored vernier confirmation pair The message to be transmitted answered retransmits.
Wherein,
Client storage processes the vernier confirmation that successful message is corresponding;
Receive message, obtain the vernier serial number received in message, it is judged that the vernier serial number in message With the vernier serial number comprised in the vernier confirmation of storage;
If the vernier serial number in message is identical with the vernier serial number of storage, or, in message Vernier serial number differs two or more and adds up unit with the vernier serial number of storage, abandons this message, to Message processing service logic returns the vernier confirmation of storage;
If the vernier serial number in message is more than one cumulative unit of vernier serial number of storage, process This message, after processing successfully, updates the vernier confirmation of storage, to message processing service logic Return the vernier confirmation updating storage.
It is preferred that message processing service logic module can further include:
Judging unit, transmits the message current to be transmitted whether position that message retrieval unit obtains for judging In message queue foremost, if it is, trigger transmitting element according to the purpose comprised in configuration file Client-side information is transmitted;Otherwise, trigger transmitting element to confirm according to the current vernier updating storage Client belonging to information, sends current message to be transmitted to the visitor belonging to described vernier confirmation Family end.
Obviously, those skilled in the art can carry out various change and modification without deviating from this to the present invention The spirit and scope of invention.So, if these amendments and modification to the present invention belong to present invention power Profit requires and within the scope of equivalent technologies, then the present invention also comprises these change and modification.

Claims (15)

1. a method based on persistent message queue transmission message, it is characterised in that the method bag Include:
Receive message to be transmitted, vernier information is set for message to be transmitted, and will vernier information be set Message write message queue;
According to the current vernier confirmation updating storage, obtain current message to be transmitted, from message team Row read current message to be transmitted, is transmitted;
Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored Vernier confirmation;Wherein,
Described basis currently updates the vernier confirmation of storage, obtains current message to be transmitted, from disappearing Current message to be transmitted is read in breath queue, is transmitted including:
If the current vernier confirmation updating storage be sky, by Memcache get method, from Message queue reads message to be transmitted foremost;
If the current vernier confirmation updating storage is not empty, the vernier updating storage is confirmed Vernier serial number corresponding to information adds up, by Memcache get method, from message queue Read the message to be transmitted that cumulative vernier serial number is corresponding;
Pre-set and store the purpose client-side information that message to be transmitted needs to send, generate message Configuration file;
From message queue, read current message to be transmitted, obtain the configuration literary composition of this current message to be transmitted Part;
Purpose client-side information according to comprising in configuration file is transmitted.
Method the most according to claim 1, wherein, described for message to be transmitted arrange vernier letter Breath includes:
Judge whether currently received message to be transmitted is the Article 1 message received, if it is, for connecing The message to be transmitted distribution vernier serial number received, and record the vernier sequence number information of distribution;If no It is that the vernier serial number of record is added up, cumulative vernier serial number is set for message to be transmitted, The vernier sequence number information that record is cumulative.
Method the most according to claim 1, wherein, described for message to be transmitted arrange vernier letter Breath includes:
Judge whether message queue exists the message of write, if it does not, to be transmitted for receive Message distribution vernier serial number;If it does, currently written into the vernier of message in acquisition message queue Sequence number information, adds up to the vernier serial number obtained, arranges cumulative trip for message to be transmitted Mark serial number.
4. according to the method described in any one of claims 1 to 3, wherein, utilize supertext to locate in advance The message of reason language development sends service logic and receives described message to be transmitted.
Method the most according to claim 4, wherein, described writes the message arranging vernier information Enter message queue to include:
Message sends service logic and passes through Memcache add method, will arrange the message of vernier serial number Write message queue.
Method the most according to claim 5, wherein, described for message to be transmitted arrange vernier letter After breath, before the message arranging vernier information is write message queue, farther include:
The message to be transmitted received is classified, message type information is set for message to be transmitted.
Method the most according to claim 3, wherein, described method farther includes:
The vernier confirmation of storage is classified, true with the vernier that client receives for mark storage Recognize information.
Method the most according to claim 7, wherein, described reading from message queue is currently treated After transmission message, before obtaining the configuration file of this current message to be transmitted, farther include:
If current message to be transmitted is positioned in message queue foremost, perform to obtain this most to be transmitted The step of the configuration file of message;
If current message to be transmitted is not positioned in message queue foremost, according to current renewal storage Client belonging to vernier confirmation, sends current message to be transmitted to described vernier confirmation Affiliated client.
Method the most according to claim 8, wherein, described method farther includes:
After a message has been sent, timing is carried out;
If being not received by the vernier confirmation letter that client returns in the timing time pre-set Breath, retransmits message to be transmitted corresponding for currently stored vernier confirmation.
10. according to the method described in any one of claims 1 to 3, wherein, after described transmission message, Before receiving according to the vernier confirmation of the message current to be transmitted return sent, farther include:
The client storage carrying out Message Processing processes the vernier confirmation that successful message is corresponding;
Receive message, obtain the vernier serial number received in message, it is judged that the vernier serial number in message With the vernier serial number comprised in the vernier confirmation of storage;
If the vernier serial number in message is identical with the vernier serial number of storage, or, in message Vernier serial number differs two or more and adds up unit with the vernier serial number of storage, abandons this message, to Message processing service logic returns the vernier confirmation of storage;
If the vernier serial number in message is more than one cumulative unit of vernier serial number of storage, process This message, after processing successfully, updates the vernier confirmation of storage, to message processing service logic Return the vernier confirmation updating storage.
11. methods according to claim 10, wherein, described method farther includes:
Confirming to have been received by the vernier confirmation that in message profile, each client returns, deletion disappears This message in breath queue.
12. 1 kinds of massage transmission devices based on persistent message queue, it is characterised in that this device Including: message transmission business logic modules and message processing service logic module, wherein,
Message sends business logic modules, is used for receiving message to be transmitted, arranges trip for message to be transmitted Mark information, and the message arranging vernier information is write message queue;
Message processing service logic module, for according to the current vernier confirmation updating storage, obtaining Take current message to be transmitted, from message queue, read current message to be transmitted, be transmitted;
Receive the vernier confirmation returned according to the message current to be transmitted sent, update currently stored Vernier confirmation;
Described message processing service logic module includes: memory element, updating block, transmission message obtain Take unit and transmitting element, wherein,
Memory element, is used for storing vernier confirmation;
Updating block, for receiving the vernier confirmation returned according to the message current to be transmitted sent, Update the vernier confirmation of storage in memory element, to transmission message retrieval unit output trigger message;
Transmission message retrieval unit, is used for receiving trigger message, and the vernier according to current renewal storage is true Recognize information, obtain current message to be transmitted, from message queue, read current message to be transmitted, output To transmitting element;
Transmitting element, for obtaining the configuration file of the message current to be transmitted of reception, according to configuration literary composition The purpose client-side information comprised in part is transmitted.
13. devices according to claim 12, it is characterised in that described message processing service is patrolled Collect module to be further used for confirming that having been received by the vernier that in message profile, each client returns confirms Information, deletes this message in message queue.
14. devices according to claim 13, it is characterised in that described message processing service is patrolled Collect module to farther include:
Timing unit, after sending message at transmitting element, carries out timing;
If in the timing time pre-set, monitor updating block and be not received by client and return The vernier confirmation returned, triggers transmission message retrieval unit by currently stored vernier confirmation pair The message to be transmitted answered retransmits.
15. devices according to claim 13, it is characterised in that described message processing service is patrolled Collect module to farther include:
Judging unit, transmits the message current to be transmitted whether position that message retrieval unit obtains for judging In message queue foremost, if it is, trigger transmitting element according to the purpose comprised in configuration file Client-side information is transmitted;Otherwise, trigger transmitting element to confirm according to the current vernier updating storage Client belonging to information, sends current message to be transmitted to the visitor belonging to described vernier confirmation Family end.
CN201210340047.3A 2012-09-13 2012-09-13 Method based on persistent message queue transmission message and massage transmission device Active CN102890631B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210340047.3A CN102890631B (en) 2012-09-13 2012-09-13 Method based on persistent message queue transmission message and massage transmission device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210340047.3A CN102890631B (en) 2012-09-13 2012-09-13 Method based on persistent message queue transmission message and massage transmission device

Publications (2)

Publication Number Publication Date
CN102890631A CN102890631A (en) 2013-01-23
CN102890631B true CN102890631B (en) 2016-12-07

Family

ID=47534140

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210340047.3A Active CN102890631B (en) 2012-09-13 2012-09-13 Method based on persistent message queue transmission message and massage transmission device

Country Status (1)

Country Link
CN (1) CN102890631B (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103761141A (en) * 2013-12-13 2014-04-30 北京奇虎科技有限公司 Method and device for realizing message queue
CN104408132B (en) * 2014-11-28 2018-03-02 北京京东尚科信息技术有限公司 Data push method and system
CN104506948B (en) * 2014-12-25 2018-10-23 深圳市九洲电器有限公司 A kind of message delivery method between middleware and user interface and system
CN105072016B (en) * 2015-07-03 2019-07-02 北京京东尚科信息技术有限公司 For carrying out the method and apparatus for sorting out processing to message
CN106953884A (en) * 2016-01-07 2017-07-14 中移(杭州)信息技术有限公司 Middleware message treatment method, device and middleware platform
CN106375462B (en) * 2016-09-13 2019-05-10 北京百度网讯科技有限公司 The method and device of message duration is realized in distributed information system
CN107885671B (en) * 2016-09-30 2021-09-14 华为技术有限公司 Nonvolatile memory persistence method and computing device
CN107872506B (en) * 2017-08-09 2021-04-02 成都萌想科技有限责任公司 Broadcasting method based on real-time message
CN107943597A (en) * 2017-08-11 2018-04-20 成都萌想科技有限责任公司 A kind of thread-safe message queue based on memcache
CN109819000A (en) * 2017-11-22 2019-05-28 航天信息股份有限公司 Methods, devices and systems and machine readable storage medium for PUSH message
CN108874560B (en) * 2018-06-05 2022-09-09 腾讯音乐娱乐科技(深圳)有限公司 Method and communication device for communication
CN109688195B (en) * 2018-11-16 2022-05-20 武汉华中时讯科技有限责任公司 Device, method and storage medium for realizing asynchronous information release
CN110224933A (en) * 2019-06-18 2019-09-10 成都品果科技有限公司 A kind of message distributing system
CN110232054B (en) * 2019-06-19 2021-07-20 北京百度网讯科技有限公司 Log transmission system and streaming log transmission method
CN112448898A (en) * 2019-08-28 2021-03-05 无锡江南计算技术研究所 Message order-preserving method based on sequence number mechanism

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101316221B (en) * 2007-05-30 2012-04-04 华为终端有限公司 Notification message processing method and equipment
CN102023974B (en) * 2009-09-14 2012-08-22 中国移动通信集团公司 Method, device and system for processing message by message queue

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8023408B2 (en) * 2004-11-19 2011-09-20 International Business Machines Corporation Dynamically changing message priority or message sequence number

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101316221B (en) * 2007-05-30 2012-04-04 华为终端有限公司 Notification message processing method and equipment
CN102023974B (en) * 2009-09-14 2012-08-22 中国移动通信集团公司 Method, device and system for processing message by message queue

Also Published As

Publication number Publication date
CN102890631A (en) 2013-01-23

Similar Documents

Publication Publication Date Title
CN102890631B (en) Method based on persistent message queue transmission message and massage transmission device
CN107592351B (en) Multi-user publishing and subscribing method and system based on Redis
CN102027461B (en) Extended messaging platform
US20160335287A1 (en) Stream computing system and method
CN104468395A (en) Direct-broadcasting-room channel access method and system
CN104092717A (en) Message processing method and system, message destination end device and distributed message system
JP6686033B2 (en) Method and apparatus for pushing messages
CN101651526B (en) Method for transmitting messages between network equipment
CN105119810A (en) Instant communication method based on XMPP protocol and system thereof
CN104683216A (en) Forwarding method and forwarding device for customer service information as well as customer service system
GB2589211A (en) Methods and systems of using remote subscriber identification modules at device
CN103546771B (en) A kind of TV programme comment processing method and system based on intelligent terminal
JP2011171867A (en) Data storage method and mail relay method of data store server in mail system
CN110968431A (en) Message processing method, device and equipment
CN110401711A (en) Data processing method, device, system and storage medium
CN101453487A (en) Memory to storage communication for hybrid systems
CN112887196B (en) Message sending method, system, device, equipment and readable storage medium
CN103684707A (en) Server-side and user-side message transmission processing method, message transmission method and message transmission system
CN106506124A (en) Retransmit message and determine method and device
CN112559219A (en) Internet of things offline message management method, device, equipment and storage medium
CN112150203A (en) Real estate client visit identification method and device, electronic equipment and storage medium
US20100131465A1 (en) Method for duplicating a database in a network of machines, and system of machines comprising a duplicated database
US20190379758A1 (en) Multicasting method in distributed cache environment, and distributed cache server using the same
CN102238206A (en) Image file packet retransmission method
CN101001213A (en) Short message transmission system and method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20230410

Address after: Room 501-502, 5/F, Sina Headquarters Scientific Research Building, Block N-1 and N-2, Zhongguancun Software Park, Dongbei Wangxi Road, Haidian District, Beijing, 100193

Patentee after: Sina Technology (China) Co.,Ltd.

Address before: 100080, International Building, No. 58 West Fourth Ring Road, Haidian District, Beijing, 20 floor

Patentee before: Sina.com Technology (China) Co.,Ltd.

TR01 Transfer of patent right