Implemented service bus for marketing.api locations.api graceperiodProcess payment.api

This commit is contained in:
Ramón Tomás 2017-06-30 08:59:26 +02:00
parent a56f99f684
commit f993463856
55 changed files with 852 additions and 422 deletions

12
.env
View File

@ -5,4 +5,14 @@
# The IP below should be swapped to your real IP or DNS name, like 192.168.88.248, etc. if testing from remote browsers or mobile devices
ESHOP_EXTERNAL_DNS_NAME_OR_IP=localhost
ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92
ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=10.121.122.92
ESHOP_AZURE_REDIS_BASKET_DB=eshopredisez55a72p6wm62.redis.cache.windows.net:6379,password=RnA4HSjsZY24c+BOVLopWI5lQI5njw1WliiRz3U5Om0=,ssl=False,abortConnect=False
ESHOP_AZURE_STORAGE_ACCOUNT=https://catalogez55a72p6wm62.blob.core.windows.net/pics/
ESHOP_AZURE_SERVICE_BUS=Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=Root;SharedAccessKey=Jd6iRe3rzTWgMXDDdyUz/AcL6YxLzb8X9afSNPnq50k=;EntityPath=eshop_event_bus
ESHOP_AZURE_COSMOSDB=mongodb://eshop-nosqlez55a72p6wm62:l8jMNoLHFXOijAvaVMjHeCwHK8gAR9SovuK86uCOvwfnMhuhwytPKByOPqrQrlsDz9RPFet2J6SzEbBQXLZokA==@eshop-nosqlez55a72p6wm62.documents.azure.com:10255/?ssl=true&replicaSet=globaldb
ESHOP_AZURE_CATALOG_DB=Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=catalogdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
ESHOP_AZURE_IDENTITY_DB=Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=identitydb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
ESHOP_AZURE_ORDERING_DB=Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=orderingdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
ESHOP_AZURE_MARKETING_DB=Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=marketingdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
ESHOP_AZUREFUNC_CAMPAIGN_DETAILS_URI=https://marketing-functions.azurewebsites.net/api/MarketingDetailsHttpTrigger?code=LhqDGSKZIHM0vwBwjHHRv6umvcuRqEtB0m8laxPkb1g1IycLyWmW1A==

View File

@ -14,6 +14,10 @@
"BasketSubscriptionName": "Basket",
"CatalogSubscriptionName": "Catalog",
"OrderingSubscriptionName": "Ordering",
"LocationsSubscriptionName": "Locations",
"MarketingSubscriptionName": "Marketing",
"GracePeriodSubscriptionName": "GracePeriod",
"PaymentSubscriptionName": "Payment",
"location": "[resourceGroup().location]",
"sbVersion": "2015-08-01",
"defaultSASKeyName": "Root",
@ -130,6 +134,86 @@
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"entityAvailabilityStatus": "Available"
}
},
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('LocationsSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[variables('serviceBusTopicName')]"
],
"properties": {
"lockDuration": "00:00:30",
"requiresSession": false,
"defaultMessageTimeToLive": "14.00:00:00",
"deadLetteringOnMessageExpiration": true,
"deadLetteringOnFilterEvaluationExceptions": true,
"maxDeliveryCount": 10,
"enableBatchedOperations": false,
"status": "Active",
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"entityAvailabilityStatus": "Available"
}
},
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('MarketingSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[variables('serviceBusTopicName')]"
],
"properties": {
"lockDuration": "00:00:30",
"requiresSession": false,
"defaultMessageTimeToLive": "14.00:00:00",
"deadLetteringOnMessageExpiration": true,
"deadLetteringOnFilterEvaluationExceptions": true,
"maxDeliveryCount": 10,
"enableBatchedOperations": false,
"status": "Active",
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"entityAvailabilityStatus": "Available"
}
},
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('GracePeriodSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[variables('serviceBusTopicName')]"
],
"properties": {
"lockDuration": "00:00:30",
"requiresSession": false,
"defaultMessageTimeToLive": "14.00:00:00",
"deadLetteringOnMessageExpiration": true,
"deadLetteringOnFilterEvaluationExceptions": true,
"maxDeliveryCount": 10,
"enableBatchedOperations": false,
"status": "Active",
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"entityAvailabilityStatus": "Available"
}
},
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('PaymentSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[variables('serviceBusTopicName')]"
],
"properties": {
"lockDuration": "00:00:30",
"requiresSession": false,
"defaultMessageTimeToLive": "14.00:00:00",
"deadLetteringOnMessageExpiration": true,
"deadLetteringOnFilterEvaluationExceptions": true,
"maxDeliveryCount": 10,
"enableBatchedOperations": false,
"status": "Active",
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"entityAvailabilityStatus": "Available"
}
}
]
}

View File

@ -5,6 +5,8 @@
<DockerLaunchBrowser>True</DockerLaunchBrowser>
<DockerServiceUrl>http://localhost:5100</DockerServiceUrl>
<DockerServiceName>webmvc</DockerServiceName>
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectVersion>2.0</ProjectVersion>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.ci.build.yml" />
@ -14,12 +16,6 @@
<None Include="docker-compose.prod.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.vs.debug.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.vs.release.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
</ItemGroup>
</Project>

View File

@ -9,14 +9,14 @@ version: '3'
services:
graceperiodmanager:
environment:
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
- EventBusConnection=rabbitmq
- ConnectionString=${ESHOP_AZURE_ORDERING_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word}
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
basket.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
- ConnectionString=${ESHOP_AZURE_REDIS_BASKET_DB:-basket.data}
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
@ -26,7 +26,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
- ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word}
- PicBaseUrl=${ESHOP_AZURE_STORAGE_ACCOUNT:-http://localhost:5101/api/v1/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
@ -38,7 +38,7 @@ services:
- ASPNETCORE_URLS=http://0.0.0.0:80
- SpaClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5104
- XamarinCallback=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5105/xamarincallback #localhost do not work for UWP login, so we have to use "external" IP always
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word
- ConnectionStrings__DefaultConnection=${ESHOP_AZURE_IDENTITY_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word}
- MvcClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5100 #Local: You need to open your local dev-machine firewall at range 5100-5105.
ports:
- "5105:80"
@ -47,7 +47,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
- ConnectionString=${ESHOP_AZURE_ORDERING_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word}
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
@ -57,15 +57,16 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word
- MongoConnectionString=mongodb://nosql.data
- ConnectionString=${ESHOP_AZURE_MARKETING_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word}
- MongoConnectionString=${ESHOP_AZURE_COSMOSDB:-mongodb://nosql.data}
- MongoDatabase=MarketingDb
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
- ExternalCatalogBaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5110 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- CampaignDetailFunctionUri=${ESHOP_AZUREFUNC_CAMPAIGN_DETAILS_URI}
ports:
- "5110:80"
webspa:
environment:
- ASPNETCORE_ENVIRONMENT=Development
@ -123,7 +124,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:5108
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5108:80"
@ -131,9 +132,9 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=mongodb://nosql.data
- ConnectionString=${ESHOP_AZURE_COSMOSDB:-mongodb://nosql.data}
- Database=LocationsDb
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5109:80"

View File

@ -1,166 +0,0 @@
version: '3'
services:
basket.api:
image: eshop/basket.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Basket/Basket.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
catalog.api:
image: eshop/catalog.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Catalog/Catalog.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
identity.api:
image: eshop/identity.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Identity/Identity.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
ordering.api:
image: eshop/ordering.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Ordering/Ordering.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
marketing.api:
image: eshop/marketing.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Marketing/Marketing.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webspa:
image: eshop/webspa:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Web/WebSPA:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webmvc:
image: eshop/webmvc:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Web/WebMVC:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webstatus:
image: eshop/webstatus:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Web/WebStatus:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
payment.api:
image: eshop/payment.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Payment/Payment.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
graceperiodmanager:
image: eshop/graceperiodmanager:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ./src/Services/GracePeriod/GracePeriodManager:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
locations.api:
image: eshop/locations.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}
environment:
- DOTNET_USE_POLLING_FILE_WATCHER=1
volumes:
- ./src/Services/Location/Locations.API:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"

View File

@ -1,112 +0,0 @@
version: '3'
services:
basket.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
catalog.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
identity.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
ordering.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
marketing.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webspa:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webmvc:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
webstatus:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
payment.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
graceperiodmanager:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
locations.api:
build:
args:
source: ${DOCKER_BUILD_SOURCE}
volumes:
- ~/clrdbg:/clrdbg:ro
entrypoint: tail -f /dev/null
labels:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.13
VisualStudioVersion = 15.0.26608.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
EndProject
@ -98,6 +98,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marketing.API", "src\Servic
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventBusServiceBus", "src\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj", "{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{5B1011EC-CEE5-47AA-B336-99381D573679}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureFunctions", "AzureFunctions", "{106B787C-2CFF-4484-8C07-D14589859E94}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "marketing-functions", "src\Services\Marketing\Infrastructure\AzureFunctions\marketing-functions.csproj", "{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@ -1312,6 +1318,54 @@ Global
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x64.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x86.ActiveCfg = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x86.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|ARM.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|iPhone.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|x64.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|x64.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|x86.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.AppStore|x86.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|ARM.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|iPhone.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|x64.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|x86.ActiveCfg = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Debug|x86.Build.0 = Debug|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|Any CPU.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|ARM.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|ARM.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|iPhone.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|iPhone.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|x64.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|x64.Build.0 = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|x86.ActiveCfg = Release|Any CPU
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1359,5 +1413,8 @@ Global
{A5260DE0-1FDD-467E-9CC1-A028AB081CEE} = {91CF7717-08AB-4E65-B10E-0B426F01E2E8}
{DF395F85-B010-465D-857A-7EBCC512C0C2} = {A5260DE0-1FDD-467E-9CC1-A028AB081CEE}
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8} = {807BB76E-B2BB-47A2-A57B-3D1B20FF5E7F}
{5B1011EC-CEE5-47AA-B336-99381D573679} = {A5260DE0-1FDD-467E-9CC1-A028AB081CEE}
{106B787C-2CFF-4484-8C07-D14589859E94} = {5B1011EC-CEE5-47AA-B336-99381D573679}
{E7F8F7C0-9FE5-4DAB-B510-1F05ADD11E1F} = {106B787C-2CFF-4484-8C07-D14589859E94}
EndGlobalSection
EndGlobal

View File

@ -82,10 +82,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
{
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection);
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
@ -94,17 +94,19 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = settings.EventBusConnection
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterEventBus(services);
services.AddSwaggerGen(options =>
{
@ -130,7 +132,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIdentityService, IdentityService>();
RegisterEventBus(services);
services.AddOptions();
var container = new ContainerBuilder();

View File

@ -9,6 +9,6 @@
},
"IdentityUrl": "http://localhost:5105",
"ConnectionString": "127.0.0.1",
"AzureServiceBusEnabled": false,
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Basket"
}

View File

@ -9,7 +9,7 @@
"Microsoft": "Information"
}
},
"AzureServiceBusEnabled": false,
"AzureServiceBusEnabled": true,
"AzureStorageEnabled": true,
"SubscriptionClientName": "Catalog"
}

View File

@ -22,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
<ProjectReference Include="..\..\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.csproj" />

View File

@ -14,6 +14,8 @@
using Microsoft.Extensions.Options;
using RabbitMQ.Client;
using Services;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.Azure.ServiceBus;
public class Program
{
@ -58,20 +60,36 @@
services.AddLogging()
.AddOptions()
.Configure<ManagerSettings>(Configuration)
.AddSingleton<IManagerService, ManagerService>()
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
.AddSingleton<IManagerService, ManagerService>();
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<ManagerSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = settings.EventBusConnection
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterEventBus(services);
RegisterEventBus(services);
var container = new ContainerBuilder();
container.Populate(services);
@ -87,7 +105,25 @@
private static void RegisterEventBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
var subscriptionClientName = Configuration["SubscriptionClientName"];
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
});
}
else
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
}
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
}
}

View File

@ -9,5 +9,7 @@
},
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
"GracePeriodTime": "1",
"CheckUpdateTime": "30000"
"CheckUpdateTime": "30000",
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "GracePeriod"
}

View File

@ -114,6 +114,21 @@ namespace Identity.API.Configuration
"locations",
"marketing"
},
},
new Client
{
ClientId = "swaggerui",
ClientName = "Swagger UI",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:5109/swagger/o2c.html" },
PostLogoutRedirectUris = { "http://localhost:5109/swagger/" },
AllowedScopes =
{
"locations"
}
}
};
}

View File

@ -46,7 +46,7 @@ namespace Locations.API.Controllers
var location = await _locationsService.GetLocation(locationId);
return Ok(location);
}
//POST api/v1/[controller]/
[Route("")]
[HttpPost]

View File

@ -0,0 +1,31 @@

using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filters
{
internal class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
{
// Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
if (hasAuthorize)
{
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", new [] { "api1" } }
});
}
}
}
}

View File

