예제 #1
0
        ///// <summary>
        ///// 调用消息处理结果。
        ///// </summary>
        //protected abstract void OnMessageHandled(TMessage payload);
        /// <summary>
        /// 调用消息处理结果。
        /// </summary>
        protected virtual void Process(TMessage message)
        {
            int count      = 0;
            int retryTimes = 1;

            if (message is IRetry)
            {
                retryTimes = (message as IRetry).RetryTimes;
            }
            while (++count <= retryTimes)
            {
                try {
                    _messageExecutor.Execute(message);
                    _messageStore.Remove(_messageTypeName, message.Id);
                    break;
                }
                catch (Exception) {
                    if (count == retryTimes)
                    {
                        throw;
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
        }
        public void Handle(T batch)
        {
            BatchStart(batch);

            batch.Messages.Each(x => _executor.Execute(x));

            BatchFinish(batch);
        }
예제 #3
0
        public void Tick()
        {
            while (true)
            {
                if (messages.Count <= 0)
                {
                    return;
                }

                Message          msg      = messages.Dequeue();
                IMessageExecutor executor = null;
                if (executors.TryGetValue(msg.messageID, out executor))
                {
                    executor.Execute(msg);
                }
                msg.Release();
            }
        }