Example #1
0
    /// <summary>
    /// Add event to event store. Note, at this point it won't be actually saved.
    /// </summary>
    /// <param name="event"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task AddEventAsync(IntegrationEvent @event, CancellationToken cancellationToken)
    {
        var eventLogEntry = new IntegrationEventLogEntry(@event, ScopeId);

        _dbContext.IntegrationEventLogs.Add(eventLogEntry);
        return(Task.CompletedTask);
    }
 public static string BuildIntegrationEventLogEntryInsertStatement(this IntegrationEventLogEntry eventLogEntry)
 {
     return
         ("INSERT INTO IntegrationEventLogEntry " +
          "(Id, EventTypeName, EventStateId, TimesSent, CreationTime, Content, TransactionId) " +
          "VALUES (@Id, @EventTypeName, @EventStateId, @TimesSent, @CreationTime, @Content, @TransactionId);");
 }
Example #3
0
        public Task SaveEventAsync(IntegrationEvent @event, Guid transactionId)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event, transactionId);

            return(_database.GetCollection <IntegrationEventLogEntry>("IntegrationEventLogs")
                   .InsertOneAsync(eventLogEntry));
        }
        public Task SaveEventAsync(IntegrationEvent @event)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event);

            //something about transaction
            _eventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            return(_eventLogContext.SaveChangesAsync());
        }
        public async Task SaveEventAsync(IntegrationEvent @event, Guid transactionId)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event, transactionId);

            await dbContext.Set <IntegrationEventLogEntry>().AddAsync(eventLogEntry);

            await dbContext.SaveChangesAsync();
        }
        public Task SaveEventAsync <T>(T @event) where T : IntegrationEvent
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event);

            IntegrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(IntegrationEventLogContext.SaveChangesAsync());
        }
Example #7
0
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _dbContext.Database.UseTransaction(transaction.GetDbTransaction());
            _dbContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_dbContext.SaveChangesAsync());
        }
        public Task SaveEventAsync(IntegrationEvent @event /*, IDbContextTransaction transaction*/)
        {
            //if (transaction == null) throw new ArgumentNullException(nameof(transaction));

            var eventLogEntry = new IntegrationEventLogEntry(@event, /*transaction.TransactionId*/ new Guid());

            //_integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            return(_integrationEventLogContext.SaveChangesAsync());
        }
        public void AddAndSaveEventAsync(IntegrationEvent evt)
        {
            _logger.LogInformation(
                "----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id,
                evt);

            var logEntry = new IntegrationEventLogEntry(evt);

            _uow.IntegrationEventRepository.Insert(logEntry);
        }
Example #10
0
        public async Task AddIntegrationEventToLog(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            var integrationEventLogEntry = new IntegrationEventLogEntry(@event, Guid.NewGuid());

            _context.IntegrationEventLogs.Add(integrationEventLogEntry);

            _logger.LogInformation(" [x] OrderingIntegrationService.AddIntegrationEventToLog(): Added integration event to integrationEventLog: {0}",
                                   JsonConvert.SerializeObject(@event));

            await _context.SaveChangesAsync();
        }
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _outboxEventContext.Database.UseTransaction(transaction.GetDbTransaction());
            _outboxEventContext.Outbox.Add(eventLogEntry);

            return(_outboxEventContext.SaveChangesAsync());
        }
Example #12
0
        public Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction), $"A {typeof(DbTransaction).FullName} is required as a pre-requisite to save the event");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _integrationEventLogContext.Database.UseTransaction(transaction);
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
Example #13
0
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction()); //using same transaction to save eventlog
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
        public int SaveEvent(IEvent @event, DbTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction", $"A {typeof(DbTransaction).FullName} is required as a pre-requisite to save the event.");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _integrationEventLogContext.Database.UseTransaction(transaction);
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            //throw new Exception("test exception");
            return(_integrationEventLogContext.SaveChanges());
        }
        public Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction)
        {
            if (transaction == null)
            {
                Console.WriteLine("null transaction");
            }
            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _integrationEventLogContext.Database.UseTransaction(transaction);

            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
Example #16
0
        public Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction", $"A {typeof(DbTransaction).FullName} is required as a pre-requisite to save the event.");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _integrationEventLogContext.Database.UseTransaction(transaction);
            _integrationEventLogContext.IntegrationEventLogs.AddAsync(eventLogEntry, cancellationToken);

            return(_integrationEventLogContext.SaveChangesAsync(cancellationToken));
        }