@ -1,15 +1,15 @@
namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services
{
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
using System;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
using System.Collections.Generic;
using global::Locations.API.IntegrationEvents.Events;
using global::Locations.API.Model;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class LocationsService : ILocationsService
{

View File

@ -1,13 +1,13 @@
namespace Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events
namespace Locations.API.IntegrationEvents.Events
{
using Locations.API.Model;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
using System.Collections.Generic;
public class UserLocationUpdatedIntegrationEvent : IntegrationEvent
{
public string UserId { get; private set; }
public List<UserLocationDetails> LocationList { get; private set; }
public string UserId { get; set; }
public List<UserLocationDetails> LocationList { get; set; }
public UserLocationUpdatedIntegrationEvent(string userId, List<UserLocationDetails> locationList)
{

View File

@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
</ItemGroup>

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Locations.API.Model
namespace Locations.API.Model
{
public class UserLocationDetails
{

View File

@ -16,6 +16,10 @@ using Microsoft.Extensions.Logging;
using RabbitMQ.Client;
using System.Reflection;
using System;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.Azure.ServiceBus;
using System.Collections.Generic;
using Swashbuckle.AspNetCore.Swagger;
namespace Microsoft.eShopOnContainers.Services.Locations.API
{
@ -51,19 +55,34 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
services.Configure<LocationSettings>(Configuration);
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
HostName = Configuration["EventBusConnection"]
};
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
RegisterServiceBus(services);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterEventBus(services);
// Add framework services.
services.AddSwaggerGen(options =>
@ -76,6 +95,21 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
Description = "The Location Microservice HTTP API. This is a Data-Driven/CRUD microservice sample",
TermsOfService = "Terms Of Service"
});
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
{
Type = "oauth2",
Flow = "implicit",
AuthorizationUrl = "http://localhost:5105/connect/authorize",
TokenUrl = "http://localhost:5105/connect/token",
Scopes = new Dictionary<string, string>()
{
{ "locations", "Locations API" }
}
});
options.OperationFilter<AuthorizeCheckOperationFilter>();
});
services.AddCors(options =>
@ -117,6 +151,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.ConfigureOAuth2("swaggerui", "", "", "Swagger UI");
});
LocationsContextSeed.SeedAsync(app, loggerFactory)
@ -134,10 +169,28 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
});
}
private void RegisterServiceBus(IServiceCollection services)
private void RegisterEventBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
var subscriptionClientName = Configuration["SubscriptionClientName"];
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
});
}
else
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
}
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
}
}
}
}

View File

@ -9,5 +9,7 @@
"System": "Information",
"Microsoft": "Information"
}
}
},
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Locations"
}

View File

@ -0,0 +1,24 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "documentDB",
"name": "inputDocument",
"databaseName": "MarketingDb",
"collectionName": "MarketingReadDataModel",
"connection": "eshop-nosqlez55a72p6wm62_DOCUMENTDB",
"direction": "in"
}
],
"disabled": false
}

View File

