Processing messages fast from MSMQ in parallel fro

2019-09-08 10:43发布

Our service run continuously 24/7 in a company, which retreives messages from MSMQ and after processing write result in DB. What we observe that our criteria of working with MSMQ is so old, and doesn't process many messages at a time, we need to process at least 200 or 250 transaction per second in a process, but what we uses only process 10 to 14 transaction in a second.

implementation Of our Code is

     while (true)//(count < 2)
        {
            response = "";
            try
            {
                rcvMsg = MQ.Receive(new TimeSpan(0, 0, QTimeOut)); //Receive Messages from Message Queue
                IsReceivedTran = true;
                rcvMsg.Formatter = new XmlMessageFormatter(types);     //Replace as one time scenerio               
                response = rcvMsg.Body.ToString();
                Msg = new Message();
                Msg.Populate(response.ToString());
                switch (Msg.TxnType)
                {
                    case Cloud.MessageLibrary.TXNTYPE.C1:
                        {
                            ThreadPool.QueueUserWorkItem(TXN1.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C2:
                        {
                            ThreadPool.QueueUserWorkItem(TXN2.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C3:
                        {
                            ThreadPool.QueueUserWorkItem(TXN3.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C4:
                        {
                            ThreadPool.QueueUserWorkItem(TXNCHWREV.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C5:
                        {
                            //Action<
                            //Task.Factory.StartNew(TXN5.callBack, Msg);
                            ThreadPool.QueueUserWorkItem(TXN5.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C6:
                        {
                            ThreadPool.QueueUserWorkItem(TXN6.callBack, Msg);
                            break;
                        }
                    case Cloud.MessageLibrary.TXNTYPE.C7:
                        {
                            ThreadPool.QueueUserWorkItem(TXN7.callBack, Msg);
                            break;
                        }
                    default:
                        {
                            ThreadPool.QueueUserWorkItem(callBack, Msg);
                            break;
                        }
                }

            }
            catch (MessageQueueException ex)
            {
                Thread.Sleep(10);
            }
            catch (Exception exp)
            {
                Thread.Sleep(10);
            }
        }

As we have multiple types of Messages, we need to process all of them, every message took approx 700ms, Is there any way to process 250 to 200 messages in a second?

Note: We are allow to go to max version of .Net.

0条回答
登录 后发表回答