Processing messages fast from MSMQ in parallel from Windows Services

扶醉桌前 提交于 2019-12-12 04:57:18

问题


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.

来源:https://stackoverflow.com/questions/42135159/processing-messages-fast-from-msmq-in-parallel-from-windows-services

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