Connecting to Remote IBM WebSphere MQ Server

by vj 13. May 2008 23:14

The below post will provide a "hello world" kind of introduction to connecting to a remote IBM WebSphere Message Queue server using client application written in C#.

Points to note:

  • Server and client should have a common OS login name. The passwords can be different between the server and client, what matters is that the login name should be identical.
  • The login name you have selected to use should be part of the MQM group on the MQ server, or it should be explicitly given permission for querying the Queue manager and the queue.
  • I have come across code on the web where they have mentioned how to connect to MQ server even with a different OS login name from the client side by explicitly setting the login and password onto the MQEnviroment class static properties, but it has not worked for me till now. So, my example code would be assuming that there is an identical login name between the client and server.
  • Make a note of the Server-connection channel name (case sensitive), queue manager name (case sensitive), queue name (case sensitive) from the server side.
  • You would need to install at the least the client package of MQ onto the client machine, the client code would be using the library from this installation to connect to the server.
  • A reference to amqmdnet.dll would have to be added to the client project, its located in <MQ Installation Path>\bin\amqmdnet.dll

 

Now for the code

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using IBM.WMQ;
   5:   
   6:  namespace RemoteMQTest {
   7:      class Test01 {
   8:          static void Main(string[] args) {
   9:              MQEnvironment.Hostname = "My_Server";
  10:              MQEnvironment.Channel = "My_Channel";
  11:   
  12:              string mqQueueManagerName = "My_Q_Manager";
  13:              string mqQueueName = "My_Queue";
  14:              int openOptions = MQC.MQOO_INPUT_AS_Q_DEF;
  15:   
  16:              MQQueueManager qMgr = new MQQueueManager(mqQueueManagerName);
  17:              MQQueue q = qMgr.AccessQueue(mqQueueName, openOptions);
  18:   
  19:              MQMessage message = new MQMessage();
  20:              message.Version = 2;
  21:   
  22:              q.Get(message);
  23:   
  24:              Console.WriteLine("I got the message : {0}", message.ReadString(message.DataLength));
  25:              message.Seek(0);
  26:   
  27:   
  28:              q.Close();
  29:              qMgr.Close();
  30:              Console.WriteLine("done!");
  31:          }
  32:      }
  33:  }

Note that in line 25, we are explicitly making the message to seek back to 0th byte.

 

Happy coding Happy

Tags: ,

Technology | References

Comments

7/13/2010 9:48:43 AM #

vogue

http://www.voguemarie.com/

vogue United States | Reply

7/19/2010 2:31:04 PM #

Dubai Furnished Apartments

I am really stunned by the facts provided by the author. I will recommend my friends to visit this site.

Dubai Furnished Apartments United States | Reply

8/25/2010 8:10:01 PM #

Arturo Nicometo

This is what has been bugging me for few days.Many thanks for the very plain explanation.. You save me lots of headaches. Many thanks again!

Arturo Nicometo United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading