【问题标题】:Connecting to MQ using XMS .Net without MQ client在没有 MQ 客户端的情况下使用 XMS .Net 连接到 MQ
【发布时间】:2019-01-28 13:00:25
【问题描述】:

我正在尝试使用 XMS .Net 连接到 MQ。 MQ 目前已在服务器上设置并使用 IBM.WMQ 我能够连接到它。现在我想探索 IBM XMS,因为它支持 API,所以将来我们可以尝试从 .net 全框架或 .net 核心客户端连接到 MQ。

在网上花了 2 天时间,但无法找到实现此功能的完整示例。我也不想在我的本地机器上安装 MQ 客户端。有没有办法做到这一点?有没有同样的好文章?

【问题讨论】:

    标签: c# .net ibm-mq xms


    【解决方案1】:

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

    IBM MQ Redistributable package 可用于开发 MQ .NET 应用程序而无需安装客户端。您必须使用 MQ v9.0.5 或更高版本才能使用 XMS.NET 客户端。您可以从以下链接下载最新的 Redistributable Package

    9.1.0 IBM MQ C and .NET redistributable client for Windows x64

    如果您安装了 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();
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2011-02-09
      • 2018-04-09
      • 1970-01-01
      • 2018-01-22
      相关资源
      最近更新 更多