@ -0,0 +1,87 @@
using System.Net;
using System.Net.Http.Headers;
using System.Configuration;
using Dapper;
using System.Data.SqlClient;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, dynamic inputDocument, TraceWriter log)
{
log.Info($"Campaign HTTP trigger function processed a request. RequestUri={req.RequestUri}");
string htmlResponse = string.Empty;
// parse query parameter
string campaignId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "campaignId", true) == 0)
.Value;
string userId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "userId", true) == 0)
.Value;
var cnnString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
using (var conn = new SqlConnection(cnnString))
{
await conn.OpenAsync();
var sql = "SELECT * FROM [dbo].[Campaign] WHERE Id = @CampaignId;";
var campaign = (await conn.QueryAsync<Campaign>(sql, new { CampaignId = campaignId })).FirstOrDefault();
htmlResponse = BuildHtmlResponse(campaign);
}
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes(htmlResponse));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;
}
private static string BuildHtmlResponse(Campaign campaign)
{
return string.Format(@"
<html>
<head>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' rel='stylesheet'>
</head>
<header>
<title>Campaign Details</title>
</header>
<body>
<div class='container'>
</br>
<div class='card-deck'>
<div class='card'>
<img class='card-img-top' src='{0}' alt='Card image cap'>
<div class='card-block'>
<h4 class='card-title'>{1}</h4>
<p class='card-text'>{2}</p>
<div class='card-footer'>
<small class='text-muted'>From {3} until {4}</small>
</div>
</div>
</div>
</div>
</div>
</body>
</html>",
campaign.PictureUri,
campaign.Name,
campaign.Description,
campaign.From.ToString("MMMM dd, yyyy"),
campaign.From.ToString("MMMM dd, yyyy"));
}
public class Campaign
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime From { get; set; }
public DateTime To { get; set; }
public string PictureUri { get; set; }
}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,16 @@
{
"IsEncrypted": false,
"Value": {
"APPSETTING_eshop-nosqlez55a72p6wm62_DOCUMENTDB": "AccountEndpoint=https://eshop-nosqlez55a72p6wm62.documents.azure.com:443/;AccountKey=l8jMNoLHFXOijAvaVMjHeCwHK8gAR9SovuK86uCOvwfnMhuhwytPKByOPqrQrlsDz9RPFet2J6SzEbBQXLZokA==;",
"APPSETTING_FUNCTIONS_EXTENSION_VERSION": "~1",
"APPSETTING_ScmType": "None",
"APPSETTING_WEBSITE_AUTH_ENABLED": "False",
"APPSETTING_AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=marketingfuncti9f5e;AccountKey=BAxvLgEs0pEyVSUgsRV8okXZY6MM/0FSikYoXyk80zhLhzPe3gyHxf9QCKDZ1qa6LsgqYdF8yoSotlg3FoDvTw==",
"APPSETTING_WEBSITE_NODE_DEFAULT_VERSION": "6.5.0",
"APPSETTING_WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "DefaultEndpointsProtocol=https;AccountName=marketingfuncti9f5e;AccountKey=BAxvLgEs0pEyVSUgsRV8okXZY6MM/0FSikYoXyk80zhLhzPe3gyHxf9QCKDZ1qa6LsgqYdF8yoSotlg3FoDvTw==",
"APPSETTING_WEBSITE_CONTENTSHARE": "marketing-functions9f5e",
"APPSETTING_WEBSITE_SLOT_NAME": "Production",
"APPSETTING_AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=marketingfuncti9f5e;AccountKey=BAxvLgEs0pEyVSUgsRV8okXZY6MM/0FSikYoXyk80zhLhzPe3gyHxf9QCKDZ1qa6LsgqYdF8yoSotlg3FoDvTw==",
"APPSETTING_WEBSITE_SITE_NAME": "marketing-functions"
}
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha5" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="MarketingDetailsHttpTrigger/function.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="MarketingDetailsHttpTrigger/run.csx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -13,6 +13,7 @@
using AspNetCore.Authorization;
using Extensions.Options;
using Microsoft.eShopOnContainers.Services.Marketing.API.ViewModel;
using Microsoft.AspNetCore.Http;
[Route("api/v1/[controller]")]
[Authorize]
@ -21,14 +22,16 @@
private readonly MarketingContext _context;
private readonly MarketingSettings _settings;
private readonly IMarketingDataRepository _marketingDataRepository;
private readonly IHttpContextAccessor _httpContextAccessor;
public CampaignsController(MarketingContext context,
IMarketingDataRepository marketingDataRepository,
IOptionsSnapshot<MarketingSettings> settings)
IOptionsSnapshot<MarketingSettings> settings, IHttpContextAccessor httpContextAccessor)
{
_context = context;
_marketingDataRepository = marketingDataRepository;
_settings = settings.Value;
_httpContextAccessor = httpContextAccessor;
}
[HttpGet]
@ -175,6 +178,7 @@
private CampaignDTO MapCampaignModelToDto(Campaign campaign)
{
var userId = _httpContextAccessor.HttpContext.User.FindFirst("sub").Value;
return new CampaignDTO
{
Id = campaign.Id,
@ -182,7 +186,8 @@
Description = campaign.Description,
From = campaign.From,
To = campaign.To,
PictureUri = GetUriPlaceholder(campaign.PictureUri)
PictureUri = GetUriPlaceholder(campaign.PictureUri),
DetailsUri = $"{_settings.CampaignDetailFunctionUri}&campaignId={campaign.Id}$userId{userId}"
};
}

View File

@ -15,5 +15,6 @@
public DateTime To { get; set; }
public string PictureUri { get; set; }
public string DetailsUri { get; set; }
}
}

View File

