コード例 #1
0
        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 });
        }
コード例 #2
0
        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 });
        }