0

我使用 xms.net 8.0.0.8,我想在 Web 应用程序中启动多线程 xms 侦听器。

我使用 new Thread t=new Thread()... 开始处理消息代码

但是出了点问题,线程被卡住并且没有读取消息?如果有人有 Web 应用程序的多线程 xms 示例可以分享或告诉我的错误?或者这是 xms 中多线程的任何错误?

public void ProcessMessage()
    {
        try
        {

            ConnectionFactory = WsHelper.CreateConnectionFactoryWMQ();
            Connection = WsHelper.CreateConnection(ConnectionFactory);
            if (QueueMessage.MessageCallType == MessageCallType.WithoutControl)
                Session = WsHelper.CreateSessionWithAutoAcknowledge(Connection);
            else
                Session = WsHelper.CreateSessionWithSessionTransaction(Connection);
            Destination = WsHelper.CreateDestination(Session, QueueMessage.QueueName);
            MessageConsumer = WsHelper.CreateConsumer(Session, Destination, QueueMessage);

            MessageListener messageListener = new MessageListener(NewMessageProcess);
            MessageConsumer.MessageListener = messageListener;
            this.Connection.Start();

            while (true)
            {
                if (stopping)
                {
                    MessageConsumer.Close();
                    return;
                }

                Thread.Sleep(1000);
            }
        }
        catch(ThreadAbortException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
    private void NewMessageProcess(IBM.XMS.IMessage msg)
    {
4

1 回答 1

1

这些看起来都不对。多线程需要深入的编程知识。你的 ThreadStart 在哪里?确保每个线程都在执行自己与队列管理器的连接。另外,您是为所有线程定义 1 个 MessageListener 还是每个线程都有自己的 MessageListener?因为看起来您对所有线程都使用了 1 ,这会破坏多线程。

您是否阅读了有关 MessageListener 以及如何处理多线程的 MQ 知识中心: https ://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.xms.doc/xms_cmesdel_async.htm

于 2018-04-03T20:33:47.350 回答