Browse Source

Change in integration event publication fow as agreed. Flow is 1- start transaction 2- modify catalog iin db 3- add event to db 4- close transaction 5- publish event 6- update event state in db

pull/126/head
dsanz 8 years ago
parent
commit
33335eb230
1 changed files with 11 additions and 15 deletions
  1. +11
    -15
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs

+ 11
- 15
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -144,12 +144,20 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
{
var oldPrice = item.Price;
item.Price = value.Price;
_context.CatalogItems.Update(item);
await _context.SaveChangesAsync();
var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice);
await ProcessEventAsync(@event);
var eventLogEntry = new IntegrationEventLogEntry(@event);
_context.IntegrationEventLog.Add(eventLogEntry);
await _context.SaveChangesAsync();
_eventBus.Publish(@event);
eventLogEntry.TimesSent++;
eventLogEntry.State = EventStateEnum.Published;
_context.IntegrationEventLog.Update(eventLogEntry);
await _context.SaveChangesAsync();
}
return Ok();
@ -164,17 +172,5 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
return items;
}
private async Task ProcessEventAsync(IntegrationEvent @event)
{
_eventBus.Publish(@event);
var eventLogEntry = new IntegrationEventLogEntry(@event);
eventLogEntry.TimesSent++;
eventLogEntry.State = EventStateEnum.Published;
_context.IntegrationEventLog.Add(eventLogEntry);
await _context.SaveChangesAsync();
}
}
}

Loading…
Cancel
Save