public void Sweep() { //find all the unsent messages var outstandingMessages = _outbox.OutstandingMessages(5000); //send them _commandProcessor.ClearOutbox(outstandingMessages.Select(message => message.Id).ToArray()); }
public override async Task <AddNewAccountCommand> HandleAsync(AddNewAccountCommand command, CancellationToken cancellationToken = new CancellationToken()) { Guid eventId; using (var uow = new AccountContext(_options)) { using (var trans = uow.Database.BeginTransaction()) { var accountRepository = new AccountRepositoryAsync(new EFUnitOfWork(uow)); var account = new Account(); account.AccountId = command.Id; account.Name = new Name(account, command.Name.FirstName, command.Name.LastName); account.ContactDetails = new ContactDetails(account, command.ContactDetails.Email, command.ContactDetails.TelephoneNumber); account.CardDetails = new CardDetails(account, command.CardDetails.CardNumber, command.CardDetails.CardSecurityCode); account.Addresses = command.Addresses; await accountRepository.AddAsync(account); eventId = _commandProcessor.DepositPost(new AccountEvent { Id = Guid.NewGuid(), AccountId = account.AccountId.ToString(), Addresses = account.Addresses.Select( addr => new AddressEvent { AddressType = addr.AddressType.ToString(), FistLineOfAddress = addr.FistLineOfAddress, State = addr.State, ZipCode = addr.ZipCode }).ToList(), Name = new NameEvent { FirstName = account.Name.FirstName, LastName = account.Name.LastName }, CardDetails = new CardDetailsEvent { CardNumber = account.CardDetails.CardNumber, CardSecurityCode = account.CardDetails.CardSecurityCode }, ContactDetails = new ContactDetailsEvent { Email = account.ContactDetails.Email, TelephoneNumber = account.ContactDetails.TelephoneNumber }, Version = account.Version }); trans.Commit(); } } _commandProcessor.ClearOutbox(eventId); return(await base.HandleAsync(command, cancellationToken)); }
public void Sweep() { //find all the unsent messages var outstandingMessages = _outbox.OutstandingMessages(_milliSecondsSinceSent); //send them if we have them if (outstandingMessages.Any()) { _commandProcessor.ClearOutbox(outstandingMessages.Select(message => message.Id).ToArray()); } }
public override async Task <BookGuestRoomOnAccount> HandleAsync(BookGuestRoomOnAccount command, CancellationToken cancellationToken = new CancellationToken()) { Guid messageId; using (var uow = new BookingContext(_options)) { using (var trans = uow.Database.BeginTransaction()) { var repository = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); var roomBooking = new RoomBooking( command.BookingId, command.DateOfFirstNight, command.NumberOfNights, command.NumberOfGuests, command.Type, command.Price, command.AccountId); await repository.AddAsync(roomBooking, cancellationToken); messageId = _messagePublisher.DepositPost(new GuestRoomBookingMade { BookingId = roomBooking.RoomBookingId.ToString(), DateOfFirstNight = roomBooking.DateOfFirstNight, NumberOfGuests = roomBooking.NumberOfGuests, NumberOfNights = roomBooking.NumberOfNights, Type = roomBooking.RoomType, Price = roomBooking.Price, AccountId = roomBooking.AccountId, }); trans.Commit(); } } _messagePublisher.ClearOutbox(messageId); return(await base.HandleAsync(command, cancellationToken)); }
/// <summary> /// Dispatches the oldest un-dispatched messages from the outbox in a background thread. /// </summary> public void Sweep() { _commandProcessor.ClearOutbox(_batchSize, _millisecondsSinceSent); }