how to get connect with ibm websphere mq by using c#.net

后端 未结 4 2198
有刺的猬
有刺的猬 2020-12-13 22:07

can any one guide me on, to get connect with ibm websphere mq by using c#.net, reason was i am trying to push the message in to MQ, kindly can any give me suggestion to conn

相关标签:
4条回答
  • 2020-12-13 22:31

    There are number of samples that come with MQ product install. Refer Nmqsput.cs for your case. When creating a new project you will need to add amqmdnet.dll as reference.

    Not sure what version of MQ you are using. I am assuming you are using MQ v701. You can find the samples under tools folder of your MQ installation.

    If are looking for JMS style of messaging in C#, then XMS .NET is worth looking at. You can find the samples of XMS .NET in the same folder as MQ samples. XMS .NET reference is here

    0 讨论(0)
  • 2020-12-13 22:35

    There is an IBM supplied dll (since v5.3 Fixpack8) on Windows called amqmdnet.dll, which is a .NET assembly providing an IBM supported model for MQSeries. (Reference) It is usually located in C:\Program Files\IBM\WebSphere MQ\bin\amqmdnet.dll

    If you need more direction, there are several examples on how to communicate with MQ from .NET on CodeProject:

    1. http://www.codeproject.com/Articles/12198/IBM-WebSphere-MQ-with-C-GUI-application-that-is-bo
    2. http://www.codeproject.com/Articles/37807/How-to-Setup-a-Websphere-MQ-with-C-NET-GUI-to-Put
    3. http://www.codeproject.com/Articles/6212/C-and-WebSphere-MQ-formerly-MQSeries-Client-Server

    Also, there's this walkthrough that could be helpful: http://www.c-sharpcorner.com/UploadFile/pk_khuman/AquickstartCsharpWebsphereMQ07112006024017AM/AquickstartCsharpWebsphereMQ.aspx

    0 讨论(0)
  • 2020-12-13 22:35

    Already converted (java to c#) mq-client - nuget, github

    c# example:

    var ff = JmsFactoryFactory.getInstance(JmsConstants.__Fields.WMQ_PROVIDER);
    var cf = ff.createConnectionFactory();
    
    cf.setIntProperty(CommonConstants.__Fields.WMQ_CONNECTION_MODE, CommonConstants.__Fields.WMQ_CM_CLIENT);
    cf.setStringProperty(CommonConstants.__Fields.WMQ_HOST_NAME, "127.0.0.1");
    cf.setIntProperty(CommonConstants.__Fields.WMQ_PORT, 8010);
    cf.setStringProperty(CommonConstants.__Fields.WMQ_CHANNEL, "EXAMPLE.CHANNEL.ONE");
    cf.setStringProperty(CommonConstants.__Fields.WMQ_QUEUE_MANAGER, "EXAMPLE_QUEUE_MANAGER");
    cf.setStringProperty(CommonConstants.__Fields.WMQ_APPLICATIONNAME, "JMS EXAMPLE");
    cf.setStringProperty(CommonConstants.USERID, "EXAMPLE_USER");
    
    using (var context = cf.createContext())
    {
        var queue = context.createQueue("queue:///EXAMPLE_QUEUE_NAME");
        var producer = context.createProducer();
        producer.send(queue, "Hello World");
    }
    
    0 讨论(0)
  • 2020-12-13 22:37

    You can connect using the .NET libraries provided by IBM; however, they require you to install the WebSphere MQ Client on every server you deploy your solution to. (lame)

    If using WebSphere MQ, the machine used to run the XMS application must be installed with the WebSphere MQ Client V7.0.1.0 or later

    You can avoid this by converting a few Java libraries using IKVM (www.ikvm.net).

    The whole process should only take about 15 minutes.

    You'll still need to download and install the client on your development box so that you can get the JAR files. After you convert them, you can uninstall the client.

    Here are the steps

    1) Get JARs

    • Download WebSphere MQ V7.5 Client: http://www-304.ibm.com/support/docview.wss?uid=swg24032744
    • Install the MQ client: You only need to install the "Java and .Net Messaging and Web Services".
    • Features

    2) Convert JARs

    • Download IKVM: www.ikvm.net
    • Extract the IKVM files (e.g. c:\tools\IKVM).
    • Open Win command prompt
      • Execute command: set path=%path%;c:\tools\IKVM\bin
      • Execute command: cd C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
      • Execute command: ikvmc -target:library -sharedclassloader { com.ibm.mq.jmqi.jar } { com.ibm.mqjms.jar } { dhbcore.jar } { jms.jar }

    3) Copy JARs

    • Open windows explorer.
    • Navigate to: C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
    • Copy the following files:
      • **com.ibm.mq.jmqi.dll
      • com.ibm.mqjms.dll
      • jms.dll**
    • Navigate to: c:\tools\IKVM\bin
    • Copy the following files:
      • **IKVM.Runtime.dll
      • IKVM.OpenJDK.Core.dll**
    • Move the copied files to a 3rd Party folder in your project/solution.

    4) References JARs

    • Reference the copied JARs. Please note that you can skip the previous Copy JARs step above and simply reference the libraries directly, if you like. The objective was to show that there were no other resources needed for proper execution.
    • Project References

    The following is a very simple example of how you can use the libraries.

    using com.ibm.msg.client.jms;
    using com.ibm.msg.client.wmq.common;
    using javax.jms;
    using System;
    
    class Program
    {
        static void Main(string[] args)
        {
            var ff = JmsFactoryFactory.getInstance(JmsConstants.__Fields.WMQ_PROVIDER);
            var cf = ff.createConnectionFactory() as JmsConnectionFactory;
    
            cf.setIntProperty(CommonConstants.__Fields.WMQ_CONNECTION_MODE, CommonConstants.__Fields.WMQ_CM_CLIENT);
            cf.setStringProperty(CommonConstants.__Fields.WMQ_HOST_NAME, "<YOUR INFO>");
            cf.setIntProperty(CommonConstants.__Fields.WMQ_PORT, 1414);
            cf.setStringProperty(CommonConstants.__Fields.WMQ_CHANNEL, "<YOUR INFO>");
            cf.setStringProperty(CommonConstants.__Fields.WMQ_QUEUE_MANAGER, "<YOUR INFO>");
    
            var connection = cf.createConnection();
            var session = connection.createSession(false, Session.__Fields.AUTO_ACKNOWLEDGE);
    
            var queue = session.createQueue("queue:///<YOUR INFO>");
            var producer = session.createProducer(queue);
    
            var msg = session.createTextMessage();
            msg.setStringProperty("JMSXGroupID", Guid.NewGuid().ToString());
            msg.setIntProperty("JMSXGroupSeq", 1);
            msg.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", true);
            msg.setText("Hello World");
    
            connection.start();
            producer.send(msg);
    
            producer.close();
            session.close();
            connection.close();
        }
    }
    
    0 讨论(0)
提交回复
热议问题