我目前必須使用MSMQ通過多臺服務器發送大小爲4MB的文件。該文件最初是被派往塊,像這樣:正在接收MSMQ交易作爲組
using (MessageQueueTransaction oTransaction = new MessageQueueTransaction())
{
// Begin the transaction
oTransaction.Begin();
// Start reading the file
using (FileStream oFile = File.OpenRead(PhysicalPath))
{
// Bytes read
int iBytesRead;
// Buffer for the file itself
var bBuffer = new byte[iMaxChunkSize];
// Read the file, a block at a time
while ((iBytesRead = oFile.Read(bBuffer, 0, bBuffer.Length)) > 0)
{
// Get the right length
byte[] bBody = new byte[iBytesRead];
Array.Copy(bBuffer, bBody, iBytesRead);
// New message
System.Messaging.Message oMessage = new System.Messaging.Message();
// Set the label
oMessage.Label = "TEST";
// Set the body
oMessage.BodyStream = new MemoryStream(bBody);
// Log
iByteCount = iByteCount + bBody.Length;
Log("Sending data (" + iByteCount + " bytes sent)", EventLogEntryType.Information);
// Transactional?
oQueue.Send(oMessage, oTransaction);
}
}
// Commit
oTransaction.Commit();
}
這些消息是從機A發送到機器B,然後轉交給機器。然而,我注意到,機器B上的PeekCompleted事件在發送所有消息之前觸發。
例如,測試運行剛纔表明發送8個消息,並且是在1,1基團上機器B處理,然後6.
我相信這是由於事務部確保郵件到達按照正確的順序,但不能保證它們全部在同一時間收集。
我擔心的是,當機器B將消息傳遞給機器C時,這些現在算作3個單獨的事務,並且我不確定事務本身是否以正確的順序傳遞(例如,1然後6然後1)。
我的問題是,是否有可能使用PeekCompleted接收消息(事先收集所有8條消息),並將它們傳遞,以便Machine C將所有8條消息放在一起?即使在同時發送多個交易的系統中也是如此?
或者交易本身是否保證以正確的順序到達?
消息的順序將保持不變,但如果存在多個同時事務,我不能100%確定它們正在連續排隊。 –