C#操作消息队列
来源:互联网 发布:数据之家社工库论坛 编辑:程序博客网 时间:2024/04/29 05:57
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;
}
}
{
///
/// 发送对象到队列中
///
/// 队列名称,因为队列名称在一个应用中应该不改变的,所以大家最好写在配置文件中
/// 要发出去的对象
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;
}
}
- C#操作消息队列
- C#操作消息队列
- C#操作消息队列
- c#中如何操作消息队列
- c# 中如何操作消息队列
- c#中如何操作消息队列
- 一个关于C#操作消息队列的代码
- C#消息队列应用程序
- C#消息队列-1
- C#消息队列专题
- linux消息队列操作
- Linux消息队列操作
- Linux消息队列操作
- Linux消息队列操作
- linux消息队列操作
- 多线程操作消息队列
- linux消息队列操作
- linux消息队列操作
- Servlet life cycle
- C#之消息队列的简要说明
- javax.swing.text
- vc积累
- 二 JavaScript基本数据结构
- C#操作消息队列
- 毕业设计开发环境搭建
- 我们不能对Google说“不”
- 三 JavaScript程序构成
- C#中在应用程序和DLL使用消息
- 四 基于对象的JavaScript语言
- lucene搜索引擎技术的分析与整理
- 做事要细致
- 五 在JavaScript中创建新对象