Exemple #1
0
        public void NAck(ReceivedMessage item)
        {
            var message = _inProcItems.FirstOrDefault(x => x.Message == item);

            if (message != null)
            {
                if (message.Transaction != null)
                {
                    message.Transaction.Rollback();
                    CloseConnection(message);
                }
                _inProcItems.Remove(message);
            }
        }
 public virtual void Init(ReceivedMessage message, int threadNumber)
 {
     Message      = message;
     ThreadNumber = threadNumber;
 }
Exemple #3
0
 public void Requeue(ReceivedMessage item)
 {
     _queue.Enqueue(item.Payload);
 }
Exemple #4
0
 public void Ack(ReceivedMessage item)
 {
 }
Exemple #5
0
        private void Execute()
        {
            int threadNo;

            lock (_counterLock)
            {
                threadNo = _counter;
                _counter++;
            }

            while (!_shutdown)
            {
                try
                {
                    ReceivedMessage item = _queue.TryDequeue(_timeOut);
                    if (item != null)
                    {
                        try
                        {
                            IWorker worker = CreateWorker(item, threadNo);
                            worker.StartLog();
                            if (worker.CanExecuteNow())
                            {
                                if (worker.AquireLock())
                                {
                                    try
                                    {
                                        worker.DoWork();
                                        try
                                        {
                                            worker.EndLog(true, false, false);
                                        }
                                        finally
                                        {
                                            _queue.Ack(item);
                                            worker.ReleaseLock();
                                            worker.Dispose();
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        _queue.Ack(item);
                                        worker.ReleaseLock();
                                        worker.EndLog(false, true, true);
                                        worker.Dispose();
                                        ex.Data.Add("PoolType", GetType().Name);
                                        ex.Data.Add("Key", item.Payload);
                                        //todo: send alert
                                    }
                                }
                                else
                                {
                                    //Thread.Sleep(2000);
                                    _queue.Ack(item);
                                    worker.EndLog(false, false, true);
                                    worker.Dispose();
                                }
                            }
                            else
                            {
                                _queue.Ack(item);
                                worker.EndLog(false, false, true);
                                worker.Dispose();
                                //_queue.Requeue(item);
                            }
                        }
                        catch (Exception ex)
                        {
                            Thread.Sleep(_timeOut); //throttle retries
                            _queue.Ack(item);
                            ex.Data.Add("PoolType", GetType().Name);
                            ex.Data.Add("Key", item.Payload);
                            //todo: send alert
                        }
                    }
                    else
                    {
                        Thread.Sleep(_timeOut); //no work
                    }
                }
                catch (Exception ex)
                {
                    //todo: send alert
                }
            }
        }