Example #17
0
        public async Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            await _context.Database.UseTransactionAsync(transaction.GetDbTransaction());

            await _context.IntegrationEventLogs.AddAsync(eventLogEntry);

            await _context.SaveChangesAsync();
        }
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction), $"{typeof(DbTransaction).FullName} is required as a pre-requisite to save the event.");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _context.Database.UseTransaction(transaction.GetDbTransaction());
            _context.IntegrationEventLogs.Add(eventLogEntry);

            throw new Exception("Testing atomicity");

            return(_context.SaveChangesAsync());
        }
        public void TestGuidAndEnum()
        {
            using (_context)
            {
                //get
                var entry = _context.Get <IntegrationEventLogEntry>(x => x.State == EventStateEnum.Published);

                entry = new IntegrationEventLogEntry
                {
                    EventId = Guid.NewGuid(),
                    State   = (EventStateEnum)Enum.Parse(typeof(EventStateEnum), "2"),
                };
                //add
                Guid _id = _context.Add(entry);
            }
        }
Example #20
0
        /// <summary>
        /// Save event to log along with the transaction during which the event was created.
        /// </summary>
        /// <param name="@event">The integration event to save.</param>
        /// <param name="transaction">The transaction during which the event was created.</param>
        public Task SaveEventAsync(IIntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            // Set the datebase transaction to the provided instance, this ensure integration events
            // are logged in the same transaction as the domain data change that spawned the event.
            _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
        private StoredEvent SaveIntegrationEventLogContext(IDomainEvent domainEvent)
        {
            var eventLogEntry = new IntegrationEventLogEntry(Guid.NewGuid().ToString(),
                                                             domainEvent.GetType().FullName,
                                                             domainEvent.TimeStamp.DateTime,
                                                             JsonConvert.SerializeObject(domainEvent)
                                                             );

            eventLogEntry.TimesSent++;
            eventLogEntry.State = EventStateEnum.Published;

            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            int result = _integrationEventLogContext.SaveChanges();

            return(new StoredEvent(domainEvent.GetType().FullName, domainEvent.TimeStamp.DateTime, JsonConvert.SerializeObject(domainEvent)));
        }
Example #22
0
        public Task SaveEventsAsync(IntegrationEvent[] events, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());

            foreach (var @event in events)
            {
                var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

                _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            }

            return(_integrationEventLogContext.SaveChangesAsync());
        }
Example #23
0
        protected async Task <bool> Publish(IntegrationEventLogEntry entry)
        {
            int  count            = 0;
            bool publishSucceeded = false;

            var eventTypeName = GetRelativeEventTypeName(entry.EventTypeName);

            var topicModel = _topicMapping.GetPublishedTopic(eventTypeName);

            if (topicModel == null)
            {
                return(false);
            }

            entry.UpdateState(EventStateEnum.InProgress);
            await _context.SaveChangesAsync();

            while (!publishSucceeded && count <= RetryTimes)
            {
                try
                {
                    publishSucceeded = _queueProcessor.PublishPlainMessageToExchange(topicModel.Exchange, topicModel.RoutingKey, entry.Content);
                }
                catch (Exception ex)
                {
                    publishSucceeded = false;
                }
            }

            if (publishSucceeded)
            {
                entry.UpdateState(EventStateEnum.Published);
                await _context.SaveChangesAsync();
            }
            else
            {
                entry.UpdateState(EventStateEnum.PublishedFailed);
                await _context.SaveChangesAsync();
            }

            return(publishSucceeded);
        }
        public Task SaveEventAsync(IntegrationEvent integrationEvent, IDbContextTransaction transaction)
        {
            try
            {
                if (transaction == null)
                {
                    throw new ArgumentNullException(nameof(transaction));
                }

                var eventLogEntry = new IntegrationEventLogEntry(integrationEvent, transaction.TransactionId);

                _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
                _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

                return(_integrationEventLogContext.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void SaveEvent(IntegrationEvent @event)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _eventLog.Add(eventLogEntry);
        }
Example #26
0
 public void Insert(IntegrationEventLogEntry logEntry)
 {
     _integrationEvents.Add(logEntry);
 }