如何使用C#中的JNDI连接到IBM MQ?

发布于 2025-02-07 07:41:35 字数 708 浏览 1 评论 0原文

我目前可以使用IBMXMSDotNetClient连接到IBM MQ,直接在C#代码中指定Connection属性。

XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connFactory = factory.CreateConnectionFactory();
connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
connFactory.SetStringProperty(XMSC.WMQ_CHANNEL, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "xxx");

但是在Java中,似乎可以通过JNDI绑定文件来完成。

从我所看到的看来,JNDI像TNS文件(指定了TNS文件(指定详细信息详细信息),由客户端在Oracle中连接到Oracle中的服务器。 我的理解是否正确

?连接属性(connfactory.setxxxproperty)。

I am currently able to connect to a IBM MQ using IBMXMSDotnetClient by specifying the connection properties directly in the c# code like below.

XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connFactory = factory.CreateConnectionFactory();
connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
connFactory.SetStringProperty(XMSC.WMQ_CHANNEL, "xxx");
connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "xxx");

But in Java, it seems that it can be done by JNDI bindings file.

From what I can see, it looks like that JNDI is something like TNS file (which specifies the connection details such host, port, SID, etc.) used by the client to connect to server in Oracle. Is my understanding correct?

If it is the case, is it possible to connect to the IBM MQ by JNDI bindings files using IBMXMSDotnetClient? All examples I can find is to set the connection properties (connFactory.SetXXXProperty) directly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2025-02-14 07:41:35

我有这个片段来创建初始上下文并使用它来创建连接工厂和会议。希望它能让您入门。

        InitialContext ic = null;
        IConnectionFactory confac = null;
        IConnection conn = null;
        ISession sess = null;
        IMessageConsumer cons = null;
        IDestination dest = null;

        try
        {
            System.Collections.Hashtable env = new System.Collections.Hashtable();
            // Set the URL or PATH where the bindings file is located
            env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
            // Initialize the context
            ic = new InitialContext(env);
            // Lookup for the connection factory name
            confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
            // Create connection using the details from connection factory
            conn = (IConnection)confac.CreateConnection();
            // Create an auto ack session
            sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            // Lookup for the destination
            dest = (IDestination)ic.Lookup("myqueue");
            // ... rest of the code - create consumer or producer
        } 
        catch (XMSException xmsE)
        {
                // Handle exception
        }

I have this snippet to create initial context and use it to create connection factory and sessions. Hope it will get you started.

        InitialContext ic = null;
        IConnectionFactory confac = null;
        IConnection conn = null;
        ISession sess = null;
        IMessageConsumer cons = null;
        IDestination dest = null;

        try
        {
            System.Collections.Hashtable env = new System.Collections.Hashtable();
            // Set the URL or PATH where the bindings file is located
            env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
            // Initialize the context
            ic = new InitialContext(env);
            // Lookup for the connection factory name
            confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
            // Create connection using the details from connection factory
            conn = (IConnection)confac.CreateConnection();
            // Create an auto ack session
            sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            // Lookup for the destination
            dest = (IDestination)ic.Lookup("myqueue");
            // ... rest of the code - create consumer or producer
        } 
        catch (XMSException xmsE)
        {
                // Handle exception
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文