MQ

 View Only
Expand all | Collapse all

From Azure Web Job .Net Appplication Connecting to IBM MQ

Shashikanth Rao Thambrahalli

Shashikanth Rao ThambrahalliThu April 15, 2021 11:30 AMBest Answer

  • 1.  From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed April 14, 2021 12:48 PM
    Dear Team,

    I created a .Net Application, this application I hosted in Azure Web Job, from the Web job I connecting to
    IBM MQ(to read read the message from the queue).

    Without MQ Client Installation can we establish the connection from the remote to the IBM MQ Server?
    Is MQ Client mandatory or prerequisites for .Net Application to connect MQ Server?

    ------------------------------
    Achyuth Reddy
    ------------------------------


  • 2.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Thu April 15, 2021 02:31 AM
    You don't need the entire MQ client installation, you can just use the MQ .NET Client from NuGet.

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 3.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Thu April 15, 2021 05:00 AM
    Thanks for the reply.

    Am using the stand alone IKVM.OpenJDK dll (Standalone dll's) is this fine to connect it?
    or any specific Nuget Package?


    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 4.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Thu April 15, 2021 05:07 AM
    I am bit confused. Initially you mentioned .NET, now you mention JDK. If your application is .NET, then you will need to use MQ .NET libraries.

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 5.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Thu April 15, 2021 07:34 AM
    Dear Shashi,

    In .Net Nuget Package this libraries are available so am planning to use this libraries instead of amqmdnetstd.dll.


    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 6.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ
    Best Answer

    Posted Thu April 15, 2021 11:30 AM
    The package you pointed out is not from IBM.  I suggest you to use the official MQ .NET package from IBM which is named IBMMQDotnetClient as described here. The package from IBM gets updated regularly with latest one being v 9.2.2 - https://www.nuget.org/packages/IBMMQDotnetClient.

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 7.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 12:50 AM
    Dear Shashi,

    I consumed the above sent nuget package but am getting an error "MQRC_MD_ERROR, 2026" while reading message from the queue.

    the below code to read message from the queue, am facing error at _mOutputQueue.Get method:

    _mGetOptions = new MQGetMessageOptions
    {
    WaitInterval = m_TmeOut,
    MatchOptions = MQC.MQMO_MATCH_CORREL_ID
    };
    _mGetOptions.Options |= MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_WAIT;
    _mOutputQueue.Get(_retrievedMessage, _mGetOptions);
    msgText = _retrievedMessage.ReadString(_retrievedMessage.MessageLength);

    Thanks for the Help.

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 8.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 01:01 AM
    You have specified MQC.MQMO_MATCH_CORREL_ID as the match option. But are you setting the required correlationId in _retrievedMessage.CorrelationId before calling Get method? That could be possible reason for 2026 reason code.

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 9.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 02:12 AM
    Dear Shashi,

    I removed the code _retrievedMessage.CorrelationId still no luck, Any other idea?

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 10.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 02:24 AM
    Can you show us the complete code? I think that would help in diagnosing the problem.

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 11.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 02:59 AM
    Edited by Achyuth Reddy Mon April 19, 2021 03:03 AM
    Pasted code below:
    private static string _readmq = string.Empty;
    public MQQueueManager _mQMgr;
    public static MQMessage _retrievedMessage;
    public MQQueue _mOutputQueue;
    private MQMessage _mqsMsg;
    private MQGetMessageOptions _mGetOptions;

    private void button2_Click(object sender, EventArgs e)
    {
    try
    {

    Hashtable connection = InitilizeMQConnection1();
    _mQMgr = new MQQueueManager(_mqManager, connection);
    const int outOpenOptions = MQC.MQOO_INPUT_AS_Q_DEF |
    MQC.MQOO_FAIL_IF_QUIESCING;
    _mOutputQueue = _mQMgr.AccessQueue(_readmq, outOpenOptions);
    string strResponseMessage = string.Empty;
    for (int i = 0; i < 10; i++)
    {
    strResponseMessage = GetMessage();
    }
    }
    catch (MQException ex)
    {
    string errorMsg = "Message : " + ex.Message + "error code :" + ex.ReasonCode;
    richTextBox1.Text = errorMsg;
    fileWriteline(errorMsg);
    filelog.Flush();
    }
    }

    private Hashtable InitilizeMQConnection1()
    {
    try
    {
    Hashtable connection = new Hashtable
    {
    { MQC.HOST_NAME_PROPERTY, _mqHost },
    { MQC.CHANNEL_PROPERTY, _mqChannel },
    { MQC.PORT_PROPERTY, Convert.ToInt64(_mqPort) },
    { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED }

    // { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT }
    };
    //connection.Add(MQC.USER_ID_PROPERTY, MQUserID);

    return connection;
    }
    catch (Exception ex)
    {
    string errorMsg = "Message : " + ex.Message;
    richTextBox1.Text = errorMsg;
    fileWriteline(errorMsg);
    filelog.Flush();
    return null;
    }
    }

    public string GetMessage()
    {
    string msgText = string.Empty;
    try
    {
    _mGetOptions = new MQGetMessageOptions
    {
    WaitInterval = m_TmeOut,
    };
    _mGetOptions.Options |= MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_WAIT;

    _mOutputQueue.Get(_retrievedMessage, _mGetOptions);
    msgText = _retrievedMessage.ReadString(_retrievedMessage.MessageLength);
    return msgText;

    }
    catch (MQException ex)
    {
    string errorMsg = string.Format("MQ Adapter:Get Message. Exception: Message [{0}], Source [{1}, Reason [{2}], Stack trace [{3}]", ex.Message, ex.Source, ex.Reason,ex.StackTrace.ToString());
    fileWriteline(errorMsg);
    return msgText;
    }
    catch (Exception ex)
    {
    string errorMsg = "An error occured " + ex.Message;
    }

    return msgText;
    }

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 12.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 05:19 AM
    As MoragH pointed out in another question, you have not initialized MQMessage. You just have public static MQMessage _retrievedMessage; at the top of your class. Is there a reason why you have made it global and static as well. I woud move the variable declaration to GetMessage method as below

    public string GetMessage()
    {
    MQMessage _retrievedMessage = new MQMessage(); <<== 
    string msgText = string.Empty;
    try
    {
    _mGetOptions = new MQGetMessageOptions
    {
    WaitInterval = m_TmeOut,
    };
    _mGetOptions.Options |= MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_WAIT;

    _mOutputQueue.Get(_retrievedMessage, _mGetOptions);
    msgText = _retrievedMessage.ReadString(_retrievedMessage.MessageLength);
    return msgText;

    }catch (MQException ex) {
    string errorMsg = string.Format("MQ Adapter:Get Message. Exception: Message [{0}], Source [{1}, Reason [{2}], Stack trace [{3}]", ex.Message, ex.Source, ex.Reason,ex.StackTrace.ToString());
    fileWriteline(errorMsg);
    return msgText;
    }catch (Exception ex){
       string errorMsg = "An error occured " + ex.Message;
    }

    return msgText;
    }
     


    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 13.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon April 19, 2021 06:55 AM
    Thanks Shashikanth.

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 14.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed April 21, 2021 02:19 AM
    Can I am assume problem is resolved?

    ------------------------------
    Shashikanth Rao Thambrahalli
    IBM
    ------------------------------



  • 15.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Sun May 23, 2021 10:43 AM
    Edited by Achyuth Reddy Sun May 23, 2021 10:44 AM
    Dear Shashi,

    Can we establish SSL Connection with  MQ .NET Client (amqmdnetstd.dll) (with out installing the MQ Client)?
    Can you please suggest me how to pass the certificate in the request?

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 16.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 12:49 AM

    ​Yes ,MQ .NET(amqmdnetstd.dll) supports SSL Connections. The certificates have to be installed on the machine where the client is running.

    If the client is running on Windows the certificates have to be installed in Windows keystore either manually or using .NET Class X509Store.

    Following link talks about how to set it up on Windows https://github.com/ibm-messaging/mq-dev-patterns/blob/master/dotnet/README.md

    If the client is running on Linux ,the certificates can be installed using the same .NET Class X509Store. Following link talks about how to install certificates on Linux.

    https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=fbad35e1-86ae-4a0b-3ebb-e990f6fd156e



    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 17.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 01:26 AM
    Dear Ram,

    Am unable to send the certificate in the request because of that request is failed.
    Below are the ways I tried to send the request:
    1. I install the Certificate and placed it in KeyStore 
    2. In the request I sent the below parameters
    { MQC.SSL_CERT_STORE_PROPERTY, "*SYSTEM"},
    { MQC.CERT_LABEL_PROPERTY,"mycertfriendlyname"}

    But still the request is failed.
    CERT_LABEL_PROPERTY is the friendly name of my certificate and SSL_CERT_STORE_PROPERTY I tried both SYSTEM and USER still no result.

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 18.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 01:39 AM

    Have you set the MQC.SSL_CIPHER_SPEC_PROPERTY property?Based on the cipher spec  the TLS version would be determined. If the property is not set then it would use the default version.

    What is the error that you are seeing? Please can you check the Queue Manager error logs.



    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 19.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 02:40 AM
    Edited by Achyuth Reddy Mon May 24, 2021 02:44 AM
    Dear Ram,

    I placed SSL_CIPHER_SPEC_PROPERTY in the request.

    But No MQ Client is installed on the server, Yes it mandatory to install the MQ Client for SSL Connection?

    Am connecting to the IBM MQ through the Standalone DLL (amqmdnetstd.dll) available in Nuget Package (IBMMQNotnetClient) because I need to connect MQ Manager through Azure PAAS (In PAAS we dnt have option to install the MQ Client).


    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 20.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 03:15 AM
    Yes, you can use IBMMQDotnetClient(Nuget package) for SSL Connection

    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 21.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 03:19 AM
    Edited by Achyuth Reddy Mon May 24, 2021 03:43 AM
    Thanks Ram,

    But am unable to pass the certificate in the request.

    i used the below parameter:

    { MQC.SSL_CERT_STORE_PROPERTY, "*SYSTEM"},
    { MQC.CERT_LABEL_PROPERTY,"mycertfriendlyname"}

    { MQC.SSL_CIPHER_SPEC_PROPERTY, "TLS_RSA_WITH_AES_128_CBC_SHA256" }, 
    Cipher Spec is correct i verified it with client.
    the remaining two property am not sure how it working?

    ------------------------------
    Achyuth Reddy
    ------------------------------



  • 22.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon May 24, 2021 03:54 AM
    What is the error that you see in the Queue manager error logs.

    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 23.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed November 08, 2023 11:17 AM

    Hi Ram,

    I am going to piggyback off of this thread regarding the use of the IBMMQDotnetClient and Azure.

    I have a very similar use case, but instead of connecting to MQ using a webjob, I am use an Azure web application. The previous poster did not mention where his MQ server is hosted, but for my use case our MQ server is hosted on our on-premise servers.

    My web application works as expected when its run from Visual Studio from my desktop PC connected to the same network where our MQ Server is hosted, but it fails when I invoke this web application from Azure even though we have an express route setup and other web apps are able to connect to on-premise databases.

    The error I am getting is as follows:


    System errorSystem.TypeInitializationException: The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
     ---> System.IO.FileNotFoundException: Error reading the  directory.
       at System.IO.FileSystemWatcher.StartRaisingEvents()
       at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
       at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
       at IBM.WMQ.MQClientCfg.CheckForMqclientIniFileChanges()
       at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
       at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
       at IBM.WMQ.MQQueueManager..cctor()
       --- End of inner exception stack trace ---
       at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, Hashtable properties)

    I am hoping that you might be able to shed some light on this error.

    Thanks,

    regards,

    Johnny



    ------------------------------
    Cho Hong Wan
    ------------------------------



  • 24.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed November 08, 2023 11:25 AM

    Hi Johnny, Please can you reach out to the IBM MQ Support team on this issue. 

    Thanks,
    Ram



    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 25.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    IBM Champion
    Posted Wed November 08, 2023 05:34 PM
    Sounds like you are not even reaching onprem yet.  There should be no issues if you have whitelisted the route (destination ip, source ip, port, etc).  Our developers are able to reach onprem MQ servers from Azure once the policy is approved and the whitelist policy is implemented.  Are you going thru a Palo Alto server (to screen out hackers, etc) from Azure to Onprem?





  • 26.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed November 08, 2023 08:08 PM

    Hi Susan,

    Thanks for the prompt response and confirmation that it should be possible to connect to on-prem MQ from an Azure web app. Ill reach out to our security team to ensure that connection to MQ from Azure is not blocked, but I am just a little puzzled by the error message I am getting as it does not really mention anything about connection errors which is expected if firewalls are an issue.

    Thanks,

    regards,

    Johnny



    ------------------------------
    Cho Hong Wan
    ------------------------------



  • 27.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed November 08, 2023 10:13 PM

    hi Susan,

    Could you advise if this nuget is expecting or creating and reading an external file, because the error message seems to suggest it is doing this?

    Thanks,

    regards,

    Johnny



    ------------------------------
    Cho Hong Wan
    ------------------------------



  • 28.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Wed November 08, 2023 11:34 PM

    Hi Johnny, it looks like a problem in some of the scenarios, please reach out to the IBM Support team. 

    Thanks,
    Ram



    ------------------------------
    Ram Subba Rao Chalamalasetti
    ------------------------------



  • 29.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Fri November 17, 2023 12:35 PM

    Hi Cho,

    I wonder if you was able to fix this issue, since I am having exactly the same scenario and the same exception, but in my case not able to find the solution yet.



    ------------------------------
    Mario Acosta
    ------------------------------



  • 30.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon November 27, 2023 01:58 PM

    I have found a workaround - all your need is to create empty mqclient.ini file in current directory. This is one line fix on the IBM side as well, not sure why they hadn't deployed it yet.

    PS Unfortunately, it seems like repeated process that amqmdnetstd.dll pushed to release without even simplest testing.



    ------------------------------
    Anatoly Zhmur
    ------------------------------



  • 31.  RE: From Azure Web Job .Net Appplication Connecting to IBM MQ

    Posted Mon November 27, 2023 01:58 PM

    Create empty mqclient.ini file in current directory to workaround this issue. Unfortunately, IBM doesn't test before pushing to production.



    ------------------------------
    Anatoly Zhmur
    ------------------------------