C# MSMQ操作

//MSMQ path
string qPath = ".\\private$\\fids_input";

//send msg to Q
public void sendMsg(string content)
{
try
{
System.Text.UTF8Encoding oEncoder = new System.Text.UTF8Encoding();


MessageQueue msgQ = new MessageQueue(qPath);
System.Messaging.Message msg = new System.Messaging.Message();

msg.Label = "PARSRqeuest";
//msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
//发消息到队列中
System.IO.MemoryStream ms = new System.IO.MemoryStream(oEncoder.GetBytes(content));
msg.BodyStream = ms;
msg.UseDeadLetterQueue = false;
msg.UseJournalQueue = false;
msgQ.Send(msg);

msg = null;
msgQ.Close();
msgQ = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

posted @ 2015-09-21 11:06  犁山  阅读(233)  评论(0编辑  收藏  举报