A kind of method and system that message sink and forwarding are realized based on message queue
Technical field
The present invention relates to field of data communication, and in particular to a kind of side that message sink and forwarding are realized based on message queue
Method and system.
Background technology
During government or enterprise application system construction and system combination, generally use message-oriented middleware handle is distributed in net
The autonomous, information system of isomery is effectively integrated integrated system to network everywhere.Existing message-oriented middleware is generally used with number
It is the working mechanism of data switching center according to swap server, message sending end transmits the message to data exchange server, number
Forward messages to message sink end again according to swap server, the advantage is that client only needs to be interacted with server, disappear
Breath transmitting terminal and message sink end need not be simultaneously online, and message sending end and message sink end need not directly be set up by connecting
The transmission of row message.
In the prior art, when message is received, the message to message sink end to be forwarded is resided in data exchange server
In internal memory, or message is stored in database or file system.The drawbacks of by message deposit in internal memory is memory source
Always limited, data exchange server will be occupied full in a large amount of situations for receiving, forwarding message, message queue, and follow-up disappears
Breath cannot be deposited into message queue and is dropped, and cause to transmit the loss of data, and if there is power down, system exception collapse
Etc. emergency case, even if the message of write-in message queue can also lose.If message is stored in into database or file system
In external storage system, message forwarding needs to be read from External memory equipment, because External memory equipment access speed is slow, meeting
The performance bottleneck for causing message to be transmitted.
Application No. 200810239601.2, Publication No. CN101431476, it is entitled " one kind be based on message team
The Chinese patent application of the data transmission method of row, server and system ",(Apply for the artificial limited public affairs of Industrial and Commercial Bank of China's share
Department), disclose a kind of by receiving message queue and sending the method that message queue carries out message sink, forwarding, in the method
Receive message queue and send message queue in internal memory, it is impossible to ensure the reliability of message transmission.
Application No. 200680023379.1, Publication No. CN101208671, entitled " managing message queues "
Chinese patent application(Apply for artificial Initio Software Corp. AB), there is provided a kind of side for writing data into multiple queues
Method, corresponding software and system, each section of wherein data are written to a corresponding queue.Although the method is by each team
Row are synchronized to nonvolatile memory, but the data on nonvolatile memory are the mirror images of data in memory queue, this
The ability that mode processes message is decided by memory size.
Application No. 200910092421.0, Publication No. CN102023974A, it is entitled " one kind pass through message team
The Chinese patent application of the methods, devices and systems of column processing message "(Applicant China Mobile Communications Corporation), in internal memory
In introduce first message queue for receiving message, introducing the second message queue is used to consume message, and message is stored in
In database.This mode message sink and treatment two message queues of needs are resided in internal memory, and also rely on database
Message is sent to the second message queue by trigger from first queue, and this mode is operated by database trigger, place
Reason is complicated;When message is sent into second queue from first queue, it is related to data base read-write to operate, poor-performing..
Message of the other prior art in direct forwarding queue in message forwarding queue, because message forwarding speed is relied on
The combination property of the computer at the network bandwidth and operation message sink end, forwarding message generally needs to take some time, and
In message forwarding process, it usually needs lockout message forwarding queue, it is impossible to forwarded the need for being stored in newly toward message forwarding queue
Message, this can cause system internal resources to block, cause message forwarding performance decline, influence message transmission real-time.Cause
This, prior art cannot meet the demand that enterprise application system size of message is big, require data efficient, transmitting.
The content of the invention
For defect present in prior art, message is realized based on message queue it is an object of the invention to provide one kind
The method and system with forwarding are received, real-time and the transmission of messaging are improve while message transmission reliability is ensured
Performance.
To achieve the above object, the technical solution adopted by the present invention is as follows:
A kind of method that message sink and forwarding are realized based on message queue, is comprised the following steps:
(1)Message sending end sends a message to data exchange server;
(2)After data exchange server receives the message of message sending end, according to the routing configuration information of the message,
Determine the message sink end of the message;The message sink end is one or more;
(3)The message to be forwarded that data exchange server will be received is saved in corresponding to each message sink end respectively
In external memory message queue;The external memory message queue is stored in external non-volatile storage device;
(4)Internal memory message queue of the data exchange server by the message deposit to be forwarded corresponding to message sink end
In;
(5)The message to be forwarded in internal memory message queue is extracted, and the message to be forwarded is transmitted to internal memory message team
The corresponding message sink end of row.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, data exchange clothes
For it creates internal memory message queue when business device forwards message to certain message sink end first, each message sink end correspondence is unique
Internal memory message queue.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(3)With step
Suddenly(4)Between it is further comprising the steps of:
(3-4)Data exchange server judges message sink end with the presence or absence of corresponding internal memory message queue, if then entering
Enter step(4)If otherwise data exchange server is to enter step after message sink end creates internal memory message queue(4).
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, is creating internal memory
During message queue, the message queue capacity of internal memory message queue is set, the message queue capacity is by message number and message count
Determined according to amount.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(4)In,
Before the internal memory message queue that be saved in message to be forwarded corresponding to message sink end by data exchange server, this is first determined whether
Whether the internal memory message queue at message sink end is busy, if otherwise directly performing step(4)If, then one in the presence of checking whether
Message sink end, if then obtaining next message sink end enters step(3)If otherwise treatment terminates.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, when internal memory message
Queue full is enough to lower condition for the moment, determines that internal memory message queue is busy:
The message number actually deposited in a, internal memory message queue reaches the message number that message queue capacity is specified, i.e., really
It is busy to determine internal memory message queue;
B, when message queue accounting coefficient reaches given threshold, it is determined that internal memory message queue is busy;The message team
Row accounting coefficient refers to the message data volume summation and message queue capacity of all message actually deposited in internal memory message queue
The ratio of the data volume specified.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(5)In,
The message to be forwarded in internal memory message queue is extracted, and the message to be forwarded is transmitted to disappearing corresponding to internal memory message queue
Cease receiving terminal concrete mode be:
1)By in all message extractions in internal memory message queue to messaging list, and deleted from internal memory message queue
The message of extracted mistake;
2)Check whether the messaging list is empty, if otherwise entering step 3)If then checking internal memory message queue
Whether the external memory message queue corresponding to message sink end is empty, if then treatment terminates, if otherwise reading external memory message queue
In message to be forwarded and in the news release to be forwarded to the internal memory message queue corresponding to message sink end and will return
Step 1);
3)The message in messaging list is obtained, acquired message is transmitted to internal memory message by data exchange server one by one
Message sink end corresponding to queue.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(5)In,
After message in messaging list is transmitted to message sink end by data exchange server one by one, institute is right in deleting external memory message queue
The successful message of forwarding answered.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(5)In,
Internal memory message queue corresponding to message sink end creates message forwarding thread, forwards thread acquired by initiation message
Message be transmitted to message sink end.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(5)In,
Only start the message forwarding thread at the message sink end that there is message to be forwarded.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(4)In,
By before message deposit to be forwarded to the corresponding internal memory message queue in message sink end, lockout message is received data exchange server
The corresponding internal memory message queue in end, after message deposit to be forwarded to internal memory message queue, data exchange server is released
Locking to internal memory message queue.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, the external memory is disappeared
Breath queue is used to preserve the message that data exchange server is not yet transmitted to message sink end, and each message sink end correspondence is unique
External memory message queue.
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step 2)In, will
News release to be forwarded is to the concrete mode in internal memory message queue in external memory message queue:
One not yet reads in external memory message queue corresponding to step 1, data exchange server reading message sink end
Message to be forwarded in internal memory message queue;
Step 2, locking page in memory message queue, the message to be forwarded are saved in the internal memory message queue, then
Release the locking to internal memory message queue;
Step 3, check in external memory message queue whether also there is the message to be forwarded not yet read in internal memory message queue,
If then return to step 1, if otherwise entering step(5).
Further, a kind of method that message sink and forwarding are realized based on message queue as described above, step(5)In,
During the message to be forwarded in internal memory message queue to be forwarded to corresponding message sink end, if data exchange takes
Business device receives new message, and needs also exist for being transmitted to the message at the message sink end in received new information simultaneously
And the corresponding internal memory message queue in the message sink end is idle, and new information is put into the internal memory message queue at the message sink end
In.
A kind of system that message sink and forwarding are realized based on message queue, including following device:
Message receiving apparatus:The to be forwarded to message sink of data exchange server is sent to for receiving message sending end
The message at end;
Message routing apparatus:The routing configuration information of the message for being received according to data exchange server, it is determined that treating
Forward the message sink end of message;The message sink end is one or more;
The outer cryopreservation device of message:Message to be forwarded is saved in for data exchange server outer corresponding to message sink end
In depositing message queue;The external memory message queue is stored in external non-volatile storage device;
Message memory device:For data exchange server by corresponding to message deposit to be forwarded to message sink end
In depositing message queue;
Message transmission device:For extracting the message to be forwarded in internal memory message queue, and the message to be forwarded is turned
Issue the message sink end corresponding to internal memory message queue.
Further, a kind of system that message sink and forwarding are realized based on message queue as described above, in the message
Cryopreservation device includes:
Internal memory message queue creation module:For when message sink end does not exist internal memory message queue, data exchange to take
Business device is its establishment internal memory message queue;
Internal memory message queue condition judgment module:For judging whether internal memory message queue does, if then treatment terminates, if
Otherwise enter external memory message processing module;
External memory message processing module:The news release to be forwarded in external memory message queue is arrived for data exchange server
In corresponding internal memory message queue.
Further, a kind of system that message sink and forwarding are realized based on message queue as described above, the message is turned
Transmitting apparatus include:
Message extraction module:For by all message extractions to be forwarded in internal memory message queue to messaging list, and from
The message of extracted mistake is deleted in internal memory message queue;
Message capturing module:For obtaining a message to be forwarded from messaging list;
Message transmitting module:For setting up message forwarding thread for internal memory message queue, and by initiation message repeated line
The message to be forwarded that message capturing module gets is forwarded to journey the message sink end corresponding to internal memory message queue;
Messaging list checks module:For checking with the presence or absence of next message to be forwarded in messaging list, if then entering
Enter message capturing module, if otherwise termination messages repeating process.
Further, a kind of system that message sink and forwarding are realized based on message queue as described above, the message is turned
Transmitting apparatus also include:
External memory message deletion module:Message transmitting module has been forwarded to message sink in for deleting external memory message queue
The message at end.
Effect of the invention is that:A kind of method that message sink and forwarding are realized based on message queue of the present invention
And system, be stored on non-volatile memory device by the message for receiving message receiving apparatus, by external memory message queue and
Two message queues of internal memory message queue cooperate and realize reception and forwarding of the data exchange server to message, message forwarding
Thread by during the message of forwarding in need disposably extracts the messaging list of Dispatch Unit in internal memory message queue, no
Must long-time committed memory message queue, do not influence during message is forwarded to be put into new receiving toward internal memory message queue
Need the message of forwarding.By method and system of the present invention, data exchange server asynchronous parallel carries out connecing for message
Receive and forward, improve the real-time of messaging;In addition for the message sink end for needing to forward without message, data exchange
Server is not necessarily it and starts forwarding thread, has saved memory source and cpu resource, improves the transmission of data exchange server
Efficiency.
Brief description of the drawings
Fig. 1 is that the present invention is a kind of realizes that message sink is former with the overall work of the method and system of forwarding based on message queue
Reason figure;
Fig. 2 is a kind of structured flowchart that message sink and the system of forwarding are realized based on message queue of the present invention;
Fig. 3 is a kind of flow chart that message sink and the method for forwarding are realized based on message queue of the present invention;
Fig. 4 is the workflow diagram of external memory message processing apparatus in implementation method;
Fig. 5 be implementation method in message transmission device realize message forwarding workflow diagram.
Specific embodiment
Core concept of the invention is:Method and system of the present invention, introduce and are stored in external non-volatile and deposit
The external memory message queue of storage equipment, and message receiving apparatus and the public internal memory message queue of message transmission device, data are handed over
Change server to receive the message of message sending end transmission and message is saved in external memory message queue, then again by the reception
Message be stored in the internal memory message queue corresponding to message sink end;Create afterwards and initiation message forwarding thread, startup disappears
Breath forwarding thread forwards messages to message sink end;After all message in having forwarded message queue, termination messages forwarding
The operation of thread.By using the method for the present invention and system, data exchange server asynchronous parallel carry out message reception and
Forwarding, improves the real-time of messaging;Cooperated by two message queues, data exchange server is largely connecing
In the case of receipts, forwarding message, also can guarantee that data efficient, reliable transmission.
With reference to Figure of description, the present invention is described in further detail with specific embodiment.
Data exchange server 21 and message exchange client are included by can be seen that system of the invention in Fig. 1(Disappear
Breath transmitting terminal 22 and message sink end 23), message sink end can be one or more.
Fig. 2 shows a kind of structured flowchart that message sink and the system of forwarding are realized based on message queue of the present invention, by
As can be seen that data exchange server 21 is core of the invention in figure.The system mainly includes message receiving apparatus
211st, message routing apparatus 212, message outer cryopreservation device 213, message memory device 214 and message transmission device 215, wherein,
Message receiving apparatus 211 are used to receive message sending end and be sent to the to be forwarded of data exchange server to be connect to message
The message of receiving end;
Message routing apparatus 212 are used for the routing configuration information of the message received according to data exchange server, it is determined that
The message sink end of message to be forwarded;The message sink end is one or more;
Be saved in message to be forwarded corresponding to message sink end for data exchange server by the outer cryopreservation device 213 of message
In external memory message queue;External memory message queue is stored in external non-volatile storage device;
Be saved in message to be forwarded corresponding to message sink end for data exchange server by message memory device 214
In internal memory message queue;The device is included being used for when message sink end does not exist internal memory message queue, data exchange server
The internal memory message queue creation module of internal memory message queue is created for it;For judging whether internal memory message queue does, if then
Treatment terminates, if otherwise inwardly depositing message queue is stored in message;And for data exchange server by external memory message queue
News release to be forwarded to the external memory message processing module in corresponding internal memory message queue;
Message transmission device 215 is used to extracting message to be forwarded in internal memory message queue, and by the message to be forwarded
It is transmitted to the message sink end corresponding to internal memory message queue;The device is included for will be all to be forwarded in internal memory message queue
Message extraction deletes the message extraction module of the message of extracted mistake in messaging list from internal memory message queue;With
In one message capturing module of message to be forwarded of acquisition from messaging list;For setting up message forwarding for internal memory message queue
Thread, and forward thread that the message to be forwarded that message capturing module gets is forwarded into internal memory message queue by initiation message
The message transmitting module at corresponding message sink end;For checking with the presence or absence of next message to be forwarded in messaging list,
If then inbound message acquisition module, if the messaging list of otherwise termination messages repeating process checks module;And for deleting
Message transmitting module has been forwarded to the external memory message deletion module of the message at message sink end in external memory message queue.
Fig. 3 shows that the one kind based on the system for realizing message sink and forwarding in Fig. 2 based on message queue is based on message
The flow chart of message sink and the method for forwarding is realized in queue, and the method is mainly included the following steps that:
Step S31:Message sending end sends a message to data exchange server;
Data exchange server 21 is core of the invention, is used to carry out the reception and forwarding of message.Data exchange
The message receiving apparatus 211 of server receive the message that message sending end sends.
Step S32:The message sink end of message to be forwarded is determined according to message routing configuration information;
Message routing apparatus 212 extract message route from the message for receiving and match somebody with somebody according to the message received in step S31
Confidence ceases, and determines the message sink end of message to be forwarded.The message sink end determined according to message routing configuration information is one
Or it is multiple.
Step S33:In the external memory message queue that message to be forwarded is saved in corresponding to message sink end;Data exchange takes
In the external memory message queue that be saved in message to be forwarded corresponding to message sink end by business device;The external memory message queue is stored in
In external non-volatile storage device.Non-volatile memory device refers to the data energy when no power supply is supplied to storage device
The equipment being enough saved.Store data in and cause in non-volatile memory device in artificial shutdown, system crash or power supply
Data can be recovered in the event of failure.Such as hard disk, USB flash disk, floppy disk, storage card are non-volatile memory device.External memory disappears
Breath queue can use file system or Database Systems, i.e., message is present in operating system file or in database.
Method of the present invention be carry out message sink to solve data exchange server in the prior art, at forwarding
During reason, by message to be forwarded reside in internal memory and cause information drop-out and directly forwarded in message queue and
The problem that the message transmission performance for causing declines, and the method that message sink and forwarding are realized based on message queue for proposing, should
Method introduces the external memory message queue being stored in external non-volatile storage device, is disappeared by external memory message queue and internal memory
Reception and forwarding of the data exchange server to message are realized in the collaborative work for ceasing two message queues of queue.Wherein, each disappears
The breath receiving terminal unique external memory message queue of correspondence, is stored in external non-volatile storage device, is not yet forwarded for preserving
To the message to be forwarded at message sink end.
Step S34:By in the internal memory message queue corresponding to message deposit to be forwarded to message sink end;
In the internal memory message queue that be saved in message to be forwarded corresponding to message sink end by data exchange server.To
To before internal memory message queue, data exchange server whether there is firstly the need of judging message sink end message deposit to be forwarded
Corresponding internal memory message queue, if there is step S34 is then directly carried out, if it does not, data exchange server is message
Receiving terminal enters step S34 after creating corresponding internal memory message queue.Therefore, data exchange server is first to certain message
It is its establishment internal memory message queue, each message sink end correspondence unique internal memory message queue during receiving terminal forwarding message.
, it is necessary to set the message queue capacity of internal memory message queue, the message queue capacity is by message during establishment internal memory message queue
Number and message data volume are determined.Message to be forwarded is saved in the internal memory corresponding to message sink end in data exchange server
During message queue, in addition it is also necessary to which whether the internal memory message queue for judging the message sink end is busy, if otherwise directly disappearing to be forwarded
Breath is saved in the internal memory message queue corresponding to message sink end;If the internal memory message queue at a certain message sink end is busy,
A message sink end in the presence of then checking whether, if then obtaining next message sink end return to step S33, if in the absence of next
Then treatment terminates at message sink end.Wherein, when internal memory message queue meets following condition for the moment, determine that internal memory message queue is
It is busy:
The message number actually deposited in a, internal memory message queue reaches the message number that message queue capacity is specified, i.e., really
It is busy to determine internal memory message queue;
B, when message queue accounting coefficient reaches given threshold, it is determined that internal memory message queue is busy;The message team
Row accounting coefficient refers to the message data volume summation and message queue capacity of all message actually deposited in internal memory message queue
The ratio of the data volume specified.
When message to be forwarded is forwarded to the corresponding internal memory message queue in message sink end by data exchange server, lock first
Determine the internal memory message queue corresponding to message sink end, the corresponding message to be forwarded in the message sink end is then deposited into internal memory
In message queue, data exchange server releases the locking to internal memory message queue after the completion of being stored in.By external memory message queue
In news release to be forwarded to internal memory message queue flow chart as shown in figure 4, concrete mode is:
One not yet reads in external memory message queue corresponding to step 1, data exchange server reading message sink end
Message to be forwarded in internal memory message queue;
Step 2, locking page in memory message queue, the message to be forwarded are saved in the internal memory message queue, then
Release the locking to internal memory message queue;
Step 3, check in external memory message queue whether also there is the message to be forwarded not yet read in internal memory message queue,
If then return to step 1, if otherwise entering step S35.
Step S35:Message to be forwarded in internal memory message queue is transmitted to corresponding message sink end.
Message to be forwarded in extraction step S34 in internal memory message queue, and to be forwarded in internal memory message queue is disappeared
Breath is transmitted to corresponding message sink end.The detail flowchart of forwarding is as shown in figure 5, the concrete mode of forwarding is:
1)By in all message extractions in internal memory message queue to messaging list, and deleted from internal memory message queue
The message of extracted mistake;
2)Check whether the messaging list is empty, if otherwise entering next step, if then checking that corresponding external memory disappears
Whether breath queue is empty, if then treatment terminates, if otherwise reading outer corresponding to the message sink end of the internal memory message queue
Deposit the message to be forwarded in message queue and the internal memory message team by the news release to be forwarded corresponding to message sink end
In row;
3)The message in messaging list is obtained, acquired message is transmitted to internal memory message by data exchange server one by one
Message sink end corresponding to queue.
After the message to be forwarded in messaging list is transmitted to message sink end by data exchange server one by one, delete outer
Deposit the corresponding successful message of forwarding in message queue.It is the internal memory corresponding to message sink end when message is forwarded
Message queue creates message forwarding thread, forwards thread that acquired message is transmitted into message sink end by initiation message.
During transmission, only start the message sink end that there is corresponding message to be forwarded, for the message sink that forwarding is needed without message
End, data exchange server is not necessarily its initiation message forwarding thread, memory source and cpu resource has been saved, so as to improve
The efficiency of transmission of data exchange server.Message to be forwarded in internal memory message queue is being forwarded to corresponding message sink
During end, if data exchange server receives new message, and needed also exist in received new information
The corresponding internal memory message queue of message and the message sink end for being transmitted to the message sink end is idle, new information is put into interior
Deposit in message queue, being achieved in message receiving apparatus and message transmission device asynchronous parallel carries out the reception and forwarding of message,
Improve the real-time and forward efficiency of messaging.
The method of the present invention and system, data exchange server receive the message that message sending end sends and by the message
It is stored in external non-volatile storage device, the message of the reception is then stored in the corresponding internal memory message in message sink end
In queue;Internal memory message queue is created and starts the message transmitting module at the message sink end, and message transmitting module is from message
Queue is extracted message and forwards messages to message sink end;After all message in having forwarded message queue, termination messages
The operation of forwarding module.By using the method for the present invention, data exchange server asynchronous parallel carries out the reception of message and turns
Hair, improves the real-time of messaging;Cooperated by two message queues, even if data exchange server is largely connecing
In the case of receipts, forwarding message, also can guarantee that data efficient, reliable transmission.
Obviously, those skilled in the art can carry out various changes and modification without deviating from essence of the invention to the present invention
God and scope.So, if these modifications of the invention and modification belong to the scope of the claims in the present invention and its equivalent technology
Within, then the present invention is also intended to comprising these changes and modification.