Beispiel #1
0
        public async Task <ProductPurchase> PurchaseProduct(ProductPurchase productPurchase,
                                                            [Service] IMediator mediator,
                                                            [Service] ILogger <ProductPurchaseMutation> logger)
        {
            try
            {
                var purchaseCommand = new ProductPurchaseCommand()
                {
                    ProductPurchase = productPurchase
                };

                return(await mediator.Send(purchaseCommand));

                //messageBus.DeclareExchange("MyShop", "topic");
                //if (messageBus.PublishMessage(new { userId, shopId, productType }, "PurchaseProduct", "MyShop"))
                //{
                //    return true;
                //}
            }
            catch (Exception ex)
            {
                logger.LogError(LoggerEvents.GenerateEventId(LoggerEventType.UnknownPurchaseProductMutationException),
                                ex,
                                $"{nameof(ProductPurchaseMutation)} PurchaseProduct encountered exception with ShopId: {productPurchase.ShopId},ProductType: {productPurchase.ProductType},UserId: {productPurchase.UserId}");

                throw;
            }
        }
Beispiel #2
0
 protected override void HandleMessage(ProductPurchase message)
 {
     if (_productPurchaseHandler == null)
     {
         _logger.LogWarning(
             LoggerEvents.GenerateEventId(LoggerEventType.MissingMessageBusDomainHandler),
             $"{nameof(MessageBusProductPurchaseHandler)}: IProductPurchaseHandler is not registered");
         return;
     }
     _productPurchaseHandler.HandleProductPurchase(message);
 }