diff --git a/docker-compose-windows.yml b/docker-compose-windows.yml index cec7323d1..cdcd6f56b 100644 --- a/docker-compose-windows.yml +++ b/docker-compose-windows.yml @@ -46,6 +46,16 @@ services: - sql.data - rabbitmq + ordering.signalrhub: + image: eshop/ordering.signalrhub:${TAG:-latest} + build: + context: . + dockerfile: src/Services/Ordering/Ordering.SignalrHub/Dockerfile + depends_on: + - sql.data + - identity.api + - rabbitmq + marketing.api: image: eshop/marketing.api-win:${TAG:-latest} build: diff --git a/docker-compose.override.windows.yml b/docker-compose.override.windows.yml index 76ccda8b0..0d31493e6 100644 --- a/docker-compose.override.windows.yml +++ b/docker-compose.override.windows.yml @@ -54,5 +54,10 @@ services: locations.api: environment: + - EventBusUserName=admin + - EventBusPassword=password + + ordering.signalrhub: + environment: - EventBusUserName=admin - EventBusPassword=password \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 49e689a74..7dcb55595 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -311,7 +311,6 @@ services: - 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 5ec0eb5aa..f32f2e067 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -153,7 +153,7 @@ services: - sql.data - rabbitmq ordering.signalrhub: - image: eshop/orderingsignalrhub:${TAG:-latest} + image: eshop/ordering.signalrhub:${TAG:-latest} build: context: . dockerfile: src/Services/Ordering/Ordering.SignalrHub/Dockerfile diff --git a/k8s/deploy.ps1 b/k8s/deploy.ps1 index eb4fc9a91..443edb4a1 100644 --- a/k8s/deploy.ps1 +++ b/k8s/deploy.ps1 @@ -65,7 +65,7 @@ if ($buildImages) { docker-compose -p .. -f ../docker-compose.yml build Write-Host "Pushing images to $registry/$dockerOrg..." -ForegroundColor Yellow - $services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "ordering.backgroundtasks", "marketing.api","payment.api","locations.api", "webmvc", "webspa", "webstatus", "ocelotapigw", "mobileshoppingagg", "webshoppingagg") + $services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "ordering.backgroundtasks", "marketing.api","payment.api","locations.api", "webmvc", "webspa", "webstatus", "ocelotapigw", "mobileshoppingagg", "webshoppingagg", "ordering.signalrhub") foreach ($service in $services) { $imageFqdn = if ($useDockerHub) {"$dockerOrg/${service}"} else {"$registry/$dockerOrg/${service}"} @@ -168,6 +168,7 @@ ExecKube -cmd 'set image deployments/payment payment=${registryPath}${dockerOrg} ExecKube -cmd 'set image deployments/webmvc webmvc=${registryPath}${dockerOrg}/webmvc:$imageTag' ExecKube -cmd 'set image deployments/webstatus webstatus=${registryPath}${dockerOrg}/webstatus:$imageTag' ExecKube -cmd 'set image deployments/webspa webspa=${registryPath}${dockerOrg}/webspa:$imageTag' +ExecKube -cmd 'set image deployments/ordering-signalrhub ordering-signalrhub=${registryPath}${dockerOrg}/ordering.signalrhub:$imageTag' ExecKube -cmd 'set image deployments/mobileshoppingagg mobileshoppingagg=${registryPath}${dockerOrg}/mobileshoppingagg:$imageTag' ExecKube -cmd 'set image deployments/webshoppingagg webshoppingagg=${registryPath}${dockerOrg}/webshoppingagg:$imageTag' @@ -195,6 +196,7 @@ ExecKube -cmd 'rollout resume deployments/apigwmm' ExecKube -cmd 'rollout resume deployments/apigwms' ExecKube -cmd 'rollout resume deployments/apigwwm' ExecKube -cmd 'rollout resume deployments/apigwws' +ExecKube -cmd 'rollout resume deployments/ordering-signalrhub' Write-Host "WebSPA is exposed at http://$externalDns, WebMVC at http://$externalDns/webmvc, WebStatus at http://$externalDns/webstatus" -ForegroundColor Yellow diff --git a/k8s/deployments.yaml b/k8s/deployments.yaml index 2d1ae0f43..ca97df9eb 100644 --- a/k8s/deployments.yaml +++ b/k8s/deployments.yaml @@ -51,13 +51,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -109,13 +103,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -204,13 +192,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -277,13 +259,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -348,6 +324,57 @@ spec: --- apiVersion: extensions/v1beta1 kind: Deployment +metadata: + name: ordering-signalrhub +spec: + paused: true + template: + metadata: + labels: + app: eshop + component: ordering-signalrhub + spec: + containers: + - name: ordering-signalrhub + image: eshop/ordering.signalrhub + imagePullPolicy: Always + env: + - name: EventBusConnection + valueFrom: + configMapKeyRef: + name: externalcfg + key: all__EventBusConnection + - name: IdentityUrl + valueFrom: + configMapKeyRef: + name: urls + key: identity_e + - name: AzureServiceBusEnabled + valueFrom: + configMapKeyRef: + name: externalcfg + key: all__UseAzureServiceBus + - name: ApplicationInsights__InstrumentationKey + valueFrom: + configMapKeyRef: + name: externalcfg + key: all__InstrumentationKey + - name: OrchestratorType + value: 'K8S' + - name: IsClusterEnv + value: 'True' + - name: SignalrStoreConnectionString + valueFrom: + configMapKeyRef: + name: externalcfg + key: keystore + ports: + - containerPort: 80 + imagePullSecrets: + - name: registry-key +--- +apiVersion: extensions/v1beta1 +kind: Deployment metadata: name: locations spec: @@ -409,13 +436,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -492,13 +513,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -540,13 +555,7 @@ spec: value: 'K8S' ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -642,16 +651,15 @@ spec: name: externalcfg key: all__EnableLoadTest - name: OrchestratorType - value: 'K8S' + value: 'K8S' + - name: SignalrHubUrl + valueFrom: + configMapKeyRef: + name: urls + key: webshoppingapigw_e ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- @@ -814,15 +822,14 @@ spec: key: all__InstrumentationKey - name: OrchestratorType value: 'K8S' + - name: SignalrHubUrl + valueFrom: + configMapKeyRef: + name: urls + key: webshoppingapigw_e ports: - containerPort: 80 - readinessProbe: - httpGet: - path: /hc - port: 80 - scheme: HTTP - initialDelaySeconds: 300 - periodSeconds: 240 + imagePullSecrets: - name: registry-key --- diff --git a/k8s/ocelot/configuration-web-shopping.json b/k8s/ocelot/configuration-web-shopping.json index edf0714a0..021056f43 100644 --- a/k8s/ocelot/configuration-web-shopping.json +++ b/k8s/ocelot/configuration-web-shopping.json @@ -71,6 +71,18 @@ ], "UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamHttpMethod": [] + }, + { + "DownstreamPathTemplate": "/{everything}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "ordering-signalrhub", + "Port": 80 + } + ], + "UpstreamPathTemplate": "/hub/{everything}", + "UpstreamHttpMethod": [] }, { "DownstreamPathTemplate": "/{everything}", diff --git a/k8s/services.yaml b/k8s/services.yaml index f7e5f2e45..035f1c798 100644 --- a/k8s/services.yaml +++ b/k8s/services.yaml @@ -59,14 +59,28 @@ kind: Service metadata: labels: app: eshop - component: orderingbackground - name: orderingbackground + component: ordering-background + name: ordering-background spec: ports: - port: 80 selector: app: eshop - component: orderingbackground + component: ordering-background +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: eshop + component: ordering-signalrhub + name: ordering-signalrhub +spec: + ports: + - port: 80 + selector: + app: eshop + component: ordering-signalrhub --- apiVersion: v1 kind: Service diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index 0e8598dcc..1dbe59e10 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -17,6 +17,9 @@ public async Task Handle(OrderPaymentSuccededIntegrationEvent @event) { + // Simulate a work time for validating the payment + await Task.Delay(10000); + var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); orderToUpdate.SetPaidStatus(); diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index fa7463041..c08554066 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -17,6 +17,9 @@ public async Task Handle(OrderStockConfirmedIntegrationEvent @event) { + // Simulate a work time for confirming the stock + await Task.Delay(10000); + var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); orderToUpdate.SetStockConfirmedStatus(); diff --git a/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj index b29ea3de6..8b8aa5832 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj +++ b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs index b59fcf627..dd8b166c1 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs @@ -15,6 +15,7 @@ using Ordering.SignalrHub.IntegrationEvents; using Ordering.SignalrHub.IntegrationEvents.EventHandling; using Ordering.SignalrHub.IntegrationEvents.Events; using RabbitMQ.Client; +using StackExchange.Redis; using System; using System.IdentityModel.Tokens.Jwt; @@ -40,7 +41,23 @@ namespace Ordering.SignalrHub .AllowCredentials()); }); - services.AddSignalR(); + if (Configuration.GetValue("IsClusterEnv") == bool.TrueString) + { + services + .AddSignalR() + .AddRedis(Configuration["SignalrStoreConnectionString"]); + + //services + // .AddSignalR() + // .AddRedis(options => options.Factory = writer => + // { + // return ConnectionMultiplexer.Connect(Configuration["SignalrStoreConnectionString"], writer); + // }); + } + else + { + services.AddSignalR(); + } if (Configuration.GetValue("AzureServiceBusEnabled")) { diff --git a/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs b/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs index d8a952544..b6f047960 100644 --- a/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs +++ b/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs @@ -1,13 +1,11 @@ using MediatR; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SignalR; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; using Microsoft.eShopOnContainers.Services.Ordering.API.Controllers; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; using Moq; using Ordering.API.Application.Commands; -using Ordering.API.Infrastructure.Hubs; using System; using System.Linq; using System.Threading;