@ -38,6 +38,7 @@
From = DateTime.Now,
To = DateTime.Now.AddDays(7),
PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/campaigns/1/pic",
PictureName = "1.png",
Rules = new List<Rule>
{
new UserLocationRule
@ -54,6 +55,7 @@
From = DateTime.Now.AddDays(-7),
To = DateTime.Now.AddDays(14),
PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/campaigns/2/pic",
PictureName = "2.png",
Rules = new List<Rule>
{
new UserLocationRule

View File

@ -0,0 +1,121 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure;
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.MarketingMigrations
{
[DbContext(typeof(MarketingContext))]
[Migration("20170629102516_added-campaign-details")]
partial class addedcampaigndetails
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.2")
.HasAnnotation("SqlServer:Sequence:.campaign_hilo", "'campaign_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.rule_hilo", "'rule_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "campaign_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<string>("DetailsUri");
b.Property<DateTime>("From")
.HasColumnName("From");
b.Property<string>("Name")
.IsRequired()
.HasColumnName("Name");
b.Property<string>("PictureName");
b.Property<string>("PictureUri")
.IsRequired()
.HasColumnName("PictureUri");
b.Property<DateTime>("To")
.HasColumnName("To");
b.HasKey("Id");
b.ToTable("Campaign");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "rule_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CampaignId");
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<int>("RuleTypeId");
b.HasKey("Id");
b.HasIndex("CampaignId");
b.ToTable("Rule");
b.HasDiscriminator<int>("RuleTypeId");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.PurchaseHistoryRule", b =>
{
b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule");
b.ToTable("PurchaseHistoryRule");
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserLocationRule", b =>
{
b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule");
b.Property<int>("LocationId")
.HasColumnName("LocationId");
b.ToTable("UserLocationRule");
b.HasDiscriminator().HasValue(3);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserProfileRule", b =>
{
b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule");
b.ToTable("UserProfileRule");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", "Campaign")
.WithMany("Rules")
.HasForeignKey("CampaignId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.MarketingMigrations
{
public partial class addedcampaigndetails : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "DetailsUri",
table: "Campaign",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "PictureName",
table: "Campaign",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DetailsUri",
table: "Campaign");
migrationBuilder.DropColumn(
name: "PictureName",
table: "Campaign");
}
}
}

View File

@ -29,6 +29,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Mark
.IsRequired()
.HasColumnName("Description");
b.Property<string>("DetailsUri");
b.Property<DateTime>("From")
.HasColumnName("From");
@ -36,6 +38,8 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Mark
.IsRequired()
.HasColumnName("Name");
b.Property<string>("PictureName");
b.Property<string>("PictureUri")
.IsRequired()
.HasColumnName("PictureUri");

View File

@ -1,13 +1,13 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.IntegrationEvents.Events
namespace Marketing.API.IntegrationEvents.Events
{
using Model;
using Marketing.API.Model;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
using BuildingBlocks.EventBus.Events;
public class UserLocationUpdatedIntegrationEvent : IntegrationEvent
{
public string UserId { get; private set; }
public List<UserLocationDetails> LocationList { get; private set; }
public string UserId { get; set; }
public List<UserLocationDetails> LocationList { get; set; }
public UserLocationUpdatedIntegrationEvent(string userId, List<UserLocationDetails> locationList)
{

View File

@ -1,12 +1,13 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.IntegrationEvents.Handlers
namespace Marketing.API.IntegrationEvents.Handlers
{
using BuildingBlocks.EventBus.Abstractions;
using System.Threading.Tasks;
using Events;
using Marketing.API.IntegrationEvents.Events;
using Marketing.API.Model;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Repositories;
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
using System;
using Infrastructure.Repositories;
using Model;
using System.Collections.Generic;
using System.Threading.Tasks;
public class UserLocationUpdatedIntegrationEventHandler
: IIntegrationEventHandler<UserLocationUpdatedIntegrationEvent>

View File

@ -5,7 +5,7 @@
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
<OutputType>Exe</OutputType>
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
<RootNamespace>Microsoft.eShopOnContainers.Services.Marketing.API</RootNamespace>
<RootNamespace>Marketing.API</RootNamespace>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
<UserSecretsId>aspnet-Marketing.API-20161122013619</UserSecretsId>
</PropertyGroup>
@ -56,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -6,5 +6,6 @@
public string MongoConnectionString { get; set; }
public string MongoDatabase { get; set; }
public string ExternalCatalogBaseUrl { get; set; }
public string CampaignDetailFunctionUri { get; set; }
}
}

View File

@ -15,8 +15,12 @@
public DateTime To { get; set; }
public string PictureName { get; set; }
public string PictureUri { get; set; }
public string DetailsUri { get; set; }
public List<Rule> Rules { get; set; }

View File

@ -1,4 +1,4 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model
namespace Marketing.API.Model
{
public class UserLocationDetails
{

View File

@ -1,4 +1,4 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API
namespace Marketing.API
{
using System.IO;
using Microsoft.AspNetCore.Builder;

View File

@ -1,28 +1,32 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API
namespace Marketing.API
{
using Autofac;
using Autofac.Extensions.DependencyInjection;
using global::Marketing.API.IntegrationEvents.Events;
using Marketing.API.IntegrationEvents.Handlers;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.ServiceBus;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.Services.Marketing.API;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Reflection;
using System;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Filters;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using RabbitMQ.Client;
using BuildingBlocks.EventBus.Abstractions;
using BuildingBlocks.EventBus;
using IntegrationEvents.Events;
using IntegrationEvents.Handlers;
using Infrastructure.Repositories;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Polly;
using System.Threading.Tasks;
using RabbitMQ.Client;
using System;
using System.Data.SqlClient;
using System.Reflection;
using System.Threading.Tasks;
public class Startup
{
@ -73,19 +77,32 @@
//Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval
});
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
HostName = Configuration["EventBusConnection"]
};
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
RegisterServiceBus(services);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
// Add framework services.
services.AddSwaggerGen(options =>
@ -109,7 +126,12 @@
.AllowCredentials());
});
RegisterEventBus(services);
services.AddTransient<IMarketingDataRepository, MarketingDataRepository>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddOptions();
//configure autofac
var container = new ContainerBuilder();
@ -134,7 +156,7 @@
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
});
var context = (MarketingContext)app
.ApplicationServices.GetService(typeof(MarketingContext));
@ -155,21 +177,35 @@
});
}
private void RegisterServiceBus(IServiceCollection services)
private void RegisterEventBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager,
InMemoryEventBusSubscriptionsManager>();
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
var subscriptionClientName = Configuration["SubscriptionClientName"];
services.AddTransient<IIntegrationEventHandler<UserLocationUpdatedIntegrationEvent>,
UserLocationUpdatedIntegrationEventHandler>();
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
});
}
else
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
}
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<UserLocationUpdatedIntegrationEventHandler>();
}
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<UserLocationUpdatedIntegrationEvent,
IIntegrationEventHandler<UserLocationUpdatedIntegrationEvent>>();
eventBus.Subscribe<UserLocationUpdatedIntegrationEvent, UserLocationUpdatedIntegrationEventHandler>();
}
private async Task WaitForSqlAvailabilityAsync(MarketingContext ctx, ILoggerFactory loggerFactory, IApplicationBuilder app, int retries = 0)

