Connecting to MQSeries with. NET

Source: Internet
Author: User
Tags mqseries

By connecting to MQSeries withing a. NET application, first it have to been done was to install MQ Series client at the Machin E which would host the application.
To does, you can obtain for example the trial version of WebSphere MQ. During installation First the prerequisites is checked. Unfortunately if you try to install the package at Windows Vista, no wonder, it'll just fail, because the operative Syst EM is currently isn't supported by the setup. The good thing is, this requirement just can be ignored. Clearly that means, just install all other prerequisites and proceed with installation.

If you installed the Web Sphere on the local machine or somewhere in the Windows environment with Active Directory Infrast Ructure, there is a group named "MQM". The Windows user is running your. NET application have to being member of this group in order to be able to connect to MQ. In this case following code can is used to establish the connection and to put one simple message in the queue:

[TestMethod]
[Description ("Changes the status of one single event."),Owner ("Ddobric")]
Publicvoid MQ ()
        {
             mqqueuemanager queuemanager = new mqqueuemanager (" Qm_testmgr ", "MyChannel", "192.168.1.64");
            mqqueue Queue = Queuemanager.accessqueue (MQC. Mqoo_output + MQC. mqoo_fail_if_quiescing);
            mqmessage Queuemessage = new mqmessage ();

             Queuemessage.format = MQC. mqfmt_string;
            Queuemessage.messageid = new byte[" {0x01, 0x02, 0x03, 0x04};
            queuemessage.writestring ( "Hello World");

            Mqputmessageoptions queueputmessageoptions = new Mqputmessageoptions ();
            queue. Put (Queuemessage, queueputmessageoptions);

}

This code connects to the MQ manager ' Qm_testmgr ' by using the channel ' MyChannel ' hostet at the specified IP address. After executing your can see the message in the "default" of the queue.
Assume want now to connect to some remote. If You use this code, the connection to the QueueManager would fail with reason code 2035 = Not Authorized. To avoid this problem the MCA of the remote channel
Have to is explicitly set. To does, open the MQ Explorer go to channel properties and open the tab MCA. Then enter the name of the user, the authorized to connect. In the example bellow, I used the user "MQM".

Now the code in the. NET application have to is slightly changed as shown in the next example:

[TestMethod]
[Description ("Changes the status of one single event."),Owner ("Ddobric")]
Publicvoid MQ ()
{
            Hashtable props = new hashtable ();
            props. ADD (MQC. Host_name_property, "sopmqseries");
            props. ADD (MQC. Channel_property, M_channelname);
            props. ADD (MQC. User_id_property,             props. ADD (MQC. Password_property, "enter anything here.");

             Mqqueuemanager QueueManager = new mqqueuemanager (M_queuemanager, props);


             mqqueue queue = Queuemanager.accessqueue ( "default",
            Span style= "COLOR: #2b91af" >MQC. mqoo_output + MQC. mqoo_fail_if_quiescing);
            mqmessage Queuemessage = new mqmessage ();

             Queuemessage.format = MQC. mqfmt_string;
            Queuemessage.messageid = new byte[" {0x01, 0x02, 0x03, 0x04};
            queuemessage.writestring ( "Hello World");

            Mqputmessageoptions queueputmessageoptions = new Mqputmessageoptions ();
            queue. Put (Queuemessage, queueputmessageoptions);

}


At this point was important, that specified username "MQM" had to match the name set in the Mca-tab. Additionally it is int Eresting, that the password does is not having to match user's password, but it had to be specified as property.
If Password property was not specified at all, the initialization would crash with a "null reference error".

Last but not least. If you don't want to specify the username in your code, means-you-would like-to-use the first code example, there also on e a little confusing possibility. Create Some other user and put in the MQM group. The name of this user should is the same as the name of the user who would run the. NET application. In this case if the name of interactive user (running the application) matches the name of the user member of MQM g Roup at the remote system (this does not has the necessarily Windows system) you'll not need the provide credential P Roperties (MQC. User_id_property and MQC. Password_property) and MCA name may be empty.

By troubleshooting following very useful link contains the list of all reason codes.

Connecting to MQSeries with. NET

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.