0

MQをリッスンして同じ処理を行うためにC#.netでメッセージ駆動型Beanを作成するコードを提案してもらえますか?

4

2 に答える 2

1

XMS は JMS にかなり似ています。これは、XMS を使用した C# のメッセージ リスナーの "hello, world" の例です。Websphere mq インストールから参照 IBM.XMS.dll を含めてください。

私のWindowsインストールでは、32ビットでした

c:\Program Files\IBM\WebSphere MQ\bin\IBM.XMS.dll

このサンプルでは、​​いくつかのハードコードされた設定が想定されており、エラー処理はありませんが、おわかりいただけたと思います。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBM.XMS;

namespace XMSTest
{
    class MyXmsApp
    {
        static void Main(string[] args)
        {
            MyXmsApp app = new MyXmsApp();
            app.Setup();
            Console.ReadLine();
        }

        public void Setup()
        {
            XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
            IConnectionFactory cf = xff.CreateConnectionFactory();
            cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "localhost");
            cf.SetIntProperty(XMSC.WMQ_PORT, 1414);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, "CLIENT");
            cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
            cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM_LOCAL");
            cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);

            IConnection conn = cf.CreateConnection();
            Console.WriteLine("connection created");
            ISession sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            IDestination dest = sess.CreateQueue("queue://q");
            IMessageConsumer consumer = sess.CreateConsumer(dest);
            MessageListener ml = new MessageListener(OnMessage);
            consumer.MessageListener = ml;
            conn.Start();
            Console.WriteLine("Consumer started");
        }

        private void OnMessage(IMessage msg)
        {
            ITextMessage textMsg = (ITextMessage)msg;
            Console.Write("Got a message: ");
            Console.WriteLine(textMsg.Text);
        }
    }
}
于 2012-07-14T10:20:48.150 に答える
0

MDB は Java になります。C# で書かれた MDB を処理できるアプリケーション サーバーがあるかどうかはわかりません。

C# アプリケーションを使用して WebSphere MQ メッセージを非同期的に受信することを考えている場合は、メッセージ リスナーを備えたXMS .NETを使用できます。

于 2012-07-12T09:17:03.787 に答える