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