简体   繁体   中英

Connecting to MQ using XMS .Net without MQ client

I am trying to connect to MQ using XMS .Net. The MQ is currently setup on the server and using IBM.WMQ I am able to connect to it. 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.

Spent 2 days over the web but not able to find a full sample where this is implemented. I also don't want to install the MQ client on my local machine. 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

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

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

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.

 /// <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();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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