public async Task <BsonValue> CreateMessageBackup(Command command, QueueActionsEnum action = QueueActionsEnum.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null)
        {
            try
            {
                if (command?.InternalMessageIdentifier == null || command.InternalMessageIdentifier.IsNullOrEmptyGuid())
                {
                    throw new ArgumentException($"The provided command  and the command identifier cannot be null ");
                }

                var backUp = new RabbitBackup
                {
                    Id = Guid.NewGuid(),
                    InternalMessageIdentifier = command.InternalMessageIdentifier,
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command),
                    MessageType    = command.MessageType,
                    TimeStampUTC   = command.Timestamp.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                var result = RabbitMqBackupLiteDbRepository.Create(backUp);

                return(result);
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error($"Error storing data with LiteDb: {ex.Message} {ex.InnerException}");
                Devon4NetLogger.Error(ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <RabbitBackup> CreateMessageBackup(Command command, QueueActionsEnum action = QueueActionsEnum.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null)
        {
            RabbitMqBackupContext ctx = null;

            try
            {
                ctx = CreateContext();

                if (ctx == null)
                {
                    throw new ArgumentException("The database provider is not supported to host threads");
                }

                if (!UseExternalDatabase)
                {
                    throw new ArgumentException(
                              "Please setup your RabbitMqBackupContext database context to use RabbitMqBackupService");
                }

                if (command?.InternalMessageIdentifier == null || command.InternalMessageIdentifier.IsNullOrEmptyGuid())
                {
                    throw new ArgumentException($"The provided command  and the command identifier cannot be null ");
                }

                var backUp = new RabbitBackup
                {
                    Id = Guid.NewGuid(),
                    InternalMessageIdentifier = command.InternalMessageIdentifier,
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command),
                    MessageType    = command.MessageType,
                    TimeStampUTC   = command.Timestamp.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                var result = await ctx.RabbitBackup.AddAsync(backUp).ConfigureAwait(false);

                await ctx.SaveChangesAsync().ConfigureAwait(false);

                return(result.Entity);
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
            finally
            {
                if (ctx != null)
                {
                    await ctx.DisposeAsync().ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 3
0
        private async Task BackUpMessage(T command, QueueActionsEnum queueAction = QueueActionsEnum.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null)
        {
            try
            {
                RabbitMqBackupLiteDbService?.CreateMessageBackup(command, queueAction, increaseRetryCounter, additionalData, errorData);

                if (RabbitMqBackupService != null && RabbitMqBackupService.UseExternalDatabase)
                {
                    await RabbitMqBackupService.CreateMessageBackup(command, queueAction, increaseRetryCounter, additionalData, errorData).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
        }