Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

ibm-mq

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

like image 318
shannu Avatar asked Feb 18 '12 06:02

shannu


People also ask

How do I connect to a queue manager in MQ?

To connect MQ Explorer to a queue manager: In the Navigator view, right-click the queue manager, then click Connect or Disconnect. MQ Explorer connects or disconnects the queue manager. The color of the queue manager's icon changes to yellow when connected, or gray when disconnected.


3 Answers

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

like image 107
Shashi Avatar answered Oct 19 '22 14:10

Shashi


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

like image 36
nybbler Avatar answered Oct 19 '22 13:10

nybbler


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();
    }
}
like image 42
Danny Avatar answered Oct 19 '22 12:10

Danny