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; } }
/// <summary> /// Clears all captured events /// </summary> public void Clear() { lock (LoggerEvents) { ClearLastEvent(); LoggerEvents.Clear(); } }
public void Clear() { lock (LoggerEvents) { lastEvent = null; LoggerEvents.Clear(); } }
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); }
private static EventId GetEventId(LoggerEvents @event) => new EventId((int)@event, @event.ToString());