带有.Net Core 2.2的WebsphereMQ

时间:2019-03-19 20:44:09

标签: c# .net-core websphere ibm-mq

我正在尝试使用.Net Core 2.2连接到WebsphereMQ队列。 我真的很困惑如何做到这一点。在显示我正在尝试(和失败)的内容之前,我需要澄清一下:

  • 我应该使用哪个库以及如何获取它? (NMS?AMQP?WebsphereClient?)
    • 我已经看到一些示例,这些示例通常使用安装WebsphereMQ(???)时附带的某些DLL。那是对的吗?我需要安装WebsphereMQ吗? (现在,我将其保存在可以连接到所需队列的远程服务器中。)

到目前为止,我一直尝试安装WebSphereMQClient并尝试使用以下代码连接到队列:

    public void StartListener()
    {
        try
        {
            var xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
            var cf = xff.CreateConnectionFactory();
            cf.SetStringProperty(XMSC.WMQ_HOST_NAME, WebsphereMqHost);
            cf.SetIntProperty(XMSC.WMQ_PORT, WebsphereMqPort);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, WebsphereMqChannel);
            cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, WebsphereMqQueueManager);
            cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);

            var conn = cf.CreateConnection();
            var sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            var queue = sess.CreateQueue(QueueName);
            var consumer = sess.CreateConsumer(queue);

            consumer.MessageListener = OnWebsphereMsg;

            conn.Start();
        }
        catch (Exception e)
        {
            _logger.LogError(e);
        }
    }

但是我在第一行遇到了一个例外:

System.Exception: Fatal error. Failed to initialize XMSFactoryFactory ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'IBM.XMS.Client.Impl.XmsFactoryFactoryImpl' threw an exception. ---> System.TypeInitializationException: The type initializer for 'IBM.XMS.Util.Tr' threw an exception. ---> System.TypeInitializationException: The type initializer for 'IBM.XMS.Util.ConfigMgr' threw an exception. ---> System.MissingMethodException: Method not found: 'System.AppDomainSetup System.AppDomain.get_SetupInformation()'.
   at IBM.XMS.Util.ConfigMgr..cctor()
   --- End of inner exception stack trace ---
   at IBM.XMS.Util.Tr.ResolveTraceSpec()
   at IBM.XMS.Util.Tr.LoadTraceConfig()
   at IBM.XMS.Util.Tr..cctor()
   --- End of inner exception stack trace ---
   at IBM.XMS.Util.Tr.Register(Type aClass, String group, String resourceBundleName)
   at IBM.XMS.Client.Impl.XmsFactoryFactoryImpl..cctor()
   --- End of inner exception stack trace ---
   at IBM.XMS.Client.Impl.XmsFactoryFactoryImpl.GetClientFactory(Int32 connectionType)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at IBM.XMS.XMSFactoryFactory.GetXmsFactory(Int32 connectionType)
   --- End of inner exception stack trace ---
   at IBM.XMS.XMSFactoryFactory.GetXmsFactory(Int32 connectionType)
   at IBM.XMS.XMSFactoryFactory.GetInstance(Int32 connectionType)
   at MyApp.Integrations.Configurations.WebsphereMqIntegrationsManager.StartListener(ListenersEnum listener, Dictionary`2 parameters).

我注意到WebsphereMqClient与.NET Standard不兼容。是由于该错误引起的吗?如何使用.NET Core应用程序连接到Websphere?

谢谢

1 个答案:

答案 0 :(得分:0)

amqmxmsstd.dll是必须使用的库,可以从MQ v9.1.1中获得。以下是信息中心链接,该链接讨论将XMS与Microsoft .NET Core一起使用。 Using XMS with Microsoft .NET Core

您将需要amqmdnetstd.dll和amqmxmsstd.dll来开发XMS .NET应用程序,并且这两个dll都是使用.NET Standard构建的。以下信息中心链接介绍了用于构建这些库的框架。 Installing IBM MQ classes for .NET Standard

正如Josh所指出的,您可以使用MQ Redist客户端来获取库。 从IBM MQ Redist clients下载“ 9.1.1.0-IBM-MQC-Redist-Win64”