0

I use xms.net 8.0.0.8 and I want to start multithread xms listener in web application.

I start processmessage code with using new Thread t=new Thread()...

but something goes wrong,and threads are stuck and not read message?If someone has multithread xms sample for web application can share or tell my mistake?Or is this any bug for multithread in 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)
    {
JoshMc
  • 10,239
  • 2
  • 19
  • 38
Bilgehan
  • 1,135
  • 1
  • 14
  • 41

1 Answers1

1

None of that looks right. Multi-threading requires in-depth programming knowledge. Where is your ThreadStart? Make sure each thread is performing its own connection to the queue manager. Also, are you defining 1 MessageListener for all threads or does each thread have its own MessageListener? Because it looks like you are using 1 for all threads which defeats multi-threading.

Did you read the MQ Knowledge Center on MessageListener and how to handle mutlit-threading: https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.xms.doc/xms_cmesdel_async.htm

Roger
  • 7,062
  • 13
  • 20