Esempio n. 1
0
        public void InitLimitTime <T, T2>(Func <T, T2> act, string queueSuccessQueue, string queueFail, string labelField = "")
        {
            action = new Action <object>((object obj) =>
            {
                try
                {
                    int LIMIT_SUGGEST_TIME = 90;

                    string errorReason = string.Empty;

                    Thread workerThread = new Thread(() =>
                    {
                        try
                        {
                            T2 result          = act.Invoke((T)obj);
                            RabbitQueue sender = new RabbitQueue(queueSuccessQueue);
                            sender.SendMessage <T2>((T2)result);
                        }
                        catch (Exception ex)
                        {
                            T2P._2015.Cross.Utility.ExceptionHandling.ExceptionHelper.GetDetailMessageAndLog(ex);
                            ExceptionHelper.GetDetailMessageAndLog(ex);
                            RabbitQueue sender = new RabbitQueue(queueFail);
                            sender.SendMessage <T>((T)obj);
                        }
                        finally
                        {
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                            GC.Collect();
                        }
                    });

                    workerThread.Start();
                    DateTime timeNow = DateTime.Now;
                    while (workerThread.IsAlive)
                    {
                        var countSeconds = DateTime.Now.Subtract(timeNow).TotalSeconds;
                        if (countSeconds >= LIMIT_SUGGEST_TIME)
                        {
                            T2P._2015.Cross.Utility.Log.Logging.Info("Time out:" + errorReason);
                            workerThread.Abort();
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHelper.GetDetailMessageAndLog(ex);
                    RabbitQueue sender = new RabbitQueue(queueFail);
                    sender.SendMessage <T>((T)obj);
                }
            });

            listener.FommatType       = typeof(T);
            listener.MessageReceived += MessageReceivedEvent;
            listener.Listener();
        }
Esempio n. 2
0
 public void Init <T>(Action <T> act, string pushFailQueue = "", string labelField = "")
 {
     action = new Action <object>((object obj) =>
     {
         try
         {
             act.Invoke((T)obj);
         }
         catch (Exception ex)
         {
             ExceptionHelper.GetDetailMessageAndLog(ex);
             RabbitQueue sender = new RabbitQueue(pushFailQueue);
             sender.SendMessage <T>((T)obj);
         }
     });
     listener.FommatType       = typeof(T);
     listener.MessageReceived += MessageReceivedEvent;
     listener.Listener();
 }
Esempio n. 3
0
        public void Init <T, T2>(Func <T, T2> act, string queueSuccessQueue, string queueFail, string labelField = "")
        {
            action = new Action <object>((object obj) =>
            {
                try
                {
                    T2 result          = act.Invoke((T)obj);
                    RabbitQueue sender = new RabbitQueue(queueSuccessQueue);
                    sender.SendMessage <T2>((T2)result);
                }
                catch (Exception ex)
                {
                    ExceptionHelper.GetDetailMessageAndLog(ex);
                    RabbitQueue sender = new RabbitQueue(queueFail);
                    sender.SendMessage <T>((T)obj);
                }
            });

            listener.FommatType       = typeof(T);
            listener.MessageReceived += MessageReceivedEvent;
            listener.Listener();
        }