Exemplo n.º 1
0
        /// <summary>
        /// Dispatch unprocessed messages.
        /// </summary>
        /// <param name="processManager">Dispatches all process manager commands.</param>
        private void DispatchMessages(IProcessManager processManager)
        {
            if (processManager.Commands != null)
            {
                var undispatched = new UndispatchedMessage(processManager.Id);

                context.Set <UndispatchedMessage>().Add(undispatched);// We create a undispatched object previous processing case of system crash.

                try
                {
                    while (processManager.Commands.Count > 0)
                    {// We process each command.
                        var command = processManager.Commands.Dequeue();
                        messagingRandomRetry.ExecuteAction(() => this.commandBus.Publish(command));
                    }
                }
                catch (Exception ex)
                {// Any kind of exception we recreate commands and update in database.
                    Exception outEx1 = null;
                    CQRSExceptionProcessor.HandleException(ex, out outEx1);

                    undispatched.Commands = this.serializer.Serialize(processManager.Commands);
                    sqlIncrementalRetry.ExecuteAction(() =>
                    {
                        context.SaveChanges();
                    });

                    throw outEx1;
                }
            }
        }
Exemplo n.º 2
0
        public void RetryDatabase()
        {
            SqlIncrementalRetry sql = new SqlIncrementalRetry();

            int i = 0;

            sql.ExecuteAction(() =>
            {
                if (i < 3)
                {
                    i++;
                    throw new TimeoutException("Retry " + i);
                }
            });

            Assert.AreEqual(i, 3);
        }