Exemple #1
0
        public async Task Consume(ConsumeContext <CancelBilling> context)
        {
            var id      = context.CorrelationId.GetValueOrDefault();
            var reason  = context.Message.Reason;
            var billing = await dbContext.Billings.FindAsync(id);

            if (billing is null)
            {
                return;
            }

            logger.LogInformation($"'{id}' exists in this context. Deleting because of {nameof(CancelBilling)} message with Reason = '{reason}'.");

            dbContext.Billings.Remove(billing);

            await dbContext.SaveChangesAsync();
        }
        public async Task Consume(ConsumeContext <PrepareBilling> context)
        {
            var id       = context.CorrelationId.GetValueOrDefault();
            var address  = context.Message.Address;
            var quantity = context.Message.Quantity;
            var amount   = context.Message.Amount;

            logger.LogInformation($"Received {nameof(PrepareBilling)} message with {{ Id = '{id}', Address = '{address}', Quantity = {quantity}, Amount = {amount} }}.");

            dbContext.Add(new Billing {
                Id = id, Address = address, Quantity = quantity, Amount = amount
            });

            await dbContext.SaveChangesAsync();

            logger.LogInformation($"Delivery '{id}' created. Waiting for Payment and Stock services.");

            await context.Publish <BillingPrepared>(new { context.CorrelationId });
        }
        public async Task Consume(ConsumeContext <CompleteBilling> context)
        {
            var id      = context.CorrelationId.GetValueOrDefault();
            var billing = await dbContext.Billings.FindAsync(id);

            logger.LogInformation($"Received payment with Id '{id}'. Processing...");

            if (billing is null)
            {
                logger.LogInformation($"'{id}' does not exists in this context. Rejecting, will retry in a few.");

                throw new BillingNotFoundException();
            }

            logger.LogInformation($"'{id}' exists in this context.");

            billing.Paid = true;

            await dbContext.SaveChangesAsync();

            logger.LogInformation($"Processed.");

            await context.Publish <BillingCompleted>(new { context.CorrelationId });
        }