1
我有一個簡單的控制檯應用程序,我正在使用MSMQ在寫入SQL Server之前存儲消息。我是MQ新手,所以請原諒我,如果有一個愚蠢的錯誤。基本上,沒有拋出錯誤,代碼只是直通運行,而無需進入處理程序...任何幫助/指導非常感激...代碼如下,謝謝: -MSMQ ReceiveCompleted沒有開火?
public void MSMQ_GetMessage(string _MQ_Path)
{
//set the correct message queue
MessageQueue _msgQ = new MessageQueue(_MQ_Path, QueueAccessMode.ReceiveAndAdmin);
//set the format of the message queue
// _msgQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(_TwitterStreamFeed) });
_msgQ.ReceiveCompleted += new ReceiveCompletedEventHandler(_msgQ_RecieveCompleted);
_msgQ.Formatter = new BinaryMessageFormatter();
_msgQ.BeginReceive();
}
//method to process message
public void _msgQ_RecieveCompleted(object sender, ReceiveCompletedEventArgs e)
{
//queue that have received a message
MessageQueue _mq = (MessageQueue)sender;
try
{
//get the messge off the queue
Message _mqmsg = _mq.EndReceive(e.AsyncResult);
//set the values back into a formatted struct
_TwitterStreamFeed _ts = (_TwitterStreamFeed)_mqmsg.Body;
//now process your SQL....
_azuresql.writeMessageToStorage(_ts);
}
catch
{
}
//refresh queue just in case any changes occurred (optional)
_mq.Refresh();
//tell MessageQueue to receive next message when it arrives
_mq.BeginReceive();
}