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.