Exemple #1
0
        public void Execute(MessageContext messagecontext, Action <MessageContext, MiddlewareContext> next, MiddlewareContext middlewarecontext)
        {
            var data = Activator.CreateInstance(messagecontext.Saga.DataType);

            var storage = _factory.Create <ISagaStorage>(Configuration.SagaStorageType);

            var serializer = _factory.Create <IMessageSerializer>(Configuration.MessageSerializerType);

            messagecontext.SagaContext.Status = DefaultStatus;

            var sagaentity = CreateSagaEntity(messagecontext);

            sagaentity.Data = serializer.Serialize(data);

            messagecontext.SagaContext.Id = storage.CreateSaga(messagecontext, sagaentity);

            messagecontext.AddTrack(messagecontext.Identity, messagecontext.Origin, messagecontext.Route, messagecontext.Saga, messagecontext.SagaContext);

            _router.Route(messagecontext, data);

            sagaentity.Updated = messagecontext.DateTimeUtc;

            SaveSaga(messagecontext, storage, sagaentity, serializer, data);

            SaveMessage(messagecontext, storage, sagaentity);
        }
Exemple #2
0
        public void Execute(MessageContext context, Action next, MiddlewareParameter parameter)
        {
            var storage = _factory.Create <IStorage>(_configuration.StorageType);

            var serializer = _factory.Create <IMessageSerializer>(_configuration.MessageSerializerType);

            var sagaentity = storage.GetSaga(context.SagaContext.Id);

            context.SagaContext.Status = DefaultStatus;

            if (sagaentity != null)
            {
                var data = serializer.Deserialize(sagaentity.Data, parameter.Saga.DataType);

                context.AddTrack(context.Id, context.Origin.Key, context.Origin.From, parameter.Route.Name, context.SagaContext.Id, parameter.Saga.Name);

                if (data != null)
                {
                    _router.Route(context, parameter.Route, data, parameter.Saga.DataType);

                    sagaentity.Data = serializer.Serialize(data);

                    sagaentity.Ended = context.DateTimeUtc;

                    sagaentity.Status = context.SagaContext.Status;

                    sagaentity.Duration = (sagaentity.Ended.Value - sagaentity.Created).TotalMilliseconds;

                    storage.UpdateSaga(context, context.SagaContext.Id, sagaentity);

                    var message = CreateMessageEntity(context, parameter, sagaentity);

                    try
                    {
                        storage.CreateMessage(context, context.SagaContext.Id, sagaentity, message);
                    }
                    catch (Exception)
                    {
                        if (!_configuration.Storage.IgnoreExceptionOnSaveMessage)
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    throw new ApplicationException($"Empty/Invalid data {parameter.Saga.DataType.FullName} for {parameter.Route.ContentType.FullName}, saga {parameter.Saga.Name}");
                }
            }
            else
            {
                throw new ApplicationException($"No data {parameter.Saga.DataType.FullName} for {parameter.Route.ContentType.FullName}, saga {parameter.Saga.Name}");
            }
        }
        public void Execute(MessageContext context, Action next, MiddlewareParameter parameter)
        {
            var data = Activator.CreateInstance(parameter.Saga.DataType);

            var storage = _factory.Create <IStorage>(_configuration.StorageType);

            var serializer = _factory.Create <IMessageSerializer>(_configuration.MessageSerializerType);

            context.SagaContext.Status = DefaultStatus;

            var sagaentity = CreateSagaEntity(context, parameter);

            sagaentity.Data = serializer.Serialize(data);

            var id = storage.CreateSaga(context, sagaentity);

            context.SagaContext.Id = id;

            context.AddTrack(context.Id, context.Origin.Key, context.Origin.From, parameter.Route.Name, context.SagaContext.Id, parameter.Saga.Name);

            _router.Route(context, parameter.Route, data, parameter.Saga.DataType);

            sagaentity = storage.GetSaga(id);

            if (sagaentity != null)
            {
                sagaentity.Data = serializer.Serialize(data);

                sagaentity.Updated = context.DateTimeUtc;

                sagaentity.Status = context.SagaContext.Status;

                storage.UpdateSaga(context, id, sagaentity);

                var messageentity = CreateMessageEntity(context, parameter, sagaentity);

                try
                {
                    storage.CreateMessage(context, id, sagaentity, messageentity);
                }
                catch (Exception)
                {
                    if (!_configuration.Storage.IgnoreExceptionOnSaveMessage)
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new ApplicationException($"No data {parameter.Saga.DataType.FullName} for {parameter.Route.ContentType.FullName}, saga {parameter.Saga.Name}");
            }
        }
Exemple #4
0
        public void Execute(MessageContext context, Action next, MiddlewareParameter parameter)
        {
            var storage = _factory.Create <IStorage>(_configuration.StorageType);

            context.AddTrack(context.Id, context.Origin.Key, context.Origin.From, parameter.Route.Name);

            if (_configuration.Storage.SaveMessage)
            {
                var message = new MessageEntity()
                {
                    Content     = context.ContentAsString,
                    ContentType = context.Route.ContentType.FullName,
                    Id          = context.Id,
                    Version     = context.Version,
                    RetryCount  = context.RetryCount,
                    LastRetry   = context.LastRetry,
                    Origin      = context.Origin,
                    Headers     = context.Headers,
                    DateTimeUtc = context.DateTimeUtc,
                    Name        = context.Route.Name,
                    Tracks      = context.Tracks
                };

                try
                {
                    storage.CreateMessage(context, message);
                }
                catch (Exception)
                {
                    if (!_configuration.Storage.IgnoreExceptionOnSaveMessage)
                    {
                        throw;
                    }
                }
            }

            _router.Route(context, parameter.Route);

            next();
        }
Exemple #5
0
        public void Execute(MessageContext messagecontext, Action <MessageContext, MiddlewareContext> next, MiddlewareContext middlewarecontext)
        {
            messagecontext.AddTrack(messagecontext.Identity, messagecontext.Origin, messagecontext.Route);

            if (_configuration.Storage.SaveMessage)
            {
                var storage = _factory.Create <ISagaStorage>(_configuration.SagaStorageType);

                var messageentity = new MessageEntity()
                {
                    Content     = messagecontext.Content,
                    ContentType = messagecontext.Route.ContentType.FullName,
                    Identity    = messagecontext.Identity,
                    Version     = messagecontext.Version,
                    RetryCount  = messagecontext.RetryCount,
                    LastRetry   = messagecontext.LastRetry,
                    Origin      = messagecontext.Origin,
                    Headers     = messagecontext.Headers,
                    DateTimeUtc = messagecontext.DateTimeUtc,
                    Name        = messagecontext.Route.Name,
                    Tracks      = messagecontext.Tracks,
                    ContentId   = messagecontext.ContentId,
                    Data        = string.Empty
                };

                try
                {
                    storage.CreateMessage(messagecontext, messageentity);
                }
                catch (Exception)
                {
                    if (!_configuration.Storage.IgnoreExceptionOnSaveMessage)
                    {
                        throw;
                    }
                }
            }

            _router.Route(messagecontext);
        }
Exemple #6
0
        public void Execute(MessageContext messagecontext, Action <MessageContext, MiddlewareContext> next, MiddlewareContext middlewarecontext)
        {
            var storage = _factory.Create <ISagaStorage>(Configuration.SagaStorageType);

            var serializer = _factory.Create <IMessageSerializer>(Configuration.MessageSerializerType);

            var sagaentity = storage.GetSaga(messagecontext.SagaContext.Id);

            messagecontext.SagaContext.Status = DefaultStatus;

            if (sagaentity != null)
            {
                messagecontext.AddTrack(messagecontext.Identity, messagecontext.Origin, messagecontext.Route, messagecontext.Saga, messagecontext.SagaContext);

                var data = serializer.Deserialize(sagaentity.Data, messagecontext.Saga.DataType);

                if (data != null)
                {
                    _router.Route(messagecontext, data);

                    sagaentity.Ended = messagecontext.DateTimeUtc;

                    sagaentity.Duration = (sagaentity.Ended.Value - sagaentity.Created).TotalMilliseconds;

                    SaveSaga(messagecontext, storage, sagaentity, serializer, data);

                    SaveMessage(messagecontext, storage, sagaentity);
                }
                else
                {
                    throw new ApplicationException($"Empty/Invalid data {messagecontext.Saga.DataType.FullName} for {messagecontext.Route.ContentType.FullName}, saga {messagecontext.Saga.Name} route {messagecontext.Route.Name}");
                }
            }
            else
            {
                throw new ApplicationException($"No data {messagecontext.Saga.DataType.FullName} for {messagecontext.Route.ContentType.FullName}, saga {messagecontext.Saga.Name} route {messagecontext.Route.Name}");
            }
        }