Exemplo n.º 1
0
        private void ExecuteProcessCommand(ProcessMessageCommand command)
        {
            var key = command.Message.Key;

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(key));
            }
            var mailbox = _mailboxDictionary.GetOrAdd(key, x =>
            {
                var box             = new Mailbox(key, _scheduler, _batchCount);
                box.OnMessageEmpty += Mailbox_OnMessageEmpty;
                return(box);
            });

            mailbox.EnqueueMessage(command.Message);
            _scheduler.ScheduleMailbox(mailbox);
        }
Exemplo n.º 2
0
        private void ExecuteProcessCommand(ProcessMessageCommand <IMessageContext> command)
        {
            var messageContext        = command.Message;
            var processingMessageFunc = command.ProcessingMessageFunc;
            var key = messageContext.Key;

            if (!string.IsNullOrWhiteSpace(key))
            {
                var mailbox = _mailboxDict.GetOrAdd(key, x =>
                {
                    return(new ProcessingMailbox <IMessageContext>(key, _processingMessageScheduler, processingMessageFunc, HandleMailboxEmpty));
                });
                mailbox.EnqueueMessage(messageContext);
                _processingMessageScheduler.ScheduleMailbox(mailbox);
            }
            else
            {
                _processingMessageScheduler.SchedulProcessing(() => processingMessageFunc(messageContext));
            }
        }