public async Task Consume(ConsumeContext <PaymentCancelled> context)
        {
            var id      = context.CorrelationId.GetValueOrDefault();
            var billing = await dbContext.Billings.FindAsync(id);

            if (billing is null)
            {
                return;
            }

            logger.LogInformation($"'{id}' exists in this context. Deleting because of {nameof(PaymentCancelled)} message.");

            dbContext.Billings.Remove(billing);

            await dbContext.SaveChangesAsync();

            await context.Publish <BillingCancelled>(new { context.CorrelationId });
        }
        public async Task Consume(ConsumeContext <OrderRegistered> context)
        {
            var id       = context.CorrelationId.GetValueOrDefault();
            var address  = context.Message.Address;
            var quantity = context.Message.Quantity;
            var amount   = quantity * 2.5f;

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

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

            await dbContext.SaveChangesAsync();

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

            await context.Publish <BillingPrepared>(new { context.CorrelationId });
        }
        public async Task Consume(ConsumeContext <PaymentCreated> context)
        {
            var id       = context.CorrelationId.GetValueOrDefault();
            var quantity = context.Message.Quantity;
            var amount   = context.Message.Amount;

            logger.LogInformation($"Received payment with {{ Id '{id}', Quantity = {quantity}, Amount = {amount}€ }}. Processing...");

            await Task.Delay(TimeSpan.FromSeconds(5));

            var billing = new Billing {
                Id = id
            };

            dbContext.Add(billing);

            await dbContext.SaveChangesAsync();

            logger.LogInformation($"Processed.");

            await context.Publish <BillingCompleted>(new { context.CorrelationId });
        }
        public async Task Consume(ConsumeContext <PaymentAccepted> 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 });
        }