C#操作消息队列
发布日期:2021-06-30 19:11:39
浏览次数:2
分类:技术文章
本文共 1238 字,大约阅读时间需要 4 分钟。
public class QueueManage { /// /// 发送对象到队列中 /// /// 队列名称,因为队列名称在一个应用中应该不改变的,所以大家最好写在配置文件中 /// 要发出去的对象 public static void SendQueue(string QueuePath,MyBase.SmsQueue sq) { System.Messaging.MessageQueue mqSend=new System.Messaging.MessageQueue(QueuePath,false); EnsureQueueExists(QueuePath); mqSend.Send(sq); } /// /// 检查队列,如果队列不存在,则建立 /// /// 队列名称 private static void EnsureQueueExists(string path) { if(!MessageQueue.Exists(path)) { if(!MessageQueue.Exists(path)) { MessageQueue.Create(path); MessageQueue mqTemp=new MessageQueue(path); mqTemp.SetPermissions("Everyone",System.Messaging.MessageQueueAccessRights.FullControl); ///不知道该给什么样的权限好,所以就给了Everone全部权限了,当然大家最好自己控制一下 } } } /// /// 从队列中取出对象列表 /// /// 队列名称 public static System.Collections.ArrayList GetMessage(string QueuePath) { MyBase.SmsQueue sq=new MyBase.SmsQueue(); System.Messaging.MessageQueue mq=new System.Messaging.MessageQueue(QueuePath,false); mq.Formatter=new XmlMessageFormatter(new Type[] {typeof(MyBase.SmsQueue)}); System.Messaging.Message[] arrM=mq.GetAllMessages(); mq.Close(); System.Collections.ArrayList al=new System.Collections.ArrayList(); foreach(System.Messaging.Message m in arrM) { sq=(TimeFound.SmsGate.Base.SmsQueue)m.Body; al.Add(sq); } return al; } }转载地址:https://linuxstyle.blog.csdn.net/article/details/1539881 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月06日 20时44分05秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30
[double free] 9447 CTF : Search Engine
2019-04-30
python 函数式编程
2019-04-30
python编码
2019-04-30
scala maven plugin
2019-04-30
flink 1-个人理解
2019-04-30
redis cli
2019-04-30
redis api
2019-04-30
flink physical partition
2019-04-30
java 解析json
2019-04-30
java http请求
2019-04-30
tensorflow 数据格式
2019-04-30
tf rnn layer
2019-04-30
tf input layer
2019-04-30
tf model create
2019-04-30
tf dense layer两种创建方式的对比和numpy实现
2019-04-30