From 04560ff4ebe1b16f542d2648fe13b9c3c63354f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Tom=C3=A1s?= Date: Thu, 19 Apr 2018 00:58:09 +0200 Subject: [PATCH] Created specific service for signalr hub --- docker-compose.override.yml | 22 +- docker-compose.yml | 8 +- eShopOnContainers-ServicesAndWebApps.sln | 51 +++++ .../Web.Bff.Shopping/apigw/configuration.json | 12 ++ .../Identity.API/Configuration/Config.cs | 9 +- .../OrderCancelledDomainEventHandler.cs | 16 +- ...dToAwaitingValidationDomainEventHandler.cs | 27 +-- ...erStatusChangedToPaidDomainEventHandler.cs | 31 ++- .../OrderShippedDomainEventHandler.cs | 21 +- ...egateWhenOrderStartedDomainEventHandler.cs | 13 +- ...angedToStockConfirmedDomainEventHandler.cs | 21 +- ...gedToAwaitingValidationIntegrationEvent.cs | 6 +- ...tatusChangedToCancelledIntegrationEvent.cs | 22 ++ ...rderStatusChangedToPaidIntegrationEvent.cs | 8 +- ...rStatusChangedToShippedIntegrationEvent.cs | 22 ++ ...ChangedToStockConfirmedIntegrationEvent.cs | 10 +- ...tatusChangedTosubmittedIntegrationEvent.cs | 22 ++ .../Ordering/Ordering.API/Ordering.API.csproj | 1 - src/Services/Ordering/Ordering.API/Startup.cs | 12 -- .../AutofacModules/ApplicationModule.cs | 30 +++ .../Ordering/Ordering.SignalrHub/Dockerfile | 20 ++ ...angedToCancelledIntegrationEventHandler.cs | 28 +++ ...tusChangedToPaidIntegrationEventHandler.cs | 26 +++ ...ChangedToShippedIntegrationEventHandler.cs | 28 +++ ...ToStockConfirmedIntegrationEventHandler.cs | 29 +++ ...angedToSubmittedIntegrationEventHandler.cs | 29 +++ ...aitingValidationIntegrationEventHandler.cs | 27 +++ ...gedToAwaitingValidationIntegrationEvent.cs | 19 ++ ...tatusChangedToCancelledIntegrationEvent.cs | 22 ++ ...rderStatusChangedToPaidIntegrationEvent.cs | 23 ++ ...rStatusChangedToShippedIntegrationEvent.cs | 22 ++ ...ChangedToStockConfirmedIntegrationEvent.cs | 18 ++ ...tatusChangedToSubmittedIntegrationEvent.cs | 22 ++ .../NotificationHub.cs} | 4 +- .../Ordering.SignalrHub.csproj | 25 +++ .../Ordering/Ordering.SignalrHub/Program.cs | 25 +++ .../Properties/launchSettings.json | 27 +++ .../Ordering/Ordering.SignalrHub/Startup.cs | 204 ++++++++++++++++++ .../Ordering.SignalrHub/appsettings.json | 15 ++ src/Web/WebMVC/AppSettings.cs | 2 +- src/Web/WebMVC/Startup.cs | 1 + src/Web/WebMVC/Views/Shared/_Layout.cshtml | 2 +- src/Web/WebSPA/AppSettings.cs | 1 + .../shared/models/configuration.model.ts | 1 + .../shared/services/configuration.service.ts | 1 + .../shared/services/security.service.ts | 2 +- .../shared/services/signalr.service.ts | 8 +- 47 files changed, 889 insertions(+), 106 deletions(-) create mode 100644 src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedTosubmittedIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/Dockerfile create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/orderStatusChangedToAwaitingValidationIntegrationEventHandler.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs rename src/Services/Ordering/{Ordering.API/Infrastructure/Hubs/NotificationsHub.cs => Ordering.SignalrHub/NotificationHub.cs} (88%) create mode 100644 src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj create mode 100644 src/Services/Ordering/Ordering.SignalrHub/Program.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/Properties/launchSettings.json create mode 100644 src/Services/Ordering/Ordering.SignalrHub/Startup.cs create mode 100644 src/Services/Ordering/Ordering.SignalrHub/appsettings.json diff --git a/docker-compose.override.yml b/docker-compose.override.yml index b3a36ab16..49e689a74 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -119,7 +119,7 @@ services: - ASPNETCORE_URLS=http://0.0.0.0:80 - IdentityUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - PurchaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202 - - MarketingUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5203 + - MarketingUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5203 - CatalogUrlHC=http://catalog.api/hc - OrderingUrlHC=http://ordering.api/hc - IdentityUrlHC=http://identity.api/hc #Local: Use ${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}, if using external IP or DNS name from browser. @@ -129,6 +129,7 @@ services: - UseCustomizationData=True - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} - OrchestratorType=${ORCHESTRATOR_TYPE} + - SignalrHubUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202 ports: - "5104:80" @@ -145,7 +146,7 @@ services: - BasketUrlHC=http://basket.api/hc - MarketingUrlHC=http://marketing.api/hc - PaymentUrlHC=http://payment.api/hc - - ExternalPurchaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202 + - SignalrHubUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202 - UseCustomizationData=True - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} - OrchestratorType=${ORCHESTRATOR_TYPE} @@ -298,4 +299,19 @@ services: - urls__identity=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5110. ports: - "5121:80" # Important: In a production environment your should remove the external port (5121) kept here for microservice debugging purposes. - # The API Gateway redirects and access through the internal port (80). \ No newline at end of file + # The API Gateway redirects and access through the internal port (80). + ordering.signalrhub: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80 + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} + - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} + - AzureServiceBusEnabled=False + - ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY} + - OrchestratorType=${ORCHESTRATOR_TYPE} + - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5110. + - IdentityUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 + ports: + - "5112:80" + diff --git a/docker-compose.yml b/docker-compose.yml index 95ab93ca4..5ec0eb5aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -151,4 +151,10 @@ services: dockerfile: src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile depends_on: - sql.data - - rabbitmq \ No newline at end of file + - rabbitmq + ordering.signalrhub: + image: eshop/orderingsignalrhub:${TAG:-latest} + build: + context: . + dockerfile: src/Services/Ordering/Ordering.SignalrHub/Dockerfile + diff --git a/eShopOnContainers-ServicesAndWebApps.sln b/eShopOnContainers-ServicesAndWebApps.sln index 3116a7d49..f127af6d9 100644 --- a/eShopOnContainers-ServicesAndWebApps.sln +++ b/eShopOnContainers-ServicesAndWebApps.sln @@ -130,6 +130,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.Shopping.HttpAggregator EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ordering.BackgroundTasks", "src\Services\Ordering\Ordering.BackgroundTasks\Ordering.BackgroundTasks.csproj", "{7D63ED4A-3EDA-4BBA-8BBA-F46BD6430931}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.SignalrHub", "src\Services\Ordering\Ordering.SignalrHub\Ordering.SignalrHub.csproj", "{E1D2B260-4E7F-4A88-BC13-9910F7C44623}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -1536,6 +1538,54 @@ Global {7D63ED4A-3EDA-4BBA-8BBA-F46BD6430931}.Release|x64.Build.0 = Release|Any CPU {7D63ED4A-3EDA-4BBA-8BBA-F46BD6430931}.Release|x86.ActiveCfg = Release|Any CPU {7D63ED4A-3EDA-4BBA-8BBA-F46BD6430931}.Release|x86.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|ARM.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|iPhone.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|x64.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|x64.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|x86.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.AppStore|x86.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|ARM.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|ARM.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|iPhone.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|x64.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|x64.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|x86.ActiveCfg = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Debug|x86.Build.0 = Debug|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|Any CPU.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|ARM.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|ARM.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|iPhone.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|iPhone.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|x64.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|x64.Build.0 = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|x86.ActiveCfg = Release|Any CPU + {E1D2B260-4E7F-4A88-BC13-9910F7C44623}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1592,6 +1642,7 @@ Global {BEA37D6D-4CF2-4AE8-9575-72388E54FBD0} = {0189E4FB-6E2B-4F2E-9B1D-5473D23FC6DB} {AF0828DB-8BDD-411A-AEEF-B780FBB8D8C1} = {28C0F5C8-4849-4035-80AB-45639424E73F} {7D63ED4A-3EDA-4BBA-8BBA-F46BD6430931} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} + {E1D2B260-4E7F-4A88-BC13-9910F7C44623} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9} diff --git a/src/ApiGateways/Web.Bff.Shopping/apigw/configuration.json b/src/ApiGateways/Web.Bff.Shopping/apigw/configuration.json index 63aeb7752..b10e78982 100644 --- a/src/ApiGateways/Web.Bff.Shopping/apigw/configuration.json +++ b/src/ApiGateways/Web.Bff.Shopping/apigw/configuration.json @@ -72,6 +72,18 @@ "UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamHttpMethod": [] }, + { + "DownstreamPathTemplate": "/{everything}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "ordering.signalrhub", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/hub/{everything}", + "UpstreamHttpMethod": [] + }, { "DownstreamPathTemplate": "/{everything}", "DownstreamScheme": "http", diff --git a/src/Services/Identity/Identity.API/Configuration/Config.cs b/src/Services/Identity/Identity.API/Configuration/Config.cs index 3bc705995..2f6e2d21e 100644 --- a/src/Services/Identity/Identity.API/Configuration/Config.cs +++ b/src/Services/Identity/Identity.API/Configuration/Config.cs @@ -16,7 +16,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration new ApiResource("marketing", "Marketing Service"), new ApiResource("locations", "Locations Service"), new ApiResource("mobileshoppingagg", "Mobile Shopping Aggregator"), - new ApiResource("webshoppingagg", "Web Shopping Aggregator") + new ApiResource("webshoppingagg", "Web Shopping Aggregator"), + new ApiResource("orders.signalrhub", "Ordering Signalr Hub") }; } @@ -55,7 +56,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration "basket", "locations", "marketing", - "webshoppingagg" + "webshoppingagg", + "orders.signalrhub" } }, new Client @@ -119,7 +121,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration "basket", "locations", "marketing", - "webshoppingagg" + "webshoppingagg", + "orders.signalrhub" }, }, new Client diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderCancelled/OrderCancelledDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderCancelled/OrderCancelledDomainEventHandler.cs index 4e88dbd5e..24a8245d6 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderCancelled/OrderCancelledDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderCancelled/OrderCancelledDomainEventHandler.cs @@ -1,13 +1,11 @@ using MediatR; -using Microsoft.AspNetCore.SignalR; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; -using Ordering.API.Infrastructure.Hubs; +using Ordering.API.Application.IntegrationEvents; +using Ordering.API.Application.IntegrationEvents.Events; using Ordering.Domain.Events; using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -19,18 +17,17 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderCancelled private readonly IOrderRepository _orderRepository; private readonly IBuyerRepository _buyerRepository; private readonly ILoggerFactory _logger; - private readonly IHubContext _hubContext; + private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; public OrderCancelledDomainEventHandler( IOrderRepository orderRepository, ILoggerFactory logger, IBuyerRepository buyerRepository, - IHubContext hubContext) + IOrderingIntegrationEventService orderingIntegrationEventService) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); - _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); } public async Task Handle(OrderCancelledDomainEvent orderCancelledDomainEvent, CancellationToken cancellationToken) @@ -42,9 +39,8 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderCancelled var order = await _orderRepository.GetAsync(orderCancelledDomainEvent.Order.Id); var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); - await _hubContext.Clients - .Group(buyer.Name) - .SendAsync("UpdatedOrderState", new { OrderId = order.Id, Status = order.OrderStatus.Name }); + var orderStatusChangedToCancelledIntegrationEvent = new OrderStatusChangedToCancelledIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToCancelledIntegrationEvent); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs index 7967d1fe4..60efead1b 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs @@ -1,20 +1,16 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderGracePeriodConfirmed { + using Domain.Events; using MediatR; + using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; - using Domain.Events; - using System; - using System.Threading.Tasks; using Ordering.API.Application.IntegrationEvents; - using System.Linq; using Ordering.API.Application.IntegrationEvents.Events; + using System; + using System.Linq; using System.Threading; - using Microsoft.AspNetCore.SignalR; - using Ordering.API.Infrastructure.Hubs; - using Microsoft.AspNetCore.Http; - using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; - using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; + using System.Threading.Tasks; public class OrderStatusChangedToAwaitingValidationDomainEventHandler : INotificationHandler @@ -23,19 +19,16 @@ private readonly ILoggerFactory _logger; private readonly IBuyerRepository _buyerRepository; private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; - private readonly IHubContext _hubContext; public OrderStatusChangedToAwaitingValidationDomainEventHandler( IOrderRepository orderRepository, ILoggerFactory logger, IBuyerRepository buyerRepository, - IOrderingIntegrationEventService orderingIntegrationEventService, - IHubContext hubContext) + IOrderingIntegrationEventService orderingIntegrationEventService) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _buyerRepository = buyerRepository; - _orderingIntegrationEventService = orderingIntegrationEventService; - _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + _orderingIntegrationEventService = orderingIntegrationEventService; } public async Task Handle(OrderStatusChangedToAwaitingValidationDomainEvent orderStatusChangedToAwaitingValidationDomainEvent, CancellationToken cancellationToken) @@ -52,12 +45,8 @@ .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); var orderStatusChangedToAwaitingValidationIntegrationEvent = new OrderStatusChangedToAwaitingValidationIntegrationEvent( - orderStatusChangedToAwaitingValidationDomainEvent.OrderId, orderStockList); + order.Id, order.OrderStatus.Name, buyer.Name, orderStockList); await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToAwaitingValidationIntegrationEvent); - - await _hubContext.Clients - .Group(buyer.Name) - .SendAsync("UpdatedOrderState", new { OrderId = order.Id, Status = order.OrderStatus.Name }); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index fa1bf41da..59c1e4708 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -1,18 +1,16 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderPaid { + using Domain.Events; using MediatR; + using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; - using Domain.Events; - using System; - using System.Threading.Tasks; using Ordering.API.Application.IntegrationEvents; - using System.Linq; using Ordering.API.Application.IntegrationEvents.Events; + using System; + using System.Linq; using System.Threading; - using Microsoft.AspNetCore.SignalR; - using Ordering.API.Infrastructure.Hubs; - using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; + using System.Threading.Tasks; public class OrderStatusChangedToPaidDomainEventHandler : INotificationHandler @@ -21,19 +19,18 @@ private readonly ILoggerFactory _logger; private readonly IBuyerRepository _buyerRepository; private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; - private readonly IHubContext _hubContext; + public OrderStatusChangedToPaidDomainEventHandler( IOrderRepository orderRepository, ILoggerFactory logger, IBuyerRepository buyerRepository, - IOrderingIntegrationEventService orderingIntegrationEventService, - IHubContext hubContext) + IOrderingIntegrationEventService orderingIntegrationEventService + ) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); - _orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService)); - _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + _orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService)); } public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedToPaidDomainEvent, CancellationToken cancellationToken) @@ -48,13 +45,13 @@ var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); - var orderStatusChangedToPaidIntegrationEvent = new OrderStatusChangedToPaidIntegrationEvent(orderStatusChangedToPaidDomainEvent.OrderId, + var orderStatusChangedToPaidIntegrationEvent = new OrderStatusChangedToPaidIntegrationEvent( + orderStatusChangedToPaidDomainEvent.OrderId, + order.OrderStatus.Name, + buyer.Name, orderStockList); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToPaidIntegrationEvent); - await _hubContext.Clients - .Group(buyer.Name) - .SendAsync("UpdatedOrderState", new { OrderId = order.Id, Status = order.OrderStatus.Name }); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToPaidIntegrationEvent); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderShipped/OrderShippedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderShipped/OrderShippedDomainEventHandler.cs index 52fb9dc22..0bf4cabcd 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderShipped/OrderShippedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderShipped/OrderShippedDomainEventHandler.cs @@ -1,13 +1,11 @@ using MediatR; -using Microsoft.AspNetCore.SignalR; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; -using Ordering.API.Infrastructure.Hubs; +using Ordering.API.Application.IntegrationEvents; +using Ordering.API.Application.IntegrationEvents.Events; using Ordering.Domain.Events; using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -18,19 +16,19 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderShipped { private readonly IOrderRepository _orderRepository; private readonly IBuyerRepository _buyerRepository; + private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; private readonly ILoggerFactory _logger; - private readonly IHubContext _hubContext; public OrderShippedDomainEventHandler( IOrderRepository orderRepository, ILoggerFactory logger, IBuyerRepository buyerRepository, - IHubContext hubContext) + IOrderingIntegrationEventService orderingIntegrationEventService) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); - _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); + _orderingIntegrationEventService = orderingIntegrationEventService; } public async Task Handle(OrderShippedDomainEvent orderShippedDomainEvent, CancellationToken cancellationToken) @@ -40,11 +38,10 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderShipped $"a status order id: {OrderStatus.Shipped.Id}"); var order = await _orderRepository.GetAsync(orderShippedDomainEvent.Order.Id); - var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); + var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); - await _hubContext.Clients - .Group(buyer.Name) - .SendAsync("UpdatedOrderState", new { OrderId = order.Id, Status = order.OrderStatus.Name }); + var orderStatusChangedToShippedIntegrationEvent = new OrderStatusChangedToShippedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToShippedIntegrationEvent); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs index f52732dc0..0a8366893 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.Extensions.Logging; +using Ordering.API.Application.IntegrationEvents; +using Ordering.API.Application.IntegrationEvents.Events; using Ordering.Domain.Events; using System; using System.Threading; @@ -16,11 +18,17 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent private readonly ILoggerFactory _logger; private readonly IBuyerRepository _buyerRepository; private readonly IIdentityService _identityService; + private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; - public ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler(ILoggerFactory logger, IBuyerRepository buyerRepository, IIdentityService identityService) + public ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler( + ILoggerFactory logger, + IBuyerRepository buyerRepository, + IIdentityService identityService, + IOrderingIntegrationEventService orderingIntegrationEventService) { _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); _identityService = identityService ?? throw new ArgumentNullException(nameof(identityService)); + _orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -50,6 +58,9 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent await _buyerRepository.UnitOfWork .SaveEntitiesAsync(); + var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedTosubmittedIntegrationEvent); + _logger.CreateLogger(nameof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler)).LogTrace($"Buyer {buyerUpdated.Id} and related payment method were validated or updated for orderId: {orderStartedEvent.Order.Id}."); } } diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs index 21f2acac2..910d764cf 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs @@ -1,17 +1,15 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStockConfirmed { + using Domain.Events; using MediatR; + using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; - using Domain.Events; - using System; - using System.Threading.Tasks; using Ordering.API.Application.IntegrationEvents; using Ordering.API.Application.IntegrationEvents.Events; + using System; using System.Threading; - using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; - using Microsoft.AspNetCore.SignalR; - using Ordering.API.Infrastructure.Hubs; + using System.Threading.Tasks; public class OrderStatusChangedToStockConfirmedDomainEventHandler : INotificationHandler @@ -19,20 +17,17 @@ private readonly IOrderRepository _orderRepository; private readonly IBuyerRepository _buyerRepository; private readonly ILoggerFactory _logger; - private readonly IHubContext _hubContext; private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; public OrderStatusChangedToStockConfirmedDomainEventHandler( IOrderRepository orderRepository, IBuyerRepository buyerRepository, ILoggerFactory logger, - IHubContext hubContext, IOrderingIntegrationEventService orderingIntegrationEventService) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); _buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); _orderingIntegrationEventService = orderingIntegrationEventService; } @@ -45,12 +40,8 @@ var order = await _orderRepository.GetAsync(orderStatusChangedToStockConfirmedDomainEvent.OrderId); var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); - var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(orderStatusChangedToStockConfirmedDomainEvent.OrderId); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToStockConfirmedIntegrationEvent); - - await _hubContext.Clients - .Group(buyer.Name) - .SendAsync("UpdatedOrderState", new { OrderId = order.Id, Status = order.OrderStatus.Name }); + var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToStockConfirmedIntegrationEvent); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs index 63ae02246..a104215af 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs @@ -6,13 +6,17 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent { public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } public IEnumerable OrderStockItems { get; } - public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, + public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, string orderStatus, string buyerName, IEnumerable orderStockItems) { OrderId = orderId; OrderStockItems = orderStockItems; + OrderStatus = orderStatus; + BuyerName = buyerName; } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs new file mode 100644 index 000000000..6ff92a1d3 --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.API.Application.IntegrationEvents.Events +{ + public class OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToCancelledIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs index 115592308..6bcbc3494 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs @@ -6,13 +6,19 @@ public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent { public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } public IEnumerable OrderStockItems { get; } public OrderStatusChangedToPaidIntegrationEvent(int orderId, + string orderStatus, + string buyerName, IEnumerable orderStockItems) { OrderId = orderId; OrderStockItems = orderStockItems; + OrderStatus = orderStatus; + BuyerName = buyerName; } } -} \ No newline at end of file +} diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs new file mode 100644 index 000000000..1753fcc78 --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.API.Application.IntegrationEvents.Events +{ + public class OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToShippedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs index d0b1ef2c4..24e51f55b 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs @@ -5,8 +5,14 @@ public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent { public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } - public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId) - => OrderId = orderId; + public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedTosubmittedIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedTosubmittedIntegrationEvent.cs new file mode 100644 index 000000000..816c8bddf --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStatusChangedTosubmittedIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.API.Application.IntegrationEvents.Events +{ + public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index 895c8a7d0..c95cff6e1 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -39,7 +39,6 @@ - diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 0bedc1fb0..2948a3997 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -6,7 +6,6 @@ using global::Ordering.API.Application.IntegrationEvents; using global::Ordering.API.Application.IntegrationEvents.Events; using global::Ordering.API.Infrastructure.Filters; - using global::Ordering.API.Infrastructure.Hubs; using global::Ordering.API.Infrastructure.Middlewares; using Infrastructure.AutofacModules; using Infrastructure.Filters; @@ -27,10 +26,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.HealthChecks; - using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; - using Microsoft.Extensions.Primitives; - using Microsoft.IdentityModel.Tokens; using Ordering.Infrastructure; using RabbitMQ.Client; using Swashbuckle.AspNetCore.Swagger; @@ -39,7 +35,6 @@ using System.Data.Common; using System.IdentityModel.Tokens.Jwt; using System.Reflection; - using System.Threading.Tasks; public class Startup { @@ -190,7 +185,6 @@ RegisterEventBus(services); ConfigureAuthService(services); services.AddOptions(); - services.AddSignalR(); //configure autofac @@ -225,12 +219,6 @@ app.UseCors("CorsPolicy"); ConfigureAuth(app); - - app.UseSignalR(routes => - { - routes.MapHub("/notificationhub", options => - options.Transports = AspNetCore.Http.Connections.TransportType.All); - }); app.UseMvcWithDefaultRoute(); diff --git a/src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs b/src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs new file mode 100644 index 000000000..030d3b8b5 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs @@ -0,0 +1,30 @@ +using Autofac; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.AutofacModules +{ + public class ApplicationModule + : Autofac.Module + { + + public string QueriesConnectionString { get; } + + public ApplicationModule() + { + } + + protected override void Load(ContainerBuilder builder) + { + + builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent).GetTypeInfo().Assembly) + .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); + + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/Dockerfile b/src/Services/Ordering/Ordering.SignalrHub/Dockerfile new file mode 100644 index 000000000..005eea8cf --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/Dockerfile @@ -0,0 +1,20 @@ +FROM microsoft/aspnetcore:2.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM microsoft/aspnetcore-build:2.0 AS build +WORKDIR /src +COPY eShopOnContainers-ServicesAndWebApps.sln ./ +COPY src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj src/Services/Ordering/Ordering.SignalrHub/ +RUN dotnet restore -nowarn:msb3202,nu1503 +COPY . . +WORKDIR /src/src/Services/Ordering/Ordering.SignalrHub +RUN dotnet build Ordering.SignalrHub.csproj -c Release -o /app + +FROM build AS publish +RUN dotnet publish Ordering.SignalrHub.csproj -c Release -o /app + +FROM base AS final +WORKDIR /app +COPY --from=publish /app . +ENTRYPOINT ["dotnet", "Ordering.SignalrHub.dll"] diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs new file mode 100644 index 000000000..171eb81f7 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToCancelledIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs new file mode 100644 index 000000000..4b0eb780c --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents.Events; +using System; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToPaidIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs new file mode 100644 index 000000000..7a19a0659 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToShippedIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs new file mode 100644 index 000000000..324ea6259 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToStockConfirmedIntegrationEventHandler : + IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToStockConfirmedIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs new file mode 100644 index 000000000..5fac4c1da --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Ordering.SignalrHub.IntegrationEvents.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToSubmittedIntegrationEventHandler : + IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToSubmittedIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/orderStatusChangedToAwaitingValidationIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/orderStatusChangedToAwaitingValidationIntegrationEventHandler.cs new file mode 100644 index 000000000..6c2733b77 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/orderStatusChangedToAwaitingValidationIntegrationEventHandler.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents +{ + public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIntegrationEventHandler + { + private readonly IHubContext _hubContext; + + public OrderStatusChangedToAwaitingValidationIntegrationEventHandler(IHubContext hubContext) + { + _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); + } + + + public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event) + { + await _hubContext.Clients + .Group(@event.BuyerName) + .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs new file mode 100644 index 000000000..2c5ecee27 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs @@ -0,0 +1,19 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System.Collections.Generic; + +namespace Ordering.SignalrHub.IntegrationEvents +{ + public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs new file mode 100644 index 000000000..e9ac5b39b --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToCancelledIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.Events +{ + public class OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToCancelledIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs new file mode 100644 index 000000000..beb49965d --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs @@ -0,0 +1,23 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.Events +{ + public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToPaidIntegrationEvent(int orderId, + string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs new file mode 100644 index 000000000..0768c7f4e --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToShippedIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.Events +{ + public class OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToShippedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs new file mode 100644 index 000000000..588505c8f --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToStockConfirmedIntegrationEvent.cs @@ -0,0 +1,18 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + +namespace Ordering.SignalrHub.IntegrationEvents.Events +{ + public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs new file mode 100644 index 000000000..5ea0cec71 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs @@ -0,0 +1,22 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.SignalrHub.IntegrationEvents.Events +{ + public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Hubs/NotificationsHub.cs b/src/Services/Ordering/Ordering.SignalrHub/NotificationHub.cs similarity index 88% rename from src/Services/Ordering/Ordering.API/Infrastructure/Hubs/NotificationsHub.cs rename to src/Services/Ordering/Ordering.SignalrHub/NotificationHub.cs index 3db819cac..8a4c1c90f 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Hubs/NotificationsHub.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/NotificationHub.cs @@ -1,9 +1,11 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; -namespace Ordering.API.Infrastructure.Hubs +namespace Ordering.SignalrHub { [Authorize] public class NotificationsHub : Hub diff --git a/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj new file mode 100644 index 000000000..b29ea3de6 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj @@ -0,0 +1,25 @@ + + + + netcoreapp2.0 + ..\..\..\..\docker-compose.dcproj + + + + + + + + + + + + + + + + + + + + diff --git a/src/Services/Ordering/Ordering.SignalrHub/Program.cs b/src/Services/Ordering/Ordering.SignalrHub/Program.cs new file mode 100644 index 000000000..6598e5504 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Ordering.SignalrHub +{ + public class Program + { + public static void Main(string[] args) + { + BuildWebHost(args).Run(); + } + + public static IWebHost BuildWebHost(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup() + .Build(); + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/Properties/launchSettings.json b/src/Services/Ordering/Ordering.SignalrHub/Properties/launchSettings.json new file mode 100644 index 000000000..3ff683a08 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:51311/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Ordering.SignalrHub": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:51312/" + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs new file mode 100644 index 000000000..b59fcf627 --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs @@ -0,0 +1,204 @@ +using Autofac; +using Autofac.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.Azure.ServiceBus; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Ordering.SignalrHub.AutofacModules; +using Ordering.SignalrHub.IntegrationEvents; +using Ordering.SignalrHub.IntegrationEvents.EventHandling; +using Ordering.SignalrHub.IntegrationEvents.Events; +using RabbitMQ.Client; +using System; +using System.IdentityModel.Tokens.Jwt; + +namespace Ordering.SignalrHub +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public IServiceProvider ConfigureServices(IServiceCollection services) + { + services.AddCors(options => + { + options.AddPolicy("CorsPolicy", + builder => builder.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials()); + }); + + services.AddSignalR(); + + if (Configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var logger = sp.GetRequiredService>(); + + var serviceBusConnectionString = Configuration["EventBusConnection"]; + var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); + + return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); + }); + } + else + { + services.AddSingleton(sp => + { + var logger = sp.GetRequiredService>(); + + + var factory = new ConnectionFactory() + { + HostName = Configuration["EventBusConnection"] + }; + + if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) + { + factory.UserName = Configuration["EventBusUserName"]; + } + + if (!string.IsNullOrEmpty(Configuration["EventBusPassword"])) + { + factory.Password = Configuration["EventBusPassword"]; + } + + var retryCount = 5; + if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) + { + retryCount = int.Parse(Configuration["EventBusRetryCount"]); + } + + return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); + }); + } + + ConfigureAuthService(services); + + RegisterEventBus(services); + + services.AddOptions(); + + //configure autofac + var container = new ContainerBuilder(); + container.RegisterModule(new ApplicationModule()); + container.Populate(services); + + return new AutofacServiceProvider(container.Build()); + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + loggerFactory.AddAzureWebAppDiagnostics(); + loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); + + var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) + { + loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'"); + app.UsePathBase(pathBase); + } + + app.UseCors("CorsPolicy"); + + app.UseAuthentication(); + + app.UseSignalR(routes => + { + routes.MapHub("/notificationhub", options => + options.Transports = Microsoft.AspNetCore.Http.Connections.TransportType.All); + }); + + ConfigureEventBus(app); + } + + private void ConfigureEventBus(IApplicationBuilder app) + { + var eventBus = app.ApplicationServices.GetRequiredService(); + + eventBus.Subscribe(); + eventBus.Subscribe(); + eventBus.Subscribe(); + eventBus.Subscribe(); + eventBus.Subscribe(); + eventBus.Subscribe(); + } + + private void ConfigureAuthService(IServiceCollection services) + { + // prevent from mapping "sub" claim to nameidentifier. + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); + + var identityUrl = Configuration.GetValue("IdentityUrl"); + + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + + }).AddJwtBearer(options => + { + options.Authority = identityUrl; + options.RequireHttpsMetadata = false; + options.Audience = "orders.signalrhub"; + }); + } + + private void RegisterEventBus(IServiceCollection services) + { + var subscriptionClientName = Configuration["SubscriptionClientName"]; + + if (Configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); + }); + } + else + { + services.AddSingleton(sp => + { + var rabbitMQPersistentConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + + var retryCount = 5; + if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) + { + retryCount = int.Parse(Configuration["EventBusRetryCount"]); + } + + return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount); + }); + } + + services.AddSingleton(); + } + } +} diff --git a/src/Services/Ordering/Ordering.SignalrHub/appsettings.json b/src/Services/Ordering/Ordering.SignalrHub/appsettings.json new file mode 100644 index 000000000..ab02fda0f --- /dev/null +++ b/src/Services/Ordering/Ordering.SignalrHub/appsettings.json @@ -0,0 +1,15 @@ +{ + "IdentityUrl": "http://localhost:5105", + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Trace", + "System": "Information", + "Microsoft": "Information" + } + }, + "AzureServiceBusEnabled": false, + "SubscriptionClientName": "Ordering.signalrhub", + "EventBusRetryCount": 5, + "EventBusConnection": "localhost" +} \ No newline at end of file diff --git a/src/Web/WebMVC/AppSettings.cs b/src/Web/WebMVC/AppSettings.cs index 580d0c060..30403aa9d 100644 --- a/src/Web/WebMVC/AppSettings.cs +++ b/src/Web/WebMVC/AppSettings.cs @@ -11,7 +11,7 @@ namespace Microsoft.eShopOnContainers.WebMVC public string MarketingUrl { get; set; } public string PurchaseUrl { get; set; } - public string ExternalPurchaseUrl { get; set; } + public string SignalrHubUrl { get; set; } public bool ActivateCampaignDetailFunction { get; set; } public Logging Logging { get; set; } public bool UseCustomizationData { get; set; } diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index 4bc2d8b88..a83bfa644 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -131,6 +131,7 @@ namespace Microsoft.eShopOnContainers.WebMVC options.Scope.Add("marketing"); options.Scope.Add("locations"); options.Scope.Add("webshoppingagg"); + options.Scope.Add("orders.signalrhub"); }); } diff --git a/src/Web/WebMVC/Views/Shared/_Layout.cshtml b/src/Web/WebMVC/Views/Shared/_Layout.cshtml index 477ace59a..a5c472e20 100644 --- a/src/Web/WebMVC/Views/Shared/_Layout.cshtml +++ b/src/Web/WebMVC/Views/Shared/_Layout.cshtml @@ -106,7 +106,7 @@ } function stablishConnection() { - let hubHttpConnection = new signalR.HttpConnection('@settings.Value.ExternalPurchaseUrl/orders-api/notificationhub', { + let hubHttpConnection = new signalR.HttpConnection('@settings.Value.SignalrHubUrl/hub/notificationhub', { transport: signalR.TransportType.LongPolling, accessTokenFactory: () => { return "Authorization", getToken(); diff --git a/src/Web/WebSPA/AppSettings.cs b/src/Web/WebSPA/AppSettings.cs index c3fbd3b80..037ed858f 100644 --- a/src/Web/WebSPA/AppSettings.cs +++ b/src/Web/WebSPA/AppSettings.cs @@ -12,6 +12,7 @@ namespace eShopOnContainers.WebSPA public string MarketingUrl { get; set; } public string PurchaseUrl { get; set; } + public string SignalrHubUrl { get; set; } public string ActivateCampaignDetailFunction { get; set; } public bool UseCustomizationData { get; set; } diff --git a/src/Web/WebSPA/Client/modules/shared/models/configuration.model.ts b/src/Web/WebSPA/Client/modules/shared/models/configuration.model.ts index 49950e9d6..eb2e46ddb 100644 --- a/src/Web/WebSPA/Client/modules/shared/models/configuration.model.ts +++ b/src/Web/WebSPA/Client/modules/shared/models/configuration.model.ts @@ -2,5 +2,6 @@ export interface IConfiguration { identityUrl: string, marketingUrl: string, purchaseUrl: string, + signalrHubUrl: string, activateCampaignDetailFunction: boolean } \ No newline at end of file diff --git a/src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts b/src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts index ea95275e0..df97e0137 100644 --- a/src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts +++ b/src/Web/WebSPA/Client/modules/shared/services/configuration.service.ts @@ -31,6 +31,7 @@ export class ConfigurationService { this.storageService.store('identityUrl', this.serverSettings.identityUrl); this.storageService.store('marketingUrl', this.serverSettings.marketingUrl); this.storageService.store('purchaseUrl', this.serverSettings.purchaseUrl); + this.storageService.store('signalrHubUrl', this.serverSettings.signalrHubUrl); this.storageService.store('activateCampaignDetailFunction', this.serverSettings.activateCampaignDetailFunction); this.isReady = true; this.settingsLoadedSource.next(); diff --git a/src/Web/WebSPA/Client/modules/shared/services/security.service.ts b/src/Web/WebSPA/Client/modules/shared/services/security.service.ts index 45007b5d1..c77697552 100644 --- a/src/Web/WebSPA/Client/modules/shared/services/security.service.ts +++ b/src/Web/WebSPA/Client/modules/shared/services/security.service.ts @@ -82,7 +82,7 @@ export class SecurityService { let client_id = 'js'; let redirect_uri = location.origin + '/'; let response_type = 'id_token token'; - let scope = 'openid profile orders basket marketing locations webshoppingagg'; + let scope = 'openid profile orders basket marketing locations webshoppingagg orders.signalrhub'; let nonce = 'N' + Math.random() + '' + Date.now(); let state = Date.now() + '' + Math.random(); diff --git a/src/Web/WebSPA/Client/modules/shared/services/signalr.service.ts b/src/Web/WebSPA/Client/modules/shared/services/signalr.service.ts index 5eb53581f..19997216c 100644 --- a/src/Web/WebSPA/Client/modules/shared/services/signalr.service.ts +++ b/src/Web/WebSPA/Client/modules/shared/services/signalr.service.ts @@ -10,7 +10,7 @@ export class SignalrService { private _hubConnection: HubConnection; private _httpConnection: HttpConnection; - private orderApiUrl: string = ''; + private SignalrHubUrl: string = ''; private msgSignalrSource = new Subject(); msgReceived$ = this.msgSignalrSource.asObservable(); @@ -19,12 +19,12 @@ export class SignalrService { private configurationService: ConfigurationService, private toastr: ToastsManager, ) { if (this.configurationService.isReady) { - this.orderApiUrl = this.configurationService.serverSettings.purchaseUrl; + this.SignalrHubUrl = this.configurationService.serverSettings.signalrHubUrl; this.init(); } else { this.configurationService.settingsLoaded$.subscribe(x => { - this.orderApiUrl = this.configurationService.serverSettings.purchaseUrl; + this.SignalrHubUrl = this.configurationService.serverSettings.signalrHubUrl; this.init(); }); } @@ -43,7 +43,7 @@ export class SignalrService { } private register() { - this._httpConnection = new HttpConnection(this.orderApiUrl + '/orders-api/notificationhub', { + this._httpConnection = new HttpConnection(this.SignalrHubUrl + '/hub/notificationhub', { transport: TransportType.LongPolling, accessTokenFactory: () => this.securityService.GetToken() });