MSMQ(微软消息队列)简单使用-支持离线提交数据(供阅)
来源:互联网 发布:微盘交易php源码 编辑:程序博客网 时间:2024/06/05 17:16
#region MessageQueue消息队列(发送/接收)
//第一条数据
MessageQueue sendQueue = new MessageQueue(".\\Private$\\MSMQDemo");
Message sendsg = new Message();
sendsg.Body = "This is test of messagequeue ";
sendsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("MessageQueue has sent succefully");
sendQueue.Send(sendsg);
//接收第一条
MessageQueue accpetQueue = new MessageQueue(".\\Private$\\MSMQDemo");
Message accpetMsg = accpetQueue.Receive();
accpetMsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
string accptTxt = accpetMsg.Body.ToString();
Console.WriteLine(accptTxt);
//加载第二条数据
sendsg.Body = "No.2 test of messagequeue ";
sendsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("MessageQueue has sent succefully");
sendQueue.Send(sendsg);
//接收第二条
MessageQueue accpetQueue2 = new MessageQueue(".\\Private$\\MSMQDemo");
Message accpetMsg2 = accpetQueue.Receive();
accpetMsg2.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
string accptTxt2 = accpetMsg2.Body.ToString();
Console.WriteLine(accptTxt2);
#endregion
在使用MSMQ之前 要先添加MSMQ消息服务 在添加删除程序里面添加Windows组件 然后在计算机-管理-服务和应用-消息队列里面在专用队列新增一个专用队列 如我这里建的是名为MSMQDemo的队列
消息队列的用处:消息队列可以保证客户端与服务器端通信的时候 由于并发而产生的服务端无法及时反馈给客户端信息而造成的服务不善 消息队列就相当于先将客户端提交的数据按照队列的FIFO规则加载到队列中 然后逐个发送给服务端 这样保证客户端与服务端失去连接后仍然能将数据提交给服务端 因为消息队列支持离线提交数据 有了它 就可以防止服务端因高并发而造成宕机
//第一条数据
MessageQueue sendQueue = new MessageQueue(".\\Private$\\MSMQDemo");
Message sendsg = new Message();
sendsg.Body = "This is test of messagequeue ";
sendsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("MessageQueue has sent succefully");
sendQueue.Send(sendsg);
//接收第一条
MessageQueue accpetQueue = new MessageQueue(".\\Private$\\MSMQDemo");
Message accpetMsg = accpetQueue.Receive();
accpetMsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
string accptTxt = accpetMsg.Body.ToString();
Console.WriteLine(accptTxt);
//加载第二条数据
sendsg.Body = "No.2 test of messagequeue ";
sendsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
Console.WriteLine("MessageQueue has sent succefully");
sendQueue.Send(sendsg);
//接收第二条
MessageQueue accpetQueue2 = new MessageQueue(".\\Private$\\MSMQDemo");
Message accpetMsg2 = accpetQueue.Receive();
accpetMsg2.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
string accptTxt2 = accpetMsg2.Body.ToString();
Console.WriteLine(accptTxt2);
#endregion
在使用MSMQ之前 要先添加MSMQ消息服务 在添加删除程序里面添加Windows组件 然后在计算机-管理-服务和应用-消息队列里面在专用队列新增一个专用队列 如我这里建的是名为MSMQDemo的队列
消息队列的用处:消息队列可以保证客户端与服务器端通信的时候 由于并发而产生的服务端无法及时反馈给客户端信息而造成的服务不善 消息队列就相当于先将客户端提交的数据按照队列的FIFO规则加载到队列中 然后逐个发送给服务端 这样保证客户端与服务端失去连接后仍然能将数据提交给服务端 因为消息队列支持离线提交数据 有了它 就可以防止服务端因高并发而造成宕机
- MSMQ(微软消息队列)简单使用-支持离线提交数据(供阅)
- MSMQ微软消息队列
- 微软消息队列-MSMQ
- 微软消息队列(MSMQ)配置使用小结(c#)
- MSMQ 微软消息队列服务
- 使用JAVA向微软消息队列(MSMQ)发送和接收消息
- (6)WCF服务离线操作与消息队列MSMQ
- 消息队列(MSMQ)
- MSMQ(MicroSoft Message Queue,微软消息队列)
- C#中使用Windows消息队列服务(MSMQ)简单示例
- 【消息队列】MSMQ(一)——微软消息队列简介及安装
- WCF服务离线操作与消息队列MSMQ
- MSMQ消息队列与WCF MSMQ的认识与使用
- IPC之 - .Net 消息队列(MSMQ) 使用
- 消息队列MSMQ的使用实例
- .Net消息队列MSMQ的使用实例
- 消息队列MSMQ的使用实例
- .Net下的MSMQ(微软消息队列)的同步异步调用 (转载)
- linux分区知识与大磁盘的分区注意事项
- hdu1728
- 关于CSAPP读到的一些(1)——Alignment(出自Machine-Level Representation of Program)
- chmod的四位数的第一位代表什么
- Templates
- MSMQ(微软消息队列)简单使用-支持离线提交数据(供阅)
- JEECMS --Java CMs内容管理系统
- 为Linux增加虚拟内存(也就是交换分区)
- Log4j学习笔记
- shell脚本程序练习
- 计算程序运行时间
- 函数总结
- JavaBean的删除
- jqGrid 属性说明