13

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 connect by using c#.net

shannu
  • 187
  • 1
  • 2
  • 11

4 Answers4

15

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

nybbler
  • 4,793
  • 28
  • 23
12

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

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();
    }
}
Danny
  • 437
  • 4
  • 11
  • Appreciate the work done by IKVM. But will IKVM provide support in case of any issues? Since this is not from IBM, they will not support. If installing whole client on all machines is the only issue, then it's possible to run applications with few MQ .NET assemblies and don't need the whole client to be installed. – Shashi May 29 '14 at 04:38
  • This is just an alternative approach that requires no installation of the WebSphere MQ client. Perhaps IBM could create a nuget deployment for an MQ client. – Danny May 29 '14 at 17:53
2

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

Shashi
  • 14,980
  • 2
  • 33
  • 52
0

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");
}
  • 1
    IBM Provides the native .NET and XMS.NET on Nuget already, why would you use this unsupported method of accessing IBM MQ Java libraries from .NT? See: https://www.nuget.org/packages/IBMMQDotnetClient – JoshMc Nov 04 '20 at 11:15