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
This commit is contained in:
parent
c8df9a232a
commit
33335eb230
@ -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…
x
Reference in New Issue
Block a user