简体   繁体   English

在没有 MQ 客户端的情况下使用 XMS .Net 连接到 MQ

[英]Connecting to MQ using XMS .Net without MQ client

I am trying to connect to MQ using XMS .Net.我正在尝试使用 XMS .Net 连接到 MQ。 The MQ is currently setup on the server and using IBM.WMQ I am able to connect to it. MQ 当前已在服务器上设置并使用 IBM.WMQ 我能够连接到它。 Now I want to explore the IBM XMS as it supports API so in future we can try connecting to MQ from .net full-framework or .net core clients.现在我想探索 IBM XMS,因为它支持 API,所以将来我们可以尝试从 .net 全框架或 .net 核心客户端连接到 MQ。

Spent 2 days over the web but not able to find a full sample where this is implemented.在网上花了 2 天时间,但无法找到实现此功能的完整示例。 I also don't want to install the MQ client on my local machine.我也不想在我的本地机器上安装 MQ 客户端。 Is there a way to do this?有没有办法做到这一点? Are there any good articles available for the same?有没有什么好的文章可用于相同的?

Following link provides an overview of XMS.NET http://www-01.ibm.com/support/docview.wss?uid=swg27024064以下链接提供了 XMS.NET 的概述http://www-01.ibm.com/support/docview.wss?uid=swg27024064

IBM MQ Redistributable package can be used to develop MQ .NET applications without installing the Client.You will have to use MQ v9.0.5 or above to use XMS.NET client.You can download the latest redistributable package from the following link IBM MQ Redistributable 包可用于开发 MQ .NET 应用程序,无需安装客户端。您必须使用 MQ v9.0.5 或更高版本才能使用 XMS.NET 客户端。您可以从以下链接下载最新的可再发行包

9.1.0 IBM MQ C and .NET redistributable client for Windows x64 9.1.0 适用于 Windows x64 的 IBM MQ C 和 .NET 可再发行客户端

If you have MQ client install then there are samples located at "MQ_INSTALL_PATH\\Tools\\dotnet\\samples\\cs\\xms\\simple\\wmq" and following link provides a brief description about the samples https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.xms.doc/xms_csamp.html Following is the code sample to get a message asynchronously using Message listeners.如果您安装了 MQ 客户端,那么示例位于“MQ_INSTALL_PATH\\Tools\\dotnet\\samples\\cs\\xms\\simple\\wmq”,以下链接提供了有关示例的简要说明https://www.ibm.com/support /knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.xms.doc/xms_csamp.html以下是使用消息侦听器异步获取消息的代码示例。

 /// <summary>
            /// Setup connection to MQ queue manager using XMS .NET
            /// </summary>
            private void ibmmqSetupConnection()
            {
                XMSFactoryFactory factoryFactory;
                IConnectionFactory cf;
                IDestination destination;
                IMessageConsumer consumerAsync;
                MessageListener messageListener;
                // Get an instance of factory.
                factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

                // Create WMQ Connection Factory.
                cf = factoryFactory.CreateConnectionFactory();

                // Set the properties
                cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "host.ibm.com");
                cf.SetIntProperty(XMSC.WMQ_PORT, 1414);
                cf.SetStringProperty(XMSC.WMQ_CHANNEL, "QM.SVRCONN");
                cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
                cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM1");
                cf.SetStringProperty(XMSC.USERID, "myuserid");
                cf.SetStringProperty(XMSC.PASSWORD, "passw0rd");

                // Create connection.
                connectionWMQ = cf.CreateConnection();
                // Create session with client acknowledge so that we can acknowledge 
                // only if message is sent to Azure Service Bus queue
                sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.ClientAcknowledge);
                // Create destination
                destination = sessionWMQ.CreateQueue("INPUTQ");
                // Create consumer
                consumerAsync = sessionWMQ.CreateConsumer(destination);

                // Setup a message listener and assign it to consumer
                messageListener = new MessageListener(OnMessageCallback);
                consumerAsync.MessageListener = messageListener;

                // Start the connection to receive messages.
                connectionWMQ.Start();

                // Wait for messages till a key is pressed by user
                Console.ReadKey();

                // Cleanup
                consumerAsync.Close();
                destination.Dispose();
                sessionWMQ.Dispose();
                connectionWMQ.Close();
            }

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

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