public async Task Consume(ConsumeContext <StartDelivery> context) { var id = context.CorrelationId.GetValueOrDefault(); logger.LogInformation($"Received {nameof(StartDelivery)} message with Id = '{id}'"); var delivery = await dbContext.Deliveries.FindAsync(id); if (delivery is null) { logger.LogInformation($"'{id}' does not exists in this context. Rejecting, will retry in a few."); throw new DeliveryNotFoundException(); } logger.LogInformation($"'{id}' exists in this context."); delivery.IsShipped = true; await dbContext.SaveChangesAsync(); logger.LogInformation($"'{id}' updated."); await context.Publish <DeliveryStarted>(new { context.CorrelationId }); }
public async Task Consume(ConsumeContext <CancelDelivery> context) { var id = context.CorrelationId.GetValueOrDefault(); var delivery = await dbContext.Deliveries.FindAsync(id); if (delivery is null) { return; } logger.LogInformation($"'{id}' exists in this context. Deleting because of {nameof(CancelDelivery)} message."); dbContext.Deliveries.Remove(delivery); await dbContext.SaveChangesAsync(); }
public async Task Consume(ConsumeContext <PrepareDelivery> context) { var id = context.CorrelationId.GetValueOrDefault(); var address = context.Message.Address; logger.LogInformation($"Received {nameof(PrepareDelivery)} message with Id = '{id}' and Address = '{address}'."); dbContext.Add(new Delivery { Id = id, Address = address }); await dbContext.SaveChangesAsync(); logger.LogInformation($"Delivery '{id}' created. Waiting for Payment, Stock and Billing services."); await context.Publish <DeliveryPrepared>(new { context.CorrelationId }); }