View File

@ -9,5 +9,7 @@
"MongoConnectionString": "mongodb://nosql.data",
"MongoDatabase": "MarketingDb",
"IdentityUrl": "http://localhost:5105",
"ExternalCatalogBaseUrl": "http://localhost:5110"
"ExternalCatalogBaseUrl": "http://localhost:5110",
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Marketing"
}

View File

@ -4,11 +4,8 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using global::Ordering.API.Application.IntegrationEvents;
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
using global::Ordering.API.Application.IntegrationEvents.Events;
using global::Ordering.API.Infrastructure.Middlewares;
using Infrastructure;
using Infrastructure.Auth;
using Infrastructure.AutofacModules;
using Infrastructure.Filters;
using Infrastructure.Services;

View File

@ -9,6 +9,6 @@
"Microsoft": "Information"
}
},
"AzureServiceBusEnabled": false,
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Ordering"
}

View File

@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />

View File

@ -12,6 +12,8 @@ using RabbitMQ.Client;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Payment.API.IntegrationEvents.Events;
using Payment.API.IntegrationEvents.EventHandling;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.Azure.ServiceBus;
namespace Payment.API
{
@ -35,19 +37,34 @@ namespace Payment.API
// Add framework services.
services.AddMvc();
services.Configure<PaymentSettings>(Configuration);
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
HostName = Configuration["EventBusConnection"]
};
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
RegisterServiceBus(services);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterEventBus(services);
services.AddSwaggerGen(options =>
{
@ -84,13 +101,28 @@ namespace Payment.API
ConfigureEventBus(app);
}
private void RegisterServiceBus(IServiceCollection services)
private void RegisterEventBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
var subscriptionClientName = Configuration["SubscriptionClientName"];
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>,
OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
});
}
else
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
}
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
}
private void ConfigureEventBus(IApplicationBuilder app)

View File

@ -5,5 +5,7 @@
"Default": "Warning"
}
},
"PaymentSucceded": "true"
"PaymentSucceded": "true",
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Payment"
}

View File

@ -12,6 +12,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
public string OrderingUrl { get; set; }
public string BasketUrl { get; set; }
public string MarketingUrl { get; set; }
public bool ActivateCampaignDetailFunction { get; set; }
public Logging Logging { get; set; }
}

