簡體   English   中英

.net應用程序和IBM Websphere MQ集成

[英].net Application and IBM Websphere MQ Integration

我是IBM Websphere MQ的新手,正在嘗試將消息從.net應用程序傳遞到駐留在Remote Box上的WebSphere MQ。

我正在嘗試此鏈接上提供的示例代碼

我的代碼如下,在Windows應用程序中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBM.WMQ;
using System.Collections;

namespace MQTest
{
class MQSample
{
    // The type of connection to use, this can be:-
    // MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
    // MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
    // MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
    // MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
    const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;

    // Define the name of the queue manager to use (applies to all connections)
    const String qManager = "QM785";

    // Define the name of your host connection (applies to client connections only)
  //  const String hostName = "NSL-D254(1785)";

    // Define the name of the channel to use (applies to client connections only)
 //   const String channel = "785.FIN.IDMS";



    /// <summary>
    /// Initialise the connection properties for the connection type requested
    /// </summary>
    /// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
    static Hashtable init(String connectionType)
    {
        Hashtable connectionProperties = new Hashtable();
        connectionProperties.Add(MQC.HOST_NAME_PROPERTY, "NSL-D254(1785)");
        connectionProperties.Add(MQC.CHANNEL_PROPERTY, "785.FIN.IDMS");
        connectionProperties.Add(MQC.USER_ID_PROPERTY, "NSLDC\truptir");
        connectionProperties.Add(MQC.PASSWORD_PROPERTY, "july@1234");

        // Add the connection type
        connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);

        // Set up the rest of the connection properties, based on the
        // connection type requested
        switch (connectionType)
        {
            case MQC.TRANSPORT_MQSERIES_BINDINGS:
                break;
            case MQC.TRANSPORT_MQSERIES_CLIENT:
            case MQC.TRANSPORT_MQSERIES_XACLIENT:
            case MQC.TRANSPORT_MQSERIES_MANAGED:
               // connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
              //  connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                break;
        }

        return connectionProperties;
    }
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static int Main(string[] args)
    {
        try
        {
            Hashtable connectionProperties = init(connectionType);
           // Environment.SetEnvironmentVariable("MQCCSID", "437");
            // Create a connection to the queue manager using the connection
            // properties just defined
            MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

            // Set up the options on the queue we want to open
            int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

            // Now specify the queue that we want to open,and the open options
            MQQueue system_default_local_queue =
              qMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);

            // Define a WebSphere MQ message, writing some text in UTF format
            MQMessage hello_world = new MQMessage();
            hello_world.WriteUTF("Hello World!");

            // Specify the message options
            MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
            // same as MQPMO_DEFAULT

            // Put the message on the queue
            system_default_local_queue.Put(hello_world, pmo);



            // Get the message back again

            // First define a WebSphere MQ message buffer to receive the message
            MQMessage retrievedMessage = new MQMessage();
            retrievedMessage.MessageId = hello_world.MessageId;

            // Set the get message options
            MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults
            //same as MQGMO_DEFAULT

            // Get the message off the queue
            system_default_local_queue.Get(retrievedMessage, gmo);

            // Prove we have the message by displaying the UTF message text
            String msgText = retrievedMessage.ReadUTF();
            Console.WriteLine("The message is: {0}", msgText);

            // Close the queue
            system_default_local_queue.Close();

            // Disconnect from the queue manager
            qMgr.Disconnect();
        }

        //If an error has occurred in the above,try to identify what went wrong.

        //Was it a WebSphere MQ error?
        catch (MQException ex)
        {
            Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
        }

        catch (System.Exception ex)
        {
            Console.WriteLine("A System error occurred: {0}", ex.ToString());
        }

        return 0;
    }//end of start
}//end of sample

}

但是我正在關注WebSphere MQ錯誤MQRC_HOST_NOT_AVAILABLE

我從開發機器ping了遠程計算機,反之亦然,這很好。

IBM WebSphere MQ設置:

-IBM WebSphere MQ已安裝在遠程計算機上

-創建的隊列管理器

-本地隊列

-服務器連接通道(顯示非活動狀態)

-在“服務器連接”通道屬性下,我提供了MCA用戶ID

-偵聽器狀態顯示正在運行

我有什么遺漏嗎,請讓我知道。

您很可能需要指定端口,隊列管理器偵聽器配置在:

const String hostName = "NSL-D254(1414)";

1414是默認值,因此最好在隊列管理器上檢查它,然后首先嘗試使用telnet。

我知道這是一個舊線程,但是最近我們對使用7.0.1.4的測試應用程序遇到了類似的問題,發現底層程序集在連接數據包中包括運行該應用程序的用戶名。

為了解決這個問題,我們以PSExec作為系統用戶運行了該應用程序。 瞧,連接又重新開始了。 舊版生產服務也以LocalSystem的身份運行,因此它以用戶身份傳遞System。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM