Message driven bean in C#

主宰稳场 提交于 2019-12-08 13:20:40

问题


Can any one suggest me code to write a message driven bean in C#.net to listen a MQ and process the same.


回答1:


XMS will be pretty similar to JMS. This is a "hello, world" example of a message listener in C# using XMS. Please include the reference IBM.XMS.dll from your websphere mq installation.

On my windows installation, 32bit, it was

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

This sample assumes a few hardcoded settings and have no error handling, but I think you get the idea.

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);
        }
    }
}



回答2:


MDB will be in Java. I am not aware if there is an application server that can handle MDB written in C#.

If your idea is to receive WebSphere MQ messages asynchronously using a C# application, then you can use XMS .NET which has a Message listener.



来源:https://stackoverflow.com/questions/11445728/message-driven-bean-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!