예제 #1
0
        public void RunError()
        {
            MessageConfig config = ConfigContext.GetInstance().SysMessageConfig;
            string pcName = Dns.GetHostName();
            HashSet<string> queuqHash = new HashSet<string>();
            new Thread(() =>
            {
                while (true)
                {
                    var messageList = MessageQueue.GetPrivateQueuesByMachine(pcName);
                    foreach (var messageQueue in messageList)
                    {
                        if (messageQueue.QueueName.ToLower().IndexOf("errorlogcmdsql") != -1)
                        {
                            if (!queuqHash.Contains(messageQueue.QueueName))
                            {
                                queuqHash.Add(messageQueue.QueueName);

                                MessageConfig tempConfig = new MessageConfig();
                                tempConfig.IsErrorQueue = true;
                                tempConfig.ManagerName = config.ManagerName;
                                tempConfig.ManagerThreadNumber = config.ManagerThreadNumber;
                                tempConfig.ManagerThreadTimeOut = config.ManagerThreadTimeOut;
                                tempConfig.ManagerMessagePath = messageQueue.Path;
                                tempConfig.ManagerErrorPath = config.ManagerErrorPath;
                                new Thread(new MSMQDistribution().Receive).Start(tempConfig);
                            }
                        }
                    }
                    Thread.Sleep(60000);
                }
            }).Start();
        }
예제 #2
0
 /// <summary>
 /// 自定义的相关配置项信息初始化
 /// </summary>
 private void Init()
 {
     try
     {
         SysMessageConfig = (MessageConfig)ConfigurationManager.GetSection("messageConfig");
         ConnctionString = ConfigHelper.GetSetting("messageConnection");
         ReDoExecuteCount = ConfigHelper.GetSetting("messageReDoExecuteCount").ToInt32(1);
     }
     catch
     {
         throw;
     }
 }
예제 #3
0
        /// <summary>
        /// 写入异常处理队列
        /// </summary>
        private void WriteErrorMSMQ(MessageConfig msgConfig, SqlMessageQueue messageQueue)
        {
            try
            {
                if (msgConfig.IsErrorQueue)
                {
                    if (messageQueue != null)
                    {
                        SaveToLog(messageQueue);
                    }
                    return;
                }
                MessageQueue mq = CreateErrorMQ(msgConfig);

                Message message = new Message();
                message.Label = Convert.ToString(MSMQCmd.SendSQLCmd);
                message.Formatter = new XmlMessageFormatter(new Type[] { typeof(SqlMessageQueue) });
                message.Body = messageQueue;
                mq.Send(message, MessageQueueTransactionType.Automatic);

            }
            catch (Exception ex)
            {
                LogHelper.WriteException(string.Format("Write error exception handling queue:{0}", ex.Message), ex);
            }
        }
예제 #4
0
 public MSMQContext(MessageConfig msgConfig, int index)
 {
     Index = index;
     MsgConfig = msgConfig;
 }
예제 #5
0
        private void InitQueue(MessageConfig msgConfig)
        {
            if (msgConfig == null) return;

            if (msgConfig.ManagerThreadNumber == 0)
            {
                throw new Exception("ManagerThreadNumber is error.");
            }
            _distribeCollection = new Dictionary<int, SafedQueue<SqlMessageQueue>>(msgConfig.ManagerThreadNumber);
            for (int i = 0; i < msgConfig.ManagerThreadNumber; i++)
            {
                if (!_distribeCollection.ContainsKey(i))
                {
                    _distribeCollection.Add(i, new SafedQueue<SqlMessageQueue>());
                }
                else
                {
                    _distribeCollection[i] = new SafedQueue<SqlMessageQueue>();
                }
                new Thread(StartWriteThread).Start(new MSMQContext(msgConfig, i));
            }
        }
예제 #6
0
        private MessageQueue CreateErrorMQ(MessageConfig msgConfig)
        {
            if (_errorMQ == null)
            {
                lock (syncRoot)
                {
                    if (_errorMQ == null)
                    {
                        if (!MessageQueue.Exists(msgConfig.ManagerErrorPath))
                        {
                            MessageQueue.Create(msgConfig.ManagerErrorPath, false);
                        }
                        _errorMQ = new MessageQueue(msgConfig.ManagerErrorPath, QueueAccessMode.Send);
                        _errorMQ.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
                    }

                }
            }

            return _errorMQ;
        }