View File

@ -11,19 +11,29 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
using System;
using ViewModels.Pagination;
using global::WebMVC.ViewModels;
using Microsoft.Extensions.Options;
[Authorize]
public class CampaignsController : Controller
{
private readonly ICampaignService _campaignService;
private readonly AppSettings _settings;
public CampaignsController(ICampaignService campaignService) =>
public CampaignsController(ICampaignService campaignService, IOptionsSnapshot<AppSettings> settings)
{
_campaignService = campaignService;
_settings = settings.Value;
}
public async Task<IActionResult> Index(int page = 0, int pageSize = 10)
{
var campaignList = await _campaignService.GetCampaigns(pageSize, page);
if(campaignList is null)
{
return View();
}
var totalPages = (int) Math.Ceiling((decimal) campaignList.Count / pageSize);
var vm = new CampaignViewModel
@ -40,6 +50,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
}
};
ViewBag.IsCampaignDetailFunctionActive = _settings.ActivateCampaignDetailFunction;
return View(vm);
}

View File

@ -15,5 +15,6 @@
public DateTime To { get; set; }
public string PictureUri { get; set; }
public string DetailsUri { get; set; }
}
}

View File

@ -13,10 +13,8 @@
new Header() { Controller = "Catalog", Text = "Back to catalog" } })
<div class="container">
@if (Model.CampaignItems != null && Model.CampaignItems.Any())
@if(Model != null && Model.CampaignItems.Any())
{
@Html.Partial("_pagination", Model.PaginationInfo)
<div class="card-group esh-campaigns-items row">
@foreach (var catalogItem in Model.CampaignItems)
{

View File

@ -1,12 +1,17 @@
@model CampaignItem
<form asp-controller="Campaigns" asp-action="Details" asp-route-id="@Model.Id">
<div class="card-block">
<h4 class="card-title esh-campaigns-name">@Model.Name</h4>
<img class="card-img-top esh-campaigns-thumbnail" src="@Model.PictureUri" alt="@Model.Name">
<input class="esh-campaigns-button" type="submit" value="More details">
@if (ViewBag.IsCampaignDetailFunctionActive == true)
{
<input type="button" value="More Details" class="btn esh-campaigns-button" onClick="window.open('@Model.DetailsUri')">
}
else
{
<input class="esh-campaigns-button" type="submit" value="More details">
}
</div>
<div class="card-footer">

View File

@ -7,6 +7,7 @@
"CallBackUrl": "http://localhost:5100/",
"IsClusterEnv": "False",
"UseResilientHttp": "True",
"ActivateCampaignDetailFunction": "True",
"Logging": {
"IncludeScopes": false,
"LogLevel": {

View File

@ -29,7 +29,7 @@
var content = new StringContent(JsonConvert.SerializeObject(location),
Encoding.UTF8, "application/json");
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
var userId = new Guid("05a98cc6-0559-4011-9e2d-b5df524004b6");
// GIVEN a new location of user is created
@ -52,7 +52,7 @@
responseBody = await UserLocationCampaignResponse.Content.ReadAsStringAsync();
var userLocationCampaigns = JsonConvert.DeserializeObject<PaginatedItemsViewModel<CampaignDTO>>(responseBody);
Assert.True(userLocationCampaigns.Data != null);
Assert.True(userLocationCampaigns.Count > 0);
}
}
}

View File

@ -1,8 +1,10 @@
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word",
"MongoConnectionString": "mongodb://localhost:27017",
"ConnectionString": "Server=tcp:eshopsql-ez55a72p6wm62.database.windows.net,1433;Initial Catalog=marketingdb;Persist Security Info=False;User ID=eshop;Password=Pass@word!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"MongoConnectionString": "mongodb://eshop-nosqlez55a72p6wm62:l8jMNoLHFXOijAvaVMjHeCwHK8gAR9SovuK86uCOvwfnMhuhwytPKByOPqrQrlsDz9RPFet2J6SzEbBQXLZokA==@eshop-nosqlez55a72p6wm62.documents.azure.com:10255/?ssl=true&replicaSet=globaldb",
"MongoDatabase": "MarketingDb",
"IdentityUrl": "http://localhost:5105",
"isTest": "true",
"EventBusConnection": "localhost"
"EventBusConnection": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Iv+cC7Wgwc8SCrE5AXrguRW6kRMk6vR7crTVBom5nPU=;EntityPath=eshop_event_bus",
"AzureServiceBusEnabled": true,
"SubscriptionClientName": "Marketing"
}