请教如何判断消息队列中的消息数量
展开全部
//信息生产者向远程服务器消息队列中写入数据
MessageQueue MQ = new MessageQueue("FormatName:DIRECT=TCP:10.168.4.36\\private$\\xiaofuyu");
try
{
for (int i = 0; i < 100; i++)
{
Message myMessage = new Message();
myMessage.Body = "This is a test message, No." + (i + 1).ToString();
myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("已发送信息条数:" + (i + 1).ToString());
MQ.Send(myMessage);
}
Console.WriteLine("发送完毕");
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
//.....省略部分代码
//信息消费者从远程队列中读取数据
MessageQueue MQ1 = new MessageQueue("FormatName:DIRECT=TCP:10.168.4.36\\private$\\xiaofuyu");
MQ1.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Message myMessage1 = new Message();
try
{
do
{
myMessage1 = MQ1.Receive(new TimeSpan(0, 0, 5));
string Context = myMessage1.Body.ToString();
Console.WriteLine("收到消息:" + Context);
}
while (myMessage1 != null);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
MessageQueue MQ = new MessageQueue("FormatName:DIRECT=TCP:10.168.4.36\\private$\\xiaofuyu");
try
{
for (int i = 0; i < 100; i++)
{
Message myMessage = new Message();
myMessage.Body = "This is a test message, No." + (i + 1).ToString();
myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("已发送信息条数:" + (i + 1).ToString());
MQ.Send(myMessage);
}
Console.WriteLine("发送完毕");
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
//.....省略部分代码
//信息消费者从远程队列中读取数据
MessageQueue MQ1 = new MessageQueue("FormatName:DIRECT=TCP:10.168.4.36\\private$\\xiaofuyu");
MQ1.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Message myMessage1 = new Message();
try
{
do
{
myMessage1 = MQ1.Receive(new TimeSpan(0, 0, 5));
string Context = myMessage1.Body.ToString();
Console.WriteLine("收到消息:" + Context);
}
while (myMessage1 != null);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询