简体   繁体   English

在Websphere MQ中创建新的队列管理器和队列(使用C#)

[英]Creating a new Queue Manager and Queue in Websphere MQ (using C#)

I'm writing an application that uses WebSphere MQ for messaging. 我正在编写一个使用WebSphere MQ进行消息传递的应用程序。 For my unittests (flowtests), I want to verify that I have put the right messages on the response queue. 对于我的单元测试(流测试),我想验证是否已在响应队列中放置了正确的消息。 I'm trying to figure out how to do this. 我正在尝试找出方法。 My main obstacle is that I think it might be scary to clear a queue before I run my unittest, because the same queue might be used by another application. 我的主要障碍是,我认为在运行单元测试之前清除队列可能会很恐怖,因为同一队列可能会被另一个应用程序使用。 I thought a decent workaround would be to create a new queue manager and queue for my unittest and delete it after using it. 我认为一个不错的解决方法是为我的单元测试创​​建一个新的队列管理器和队列,并在使用后删除它。

So my question is: Is it possible to create a queue manager and queue using C#? 所以我的问题是:是否可以使用C#创建队列管理器和队列?

For future reference and future people who want to create queues. 供将来参考,以及以后想要创建队列的人员。 I figured out how to create and delete IBM MQ queues (not queuemanagers) with PCF messaging. 我了解了如何使用PCF消息传递创建和删除IBM MQ队列(而非队列管理器)。 It is not very straightforward, but it can be done. 这不是很简单,但是可以做到。

We have implemented it in a library and are using it to create and delete queues before and after integration tests respectivally. 我们已经在一个库中实现了它,并正在使用它在集成测试之前和之后分别创建和删除队列。 The most important part of code in this library is shown in the code sample below. 下面的代码示例中显示了该库中最重要的代码部分。 Just add a reference to amqmdnet.dll and below code will create a queue and delete it. 只需添加对amqmdnet.dll的引用,下面的代码将创建一个队列并将其删除。

string queueManagerName = "QM_LOCAL";
string queueName = "DeleteMeQueue";

Hashtable options = new Hashtable();

// This is a connection to a local server. For a remote server use 'TRANSPORT_MQSERIES_CLIENT', 'TRANSPORT_MQSERIES_XACLIENT' or 'TRANSPORT_MQSERIES_MANAGED'
options.Add(IBM.WMQ.MQC.TRANSPORT_PROPERTY, "TRANSPORT_MQSERIES_BINDINGS");

// For 'TRANSPORT_MQSERIES_CLIENT', 'TRANSPORT_MQSERIES_XACLIENT' or 'TRANSPORT_MQSERIES_MANAGED' uncomment the below
// string hostName = "RemoteServerName";
// string channelName = "SYSTEM.ADMIN.SVRCONN";
// int portNumber = 1414;
// options.Add(IBM.WMQ.MQC.HOST_NAME_PROPERTY, hostName);
// options.Add(IBM.WMQ.MQC.CHANNEL_PROPERTY, channelName);
// options.Add(IBM.WMQ.MQC.PORT_PROPERTY, portNumber);
// options.Add(IBM.WMQ.MQC.CONNECT_OPTIONS_PROPERTY, IBM.WMQ.MQC.MQC.MQCNO_STANDARD_BINDING);
IBM.WMQ.MQQueueManager queueManager = null;
IBM.WMQ.PCF.PCFMessageAgent agent = null;
try
{
    // Initialize a connection to the (remote) queuemanager and a PCF message agent.
    queueManager = new IBM.WMQ.MQQueueManager(queueManagerName, options);
    agent = new IBM.WMQ.PCF.PCFMessageAgent(queueManager);

    // Create queue
    IBM.WMQ.PCF.PCFMessage createRequest = new IBM.WMQ.PCF.PCFMessage(IBM.WMQ.PCF.CMQCFC.MQCMD_CREATE_Q);
    createRequest.AddParameter(IBM.WMQ.MQC.MQCA_Q_NAME, queueName);
    createRequest.AddParameter(IBM.WMQ.MQC.MQIA_Q_TYPE, IBM.WMQ.MQC.MQQT_LOCAL);
    createRequest.AddParameter(IBM.WMQ.MQC.MQIA_DEF_PERSISTENCE, IBM.WMQ.MQC.MQPER_PERSISTENT);
    createRequest.AddParameter(IBM.WMQ.MQC.MQCA_Q_DESC, "Created by " + Environment.UserName + " on " + DateTime.UtcNow.ToString("o"));
    IBM.WMQ.PCF.PCFMessage[] createResponses = agent.Send(createRequest);

    // Delete queue
    IBM.WMQ.PCF.PCFMessage deleteRequest = new IBM.WMQ.PCF.PCFMessage(IBM.WMQ.PCF.CMQCFC.MQCMD_DELETE_Q);
    deleteRequest.AddParameter(IBM.WMQ.MQC.MQCA_Q_NAME, queueName);
    IBM.WMQ.PCF.PCFMessage[] deleteResponses = agent.Send(deleteRequest);
}
finally
{
    // Disconnect the agent and queuemanager.
    if (agent != null) agent.Disconnect();
    if (queueManager != null && queueManager.IsConnected) queueManager.Disconnect();
}

Creation of queue manager and queues are administrative jobs. 队列管理器和队列的创建是管理工作。 Creation of queue manager can not be done using an user defined application. 使用用户定义的应用程序无法完成队列管理器的创建。 You have to use the command crtmqm <qmname> provided by MQ to create queue manager. 您必须使用MQ提供的命令crtmqm <qmname>来创建队列管理器。

I would suggest you ask your queue manager administrator to create dedicated queue for you. 我建议您请队列管理器管理员为您创建专用队列。 Only your unit test use this queue and no other user is allowed to put/get messages to this queue. 仅您的单元测试使用此队列,不允许其他用户将消息放入/获取到此队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM