IBM WebSphere MQ的C#工具类以及源码
作者:网络转载 发布时间:[ 2015/4/22 10:38:42 ] 推荐标签:IBM WebSphere MQ C# 源码
简单的介绍一下MQ常用的对象
Queue的分类:
MQ工具类:
using IBM.WMQ;
using IBM.WMQ.PCF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using IBM.WMQAX;
/// <summary>
/// MQHelp 类库
/// henrylee
/// </summary>
public class MQHelp
{
public MQHelp()
{
}
/// <summary>
/// 创建本地队列
/// </summary>
/// <param name="qmName">队列管理器</param>
/// <param name="queueName">队列名称</param>
/// <param name="isTransmissionQueue">是否为传输队列</param>
public void CreateQueue(string qmName, string queueName, bool isTransmissionQueue = false)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_CREATE_Q);
request.AddParameter(MQC.MQCA_Q_NAME, queueName);
request.AddParameter(MQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL);
if (isTransmissionQueue) request.AddParameter(MQC.MQIA_USAGE, MQC.MQUS_TRANSMISSION);
PCFMessage[] response = agent.Send(request);
}
/// <summary>
/// 删除队列
/// </summary>
public void DelQueue(string qmName, string queueName)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_DELETE_Q);
request.AddParameter(MQC.MQCA_Q_NAME, queueName);
PCFMessage[] response = agent.Send(request);
}
/// <summary>
/// 读取消息
/// </summary>
/// <returns></returns>
public string ReadMessage(string qmName, string queueName)
{
MQQueueManager qMgr = new MQQueueManager(qmName);
MQQueue queue = qMgr.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_WAIT;
gmo.WaitInterval = 1000;
gmo.MatchOptions = MQC.MQMO_NONE;
MQMessage message = new MQMessage();
queue.Get(message);
return message.ReadString(message.MessageLength);
}
/// <summary>
/// 写入消息
/// </summary>
public void WriteMessage(string qmName, string queueName, string body)
{
MQQueueManager qMgr = new MQQueueManager(qmName);
MQQueue queue = qMgr.AccessQueue(queueName, MQC.MQOO_OUTPUT);
MQMessage message = new MQMessage();
message.WriteString(body);
message.Format = MQC.MQFMT_STRING;
queue.Put(message);
}
/// <summary>
/// 获取当前管理器所有队列
/// </summary>
/// <param name="qmName">队列管理器</param>
/// <param name="isFindSystemQueue">是否包含系统队列</param>
/// <returns></returns>
public List<string> GetALLQueue(string qmName, bool isFindSystemQueue = false)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_NAMES);
request.AddParameter(MQC.MQCA_Q_NAME, "*");
PCFMessage[] response = agent.Send(request);
string[] names = response[0].GetStringListParameterValue(CMQCFC.MQCACF_Q_NAMES);
List<string> result = null;
if (!isFindSystemQueue)
result = names.ToList().Where(s => !s.Contains("AMQ.") && !s.Contains("SYSTEM.")).ToList();
else
result = names.ToList();
return result;
}
/// <summary>
/// 创建远程队列
/// </summary>
/// <param name="qmName">队列管理器</param>
/// <param name="queueName">队列名称</param>
/// <param name="ycqmName">远程队列管理器名称</param>
/// <param name="ycqueueName">远程队列名称</param>
/// <param name="csqueueName">传输队列名称</param>
public void CreateRemoteQueue(string qmName, string queueName, string ycqmName, string ycqueueName, string csqueueName)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_CREATE_Q);
request.AddParameter(MQC.MQCA_Q_NAME, queueName);
request.AddParameter(MQC.MQIA_Q_TYPE, MQC.MQQT_REMOTE);
request.AddParameter(MQC.MQCA_REMOTE_Q_MGR_NAME, ycqmName);
request.AddParameter(MQC.MQCA_REMOTE_Q_NAME, ycqueueName);
request.AddParameter(MQC.MQCA_XMIT_Q_NAME, csqueueName);
PCFMessage[] response = agent.Send(request);
agent.Disconnect();
}
/// <summary>
/// 创建发送方通道
/// </summary>
/// <param name="qmName">队列管理器</param>
/// <param name="channelName">通道名称</param>
/// <param name="transmissionQueueName">传输队列名称</param>
/// <param name="iPPort">IP地址与端口号 例:localhost(1415) </param>
public void CreateChannelBySend(string qmName, string channelName, string transmissionQueueName, string iPPort)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);
request.AddParameter(CMQCFC.MQCACH_CHANNEL_NAME, channelName);
request.AddParameter(CMQCFC.MQIACH_CHANNEL_TYPE, MQC.MQCHT_SENDER);
request.AddParameter(CMQCFC.MQCACH_CONNECTION_NAME, iPPort);
request.AddParameter(CMQCFC.MQCACH_XMIT_Q_NAME, transmissionQueueName);
PCFMessage[] response = agent.Send(request);
agent.Disconnect();
}
/// <summary>
/// 创建接受方通道
/// </summary>
/// <param name="qmName">队列管理器</param>
/// <param name="channelName">管道名称</param>
public void CreateChannelByReceive(string qmName, string channelName)
{
PCFMessageAgent agent = new PCFMessageAgent(qmName);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);
request.AddParameter(CMQCFC.MQCACH_CHANNEL_NAME, channelName);
request.AddParameter(CMQCFC.MQIACH_CHANNEL_TYPE, MQC.MQCHT_RECEIVER);
PCFMessage[] response = agent.Send(request);
agent.Disconnect();
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11