我正在尝试使用 XMS .Net 连接到 MQ。MQ 目前已在服务器上设置并使用 IBM.WMQ 我能够连接到它。现在我想探索 IBM XMS,因为它支持 API,所以将来我们可以尝试从 .net 全框架或 .net 核心客户端连接到 MQ。
在网上花了 2 天时间,但无法找到实现此功能的完整示例。我也不想在我的本地机器上安装 MQ 客户端。有没有办法做到这一点?有没有相同的好文章?
以下链接提供了 XMS.NET 的概述 http://www-01.ibm.com/support/docview.wss?uid=swg27024064
IBM MQ Redistributable 包可用于开发 MQ .NET 应用程序而无需安装客户端。您必须使用 MQ v9.0.5 或更高版本才能使用 XMS.NET 客户端。您可以从以下链接下载最新的可再分发包
9.1.0 适用于 Windows x64 的 IBM MQ C 和 .NET 可再发行客户端
如果您安装了 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();
}