예제 #1
0
        private void ReDoSqlExecute(MSMQContext context, SqlMessageQueue messageQueue, int runTimes)
        {
            try
            {
                for (int i = 0; i < ConfigContext.GetInstance().ReDoExecuteCount; i++)
                {
                    runTimes++;
                    if (DoSqlExecute(messageQueue, runTimes))
                    {
                        LogHelper.WriteDebug(string.Format("Message queue [{0} times] re-execute Sql: {1} successfully!", runTimes, messageQueue.commandText));
                        return;
                    }
                }

                WriteErrorMSMQ(context.MsgConfig, messageQueue);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(string.Format("Queue reexecute {0} error:", context.MsgConfig.ManagerMessagePath), ex);
            }
        }
예제 #2
0
        private void StartWriteThread(object item)
        {
            MSMQContext context = item as MSMQContext;

            if (context == null)
            {
                return;
            }

            try
            {
                SafedQueue <SqlMessageQueue> msmqQueue = GetQueue(context.Index);
                while (true)
                {
                    try
                    {
                        while (msmqQueue.Count == 0)
                        {
                            Thread.Sleep(BufferWait);
                        }
                        List <SqlMessageQueue> smqBuffer = new List <SqlMessageQueue>(BufferMaxCount);
                        while (smqBuffer.Count < BufferMaxCount)
                        {
                            if (msmqQueue.Count == 0)
                            {
                                break;
                            }
                            SqlMessageQueue sqlMsgQueue;
                            if (msmqQueue.TryDequeue(out sqlMsgQueue))
                            {
                                smqBuffer.Add(sqlMsgQueue);
                            }
                            else
                            {
                                Thread.Sleep(SleepSeconds);
                            }
                        }
                        Interlocked.Exchange(ref writeCount, writeCount - smqBuffer.Count);
                        TraceWriteLine(string.Format("Queue [{0} _ {1}] has buffered {2} / {3}, remaining: {4}", context.MsgConfig.ManagerMessagePath, context.Index, smqBuffer.Count, BufferMaxCount, writeCount));

                        foreach (SqlMessageQueue itemQueue in smqBuffer)
                        {
                            if (itemQueue == null)
                            {
                                continue;
                            }
                            int runTimes = 0;
                            if (!DoSqlExecute(itemQueue, runTimes))
                            {
                                //失败重执行次数
                                ReDoSqlExecute(context, itemQueue, runTimes);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LogHelper.WriteException(string.Format("Queue write {0} error:", context.MsgConfig.ManagerMessagePath), e);
                    }
                }
            }
            catch (Exception error)
            {
                LogHelper.WriteException(string.Format("Queue write {0} error:", context.MsgConfig.ManagerMessagePath), error);
            }
        }
예제 #3
0
        private void ReDoSqlExecute(MSMQContext context, SqlMessageQueue messageQueue, int runTimes)
        {
            try
            {
                for (int i = 0; i < ConfigContext.GetInstance().ReDoExecuteCount; i++)
                {
                    runTimes++;
                    if (DoSqlExecute(messageQueue, runTimes))
                    {
                        LogHelper.WriteDebug(string.Format("Message queue [{0} times] re-execute Sql: {1} successfully!", runTimes, messageQueue.commandText));
                        return;
                    }
                }

                WriteErrorMSMQ(context.MsgConfig, messageQueue);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(string.Format("Queue reexecute {0} error:", context.MsgConfig.ManagerMessagePath), ex);
            }
        }