Browse Source

Merge remote-tracking branch 'eShopOnAzure/dev' into dev

# Conflicts:
#	docker-compose.override.yml
#	src/Services/Catalog/Catalog.API/CatalogSettings.cs
#	src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
#	src/Services/Catalog/Catalog.API/Controllers/PicController.cs
#	src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs
#	src/Services/Catalog/Catalog.API/settings.json
#	src/Services/Ordering/Ordering.API/Startup.cs
pull/457/head
Eduard Tomas 7 years ago
parent
commit
10d03a68e3
65 changed files with 2110 additions and 92 deletions
  1. +0
    -1
      .gitignore
  2. BIN
      azure-docs/builds/images/android-build-step1.png
  3. BIN
      azure-docs/builds/images/android-build-step2.png
  4. BIN
      azure-docs/builds/images/android-build-step3.png
  5. BIN
      azure-docs/builds/images/android-build-step4.png
  6. BIN
      azure-docs/builds/images/android-build-step5.png
  7. BIN
      azure-docs/builds/images/android-build.png
  8. BIN
      azure-docs/builds/images/ios-build-step1.png
  9. BIN
      azure-docs/builds/images/ios-build-step2.png
  10. BIN
      azure-docs/builds/images/ios-build-step3.png
  11. BIN
      azure-docs/builds/images/ios-build.png
  12. +95
    -0
      azure-docs/builds/xamarin-android.md
  13. +63
    -0
      azure-docs/builds/xamarin-iOS.md
  14. +6
    -0
      azure-docs/readme.md
  15. +7
    -0
      cli-linux/run.sh
  16. +32
    -0
      deploy/az/cosmos/deploycosmos.json
  17. +9
    -0
      deploy/az/cosmos/deploycosmos.parameters.json
  18. +23
    -0
      deploy/az/create-resources.cmd
  19. +20
    -0
      deploy/az/readme.md
  20. +31
    -0
      deploy/az/redis/readme.md
  21. +42
    -0
      deploy/az/redis/redisdeploy.json
  22. +9
    -0
      deploy/az/redis/redisdeploy.parameters.json
  23. +33
    -0
      deploy/az/servicebus/readme.md
  24. +145
    -0
      deploy/az/servicebus/sbusdeploy.json
  25. +9
    -0
      deploy/az/servicebus/sbusdeploy.parameters.json
  26. +36
    -0
      deploy/az/sql/readme.md
  27. +123
    -0
      deploy/az/sql/sqldeploy.json
  28. +23
    -0
      deploy/az/sql/sqldeploy.parameters.json
  29. +91
    -0
      deploy/az/storage/deploystorage.json
  30. +12
    -0
      deploy/az/storage/deploystorage.parameters.json
  31. +48
    -0
      deploy/az/vms/docker-machine.md
  32. +199
    -0
      deploy/az/vms/linux-vm/linuxvm.json
  33. +7
    -0
      deploy/az/vms/linux-vm/linuxvm.parameters.json
  34. +77
    -0
      deploy/az/vms/plain-vm.md
  35. +10
    -0
      deploy/az/vms/readme.md
  36. +290
    -0
      deploy/az/vms/win-vm/windowsvm.json
  37. +7
    -0
      deploy/az/vms/win-vm/windowsvm.parameters.json
  38. +27
    -0
      deploy/readme.md
  39. +5
    -5
      docker-compose.override.yml
  40. +4
    -4
      docker-compose.prod.yml
  41. +52
    -1
      eShopOnContainers-ServicesAndWebApps.sln
  42. +1
    -0
      src/BuildingBlocks/EventBus/EventBus/EventBus.csproj
  43. +45
    -0
      src/BuildingBlocks/EventBus/EventBusServiceBus/DefaultServiceBusPersisterConnection.cs
  44. +180
    -0
      src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs
  45. +17
    -0
      src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj
  46. +12
    -0
      src/BuildingBlocks/EventBus/EventBusServiceBus/IServiceBusPersisterConnection.cs
  47. +0
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs
  48. +0
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Windows/project.json
  49. +2
    -0
      src/Services/Basket/Basket.API/Basket.API.csproj
  50. +6
    -18
      src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs
  51. +52
    -13
      src/Services/Basket/Basket.API/Startup.cs
  52. +4
    -2
      src/Services/Basket/Basket.API/appsettings.json
  53. +1
    -0
      src/Services/Catalog/Catalog.API/Catalog.API.csproj
  54. +2
    -1
      src/Services/Catalog/Catalog.API/CatalogSettings.cs
  55. +8
    -8
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  56. +8
    -1
      src/Services/Catalog/Catalog.API/Controllers/PicController.cs
  57. +3
    -1
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs
  58. +99
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.Designer.cs
  59. +25
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.cs
  60. +2
    -0
      src/Services/Catalog/Catalog.API/Model/CatalogItem.cs
  61. +49
    -19
      src/Services/Catalog/Catalog.API/Startup.cs
  62. +5
    -2
      src/Services/Catalog/Catalog.API/settings.json
  63. +1
    -0
      src/Services/Ordering/Ordering.API/Ordering.API.csproj
  64. +50
    -15
      src/Services/Ordering/Ordering.API/Startup.cs
  65. +3
    -1
      src/Services/Ordering/Ordering.API/settings.json

+ 0
- 1
.gitignore View File

@ -189,7 +189,6 @@ ClientBin/
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs


BIN
azure-docs/builds/images/android-build-step1.png View File

Before After
Width: 1300  |  Height: 623  |  Size: 51 KiB

BIN
azure-docs/builds/images/android-build-step2.png View File

Before After
Width: 984  |  Height: 806  |  Size: 53 KiB

BIN
azure-docs/builds/images/android-build-step3.png View File

Before After
Width: 976  |  Height: 420  |  Size: 26 KiB

BIN
azure-docs/builds/images/android-build-step4.png View File

Before After
Width: 1007  |  Height: 791  |  Size: 52 KiB

BIN
azure-docs/builds/images/android-build-step5.png View File

Before After
Width: 974  |  Height: 403  |  Size: 25 KiB

BIN
azure-docs/builds/images/android-build.png View File

Before After
Width: 640  |  Height: 601  |  Size: 58 KiB

BIN
azure-docs/builds/images/ios-build-step1.png View File

Before After
Width: 1309  |  Height: 688  |  Size: 49 KiB

BIN
azure-docs/builds/images/ios-build-step2.png View File

Before After
Width: 1157  |  Height: 697  |  Size: 48 KiB

BIN
azure-docs/builds/images/ios-build-step3.png View File

Before After
Width: 1268  |  Height: 525  |  Size: 35 KiB

BIN
azure-docs/builds/images/ios-build.png View File

Before After
Width: 668  |  Height: 463  |  Size: 45 KiB

+ 95
- 0
azure-docs/builds/xamarin-android.md View File

@ -0,0 +1,95 @@
# Xamarin Android Build
Follow these steps to create a VSTS build for your eShopOnContainers app (android).
**Note**: This document assumes basic knowledge about creating builds and configuring external VSTS connections
## Creating the build
Despite the _"Get Sources"_ task there are five tasks more in the build:
1. Restore NuGet Packages
2. Build Xamarin Android Project
3. Download the certstore to sign the APK
4. Sign the APK
5. Publish the build artifact.
![Android Build Steps](images/android-build.png)
Let's discuss each of them.
### Restore NuGet Packages
Add a "NuGet restore" task and enter the following configuration:
1. Enter `eShopOnContainers-Android.sln` in "Path to solution, packages.config, or project.json". This sln is created ex professo for the build and contains only the Xamarin Android project plus the Xamarin Forms one.
![Android Build Step 1](images/android-build-step1.png)
### Build the project
Add a "Xamarin Android" task with following configuration:
1. `**/*Droid*.csproj` in "Project"
2. `$(build.binariesdirectory)/$(BuildConfiguration)` in "Output Directory"
3. `$(BuildConfiguration)` in "Configuration"
4. Ensure that the "Create App Package" checkbox is enabled
5. In "JDK Options" be sure to select "JDK 8" in the "JDK Version" dropdown.
![Android Build Step 2](images/android-build-step2.png)
### Download the keystore to sign the build
** Note** This require you have a valid keystore. Refer to [this Xamarin article](https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_2_-_signing_the_android_application_package/) for instructions on how create one, using Visual Studio and Xamarin. Or if you prefer, you can read [how use the Android SDK tools to create a keystore](https://developer.android.com/studio/publish/app-signing.html).
This build assumes the keystore is stored somewhere in internet. Beware on where you store your keystores! Keem them safe and privately. Always consider other possible alternatives on where store the keycert:
1. Store in the source control repository, **assuming it's private**. For public repositories this option is discarded
2. Store in the build agent. If you use a custom VSTS build agent, store the keycert files locally in the agent. This is simple and secure.
3. Store in internet. If this is the case, **protect the resource**. You can be forced to use this option if your repository is public *and* you use the VSTS hosted agent.
Add a task "Download file" (**Note:** this task is installed [through a VSTS extension](https://marketplace.visualstudio.com/items?itemName=automagically.DownloadFile)) with following configuration:
1. `$(keystore.url)$(keystore.name)` in "File URL"
2. `$(Build.SourcesDirectory)` in "Destination Folder"
Fill the "Credentials" section accordly.
![Android Build Step 3](images/android-build-step3.png)
**Note:** You can, of course, use any other way to download the file (like a Powershell task).
### Signing the APK
Add a "Android Signing" task with following configuation:
1. `$(build.binariesdirectory)/$(BuildConfiguration)/*.apk` in "APK Files"
2. Ensure the checkbox "Sign the APK" is checked
3. `$(Build.SourcesDirectory)\$(keystore.name)` in "Keystore file". This location has to be where the keystore is. If you downloaded it using a previous task (as our example), use the same value. If keystore is physically in the VSTS agent you can use the filepath.
4. `$(keystore.pwd)` in "Keystore Password"
5. `$(keystore.alias)` in "Keystore Alias"
6. `$(key.pwd)` in "Key password".
7. `-verbose` in "Jarsigner Arguments"
7. Ensure the checkbox "Zipalign" is checked.
![Android Build Step 4](images/android-build-step4.png)
### Publishing build artifact
Add a "Publish Build Artifacts" task, with following configuration:
1. `$(build.binariesdirectory)/$(BuildConfiguration)` in "Path to publish"
2. `drop` in "Artifact Name"
3. `Server` in "Artifact Type"
![Android Build Step 5](images/android-build-step5.png)
## Variables
You need to setup the following variables:
1. `keystore.pwd` -> Password of the keystore
2. `keystore.alias` -> Alias of the keystore
3. `keystore.url` -> Full URL of the keystore
4. `key.pwd` -> Password of the key

+ 63
- 0
azure-docs/builds/xamarin-iOS.md View File

@ -0,0 +1,63 @@
# Xamarin iOS Build
Follow these steps to create a VSTS build for your eShopOnContainers app (iOS)
**Note**: This document assumes basic knowledge about creating builds and configuring external VSTS connections
## Creating the build
Despite the _"Get Sources"_ task there are three tasks more in the build:
1. Build Xamarin iOS Project
2. Copy generated packages
3. Publish the build artifact.
![iOS Build Steps](images/ios-build.png)
Let's discuss each of them.
### Build the project
Add a "Xamarin iOS" task with following configuration:
1. `eShopOnContainers-iOS.sln` in "Solution". This solution has been created ex professo for the build.
2. Ensure that the "Create App Package" checkbox is enabled
**About signing & Provisioning section**
In order to deploy your app to a physical device you must sign it using a certificate with a provisioning profile. Refer to [this blog
post of the Xamarin team](https://blog.xamarin.com/continuous-integration-for-ios-apps-with-visual-studio-team-services/) for more info.
Basically you have three options for setting the certificate (p12 file) and the provisioning profile:
1. Use MacInCloud VSTS agent and setup the p12 file and provisioning profile in the setup [https://blogs.msdn.microsoft.com/visualstudioalm/2015/11/18/macincloud-visual-studio-team-services-build-and-improvements-to-ios-build-support/](https://blogs.msdn.microsoft.com/visualstudioalm/2015/11/18/macincloud-visual-studio-team-services-build-and-improvements-to-ios-build-support/)
2. Use a custom mac machine with the certificate and provisioning profile installed. In this case you don't have to do anything else.
3. Have the p12 file and the provisioning profile reachable on somewhere
If you choose option 3, you need to download the certificate and the provisioning profile into the build agent (using a previous build task).
Once downloaded two files, you have to specify the location of both in the "Signing & Provisioning Section".
![iOS Build Step 1](images/ios-build-step1.png)
### Copy generated files to output folder
Add a "Copy files" task with following configuration:
1. `src/Mobile/eShopOnContainers/eShopOnContainers.iOS/bin/iPhone/$(BuildConfiguration)` in "Source Folder"
2. `**/*.ipa` in "Contents"
3. `$(Build.ArtifactStagingDirectory)` in "Target Folder"
4. Ensure that "Clean Target folder" (under "Advanced" section) is checked
This way we copy the generated IPA in the _Build.ArtifactStagingDirectory_ folder (and remove any previous IPA generated by a previous build).
![iOS Build Step 2](images/ios-build-step2.png)
### Publishing build artifact
Add a "Publish Build Artifacts" task, with following configuration:
1. `$(Build.ArtifactStagingDirectory)` in "Path to publish"
2. `drop` in "Artifact Name"
3. `Server` in "Artifact Type"
![Android Build Step 3](images/ios-build-step3.png)

+ 6
- 0
azure-docs/readme.md View File

@ -0,0 +1,6 @@
# Azure Related Documentation
## Builds and releases
1. [VSTS build for Xamarin App (Android)](builds/xamarin-android.md)
2. [VSTS build for Xamarin App (iOS)](builds/xamarin-iOS.md)

+ 7
- 0
cli-linux/run.sh View File

@ -0,0 +1,7 @@
#!/bin/bash
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull
export ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=$(curl ipinfo.io/ip)
docker-compose -f docker-compose.images.yml -f docker-compose.prod.yml up -d --force-recreate

+ 32
- 0
deploy/az/cosmos/deploycosmos.json View File

@ -0,0 +1,32 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "String"
}
},
"variables": {
"name": "[concat(parameters('name'), uniqueString(resourceGroup().id))]",
"location":"[resourceGroup().location]"
},
"resources": [
{
"type": "Microsoft.DocumentDb/databaseAccounts",
"kind": "MongoDB",
"name": "[variables('name')]",
"apiVersion": "2015-04-08",
"location": "[variables('location')]",
"properties": {
"databaseAccountOfferType": "Standard",
"locations": [
{
"id": "[concat(variables('name'), '-', variables('location'))]",
"failoverPriority": 0,
"locationName": "[variables('location')]"
}
]
}
}
]
}

+ 9
- 0
deploy/az/cosmos/deploycosmos.parameters.json View File

@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "eshop-nosql"
}
}
}

+ 23
- 0
deploy/az/create-resources.cmd View File

@ -0,0 +1,23 @@
@echo off
if %1.==. GOTO error
if %2.==. GOTO error
if NOT %3.==-c. GOTO deployresources
if %4.==. GOTO error
echo Creating resource group %2 in '%4'
call az group create --name %2 --location %4
:deployresources
echo Deploying ARM template '%1.json' in resource group %2
call az group deployment create --resource-group %2 --parameters @%1.parameters.json --template-file %1.json
GOTO end
:error
echo.
echo Usage:
echo create-resources arm-file resource-group-name [-c location]
echo arm-file: Path to ARM template WITHOUT .json extension. An parameter file with same name plus '.parameters' MUST exist in same folde
echo resource-grop-name: Name of the resource group to use or create
echo -c: If appears means that resource group must be created. If -c is specified, must use enter location
echo.
echo Examples:
echo create-resources path_and_filename testgroup (Deploys path_and_filename.json with parameters specified in path_and_filename.parameters.json file).
echo create-resources path_and_filename newgroup -c westus (Deploys path_and_filename.json (with parameters specified in path_and_filename.parameters.json file) in a NEW resource group named newgroup in the westus location)
:end

+ 20
- 0
deploy/az/readme.md View File

@ -0,0 +1,20 @@
# Deploying resources using create-resources script
The `create-resources` script is a basic script to allow easy deployment of one ARM template in one resource group. You can deploy to an existing resource group or to create one.
## Deploying to a existing resource group
Just type `create-resources path-to-arm-template resourcegroup`. Called this way the script will:
1. Search for `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files
2. If they exist, will deploy them in the `resourcegroup` specified (that has to exist).
## Deploying to a new resource group
Just type `create-resources path-to-arm-template resourcegroup -c location`. Called this way the script will:
1. Search for `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files
2. If they exist, will create the `resourcegroup` specified in the `location` specified.
3. Finally will deploy `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files in the `resourcegroup`

+ 31
- 0
deploy/az/redis/readme.md View File

@ -0,0 +1,31 @@
# Deploying Redis Cache
The ARM template `redisdeploy.json` and its parameter file (`redisdeploy.parameters.json`) are used to deploy following resources:
1. One Redis Cache
## Editing sbusdeploy.parameters.json file
You can edit the `redisdeploy.parameters.parameters.json` file to set your values, but is not needed. The only parameter than can
be set is:
1. `namespaceprefix` is a string that is used to create the Redis namespace. ARM script creates unique values by appending a unique string to this parameter value, so you can leave the default value.
## Deploy the template
Once parameter file is edited you can deploy it using [create-resources script](../readme.md).
i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type:
```
create-resources.cmd redis\redisdeploy newResourceGroup -c westus
```

+ 42
- 0
deploy/az/redis/redisdeploy.json View File

@ -0,0 +1,42 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"namespaceprefix": {
"type": "string",
"metadata": {
"description": "Name of the Redis namespace"
}
}
},
"variables": {
"location": "[resourceGroup().location]",
"namespaceprefix": "[concat(parameters('namespaceprefix'), uniqueString(resourceGroup().id))]",
"sbVersion": "2016-04-01"
},
"resources": [
{
"type": "Microsoft.Cache/Redis",
"name": "[variables('namespaceprefix')]",
"apiVersion": "[variables('sbVersion')]",
"location": "[variables('location')]",
"scale": null,
"properties": {
"redisVersion": "3.2.7",
"sku": {
"name": "Standard",
"family": "C",
"capacity": 1
},
"enableNonSslPort": true,
"redisConfiguration": {
"maxclients": "1000",
"maxmemory-reserved": "50",
"maxfragmentationmemory-reserved": "50",
"maxmemory-policy": "volatile-lru",
"maxmemory-delta": "50"
}
}
}
]
}

+ 9
- 0
deploy/az/redis/redisdeploy.parameters.json View File

@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"namespaceprefix": {
"value": "eshopredis"
}
}
}

+ 33
- 0
deploy/az/servicebus/readme.md View File

@ -0,0 +1,33 @@
# Deploying Azure Service Bus
The ARM template `sbusdeploy.json` and its parameter file (`sbusdeploy.parameters.json`) are used to deploy following resources:
1. One Service Bus namespace
2. One Service Bus
3. Subscriptions used by application
## Editing sbusdeploy.parameters.json file
You can edit the `sbusdeploy.parameters.parameters.json` file to set your values, but is not needed. The only parameter than can
be set is:
1. `namespaceprefix` is a string that is used to create the namespace. ARM script creates unique values by appending a unique string to this parameter value, so you can leave the default value.
## Deploy the template
Once parameter file is edited you can deploy it using [create-resources script](../readme.md).
i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type:
```
create-resources.cmd servicebus\sbusdeploy newResourceGroup -c westus
```

+ 145
- 0
deploy/az/servicebus/sbusdeploy.json View File

@ -0,0 +1,145 @@
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"namespaceprefix": {
"type": "string",
"metadata": {
"description": "Name of the Service Bus namespace"
}
}
},
"variables": {
"serviceBusTopicName": "eshop_event_bus",
"BasketSubscriptionName": "Basket",
"CatalogSubscriptionName": "Catalog",
"OrderingSubscriptionName": "Ordering",
"location": "[resourceGroup().location]",
"sbVersion": "2015-08-01",
"defaultSASKeyName": "Root",
"namespace":"[concat(parameters('namespaceprefix'), uniqueString(resourceGroup().id))]",
"authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/topics/authorizationRules', variables('namespace'), variables('serviceBusTopicName'), variables('defaultSASKeyName'))]"
},
"resources": [
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('namespace')]",
"type": "Microsoft.ServiceBus/Namespaces",
"location": "[variables('location')]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"resources": [
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('serviceBusTopicName')]",
"type": "Topics",
"dependsOn": [
"[concat('Microsoft.ServiceBus/namespaces/', variables('namespace'))]"
],
"properties": {
"path": "[variables('serviceBusTopicName')]",
"defaultMessageTimeToLive": "14.00:00:00",
"maxSizeInMegabytes": 1024,
"requiresDuplicateDetection": false,
"enableBatchedOperations": true,
"sizeInBytes": 0,
"filteringMessagesBeforePublishing": false,
"isAnonymousAccessible": false,
"status": "Active",
"supportOrdering": false,
"autoDeleteOnIdle": "10675199.02:48:05.4775807",
"enablePartitioning": true,
"isExpress": false,
"enableSubscriptionPartitioning": false,
"enableExpress": false
},
"resources": [
{
"type": "AuthorizationRules",
"name": "[variables('defaultSASKeyName')]",
"apiVersion": "[variables('sbVersion')]",
"properties": {
"rights": [
"Manage",
"Send",
"Listen"
]
},
"dependsOn": [
"[variables('serviceBusTopicName')]"
]
},
{
"apiVersion": "[variables('sbVersion')]",
"name": "[variables('BasketSubscriptionName')]",
"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('OrderingSubscriptionName')]",
"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('CatalogSubscriptionName')]",
"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"
}
}
]
}
]
}
],
"outputs": {
"NamespaceConnectionString": {
"type": "string",
"value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
}
}
}

+ 9
- 0
deploy/az/servicebus/sbusdeploy.parameters.json View File

@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"namespaceprefix": {
"value": "eshopsb"
}
}
}

+ 36
- 0
deploy/az/sql/readme.md View File

@ -0,0 +1,36 @@
# Deploying SQL Server & SQL Databases
The ARM template `sqldeploy.json` and its parameter file (`sqldeploy.parameters.json`) are used to deploy following resources:
1. One SQL Server
2. Three SQL databases (for ordering, catalog and identity) services.
3. Firewall rules to **allow access from any IP to SQL Server**. This allows easy management, but is not desired in production environments.
## Editing sqldeploy.parameters.json file
You **must** edit the `sqldeploy.parameters.json` file to set login and password of the admin user.
1. `sql_server` is a object parameter that contains the sql server name and the database names. You can leave default values if you want.
2. `admin` is a string with the admin logon. You MUST provide a valid value
3. `adminpwd` is a string with the admin password. You MUST provide a valid value
ARM script ensures uniqueness of the SQL server created by appending one unique string in its name (defined in the `sql_server.name` parameter).
## Deploy the template
Once parameter file is edited you can deploy it using [create-resources script](../readme.md).
i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type:
```
create-resources.cmd sql\sqldeploy newResourceGroup -c westus
```

+ 123
- 0
deploy/az/sql/sqldeploy.json View File

@ -0,0 +1,123 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sql_server": {
"type": "object"
},
"admin": {
"type": "string"
},
"adminpwd": {
"type": "string"
}
},
"variables": {
"sql_server_name": "[concat(parameters('sql_server').name, '-', uniqueString(resourceGroup().id))]",
"admin": "[parameters('admin')]",
"adminpwd": "[parameters('adminpwd')]"
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"name": "[variables('sql_server_name')]",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"administratorLogin": "[variables('admin')]",
"administratorLoginPassword": "[variables('adminpwd')]",
"version": "12.0"
},
"resources": [
{
"type": "databases",
"name": "[parameters('sql_server').dbs.ordering]",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"edition": "Standard",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "S1"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
},
{
"type": "databases",
"name": "[parameters('sql_server').dbs.identity]",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"edition": "Standard",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "S1"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
},
{
"type": "databases",
"name": "[parameters('sql_server').dbs.catalog]",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"edition": "Standard",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "S1"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
},
{
"type": "databases",
"name": "[parameters('sql_server').dbs.marketing]",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"edition": "Standard",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "S1"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
},
{
"type": "firewallrules",
"name": "AllowAllWindowsAzureIps",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
},
{
"type": "firewallrules",
"name": "AllConnectionsAllowed",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]"
]
}
]
}
],
"outputs": {
}
}

+ 23
- 0
deploy/az/sql/sqldeploy.parameters.json View File

@ -0,0 +1,23 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sql_server": {
"value": {
"name": "eshopsql",
"dbs": {
"ordering": "orderingdb",
"identity": "identitydb",
"catalog": "catalogdb",
"marketing": "marketingdb"
}
}
},
"admin": {
"value": null
},
"adminpwd": {
"value": null
}
}
}

+ 91
- 0
deploy/az/storage/deploystorage.json View File

@ -0,0 +1,91 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"catalogstorage": {
"type": "string"
},
"profileName" : {
"type": "string"
}
},
"variables": {
"catalogstorage": "[concat(parameters('catalogstorage'), uniqueString(resourceGroup().id))]",
"endpointName": "[concat('endpoint-', uniqueString(resourceGroup().id))]",
"profileName": "[parameters('profileName')]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('catalogstorage')]",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[variables('catalogstorage')]"
},
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage"
},
{
"name": "[variables('profileName')]",
"type": "Microsoft.Cdn/profiles",
"location": "[resourceGroup().location]",
"apiVersion": "2016-04-02",
"tags": {
"displayName": "[variables('profileName')]"
},
"sku": {
"name": "Standard_Verizon"
},
"resources": [
{
"apiVersion": "2016-04-02",
"name": "[variables('endpointName')]",
"type": "endpoints",
"dependsOn": [
"[variables('profileName')]",
"[variables('catalogstorage')]"
],
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[variables('endpointName')]"
},
"properties": {
"originHostHeader": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('catalogstorage')),'2015-06-15' ).primaryEndpoints.blob,'https://',''),'/','')]",
"isHttpAllowed": true,
"isHttpsAllowed": true,
"queryStringCachingBehavior": "IgnoreQueryString",
"contentTypesToCompress": [
"text/plain",
"text/html",
"text/css",
"application/x-javascript",
"text/javascript"
],
"isCompressionEnabled": "True",
"origins": [
{
"name": "origin1",
"properties": {
"hostName": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('catalogstorage')),'2015-06-15' ).primaryEndpoints.blob,'https://',''),'/','')]"
}
}
]
}
}
]
}
],
"outputs": {
"hostName": {
"type": "string",
"value": "[reference(resourceId('Microsoft.cdn/profiles/endpoints', variables('profileName'), variables('endpointName'))).hostName]"
},
"originHostHeader": {
"type": "string",
"value": "[reference(resourceId('Microsoft.cdn/profiles/endpoints', variables('profileName'), variables('endpointName'))).originHostHeader]"
}
}
}

+ 12
- 0
deploy/az/storage/deploystorage.parameters.json View File

@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"catalogstorage": {
"value": "catalog"
},
"profileName":{
"value": "eshopcatalog"
}
}
}

+ 48
- 0
deploy/az/vms/docker-machine.md View File

@ -0,0 +1,48 @@
# Create a VM using docker-machine
Ensure you are logged in the desired subscription Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details.
1. Use `az account show` to find your subscription id.
2. Use `docker-machine create --driver azure --azure-subscription-id <subs_id> --azure-resource-group <resource_group> --azure-ssh-user <login_name> <machine_name>`
After use `docker-machine create` you'll need to authenticate in Azure (even thought if you are logged using `az`, because this is not an Azure CLI 2.0 command). This command will fully create the VM with all the needed settings to run Docker.
**Note** Refer to this article with all the [parameters that docker-machine accepts when creating Azure VMs](https://docs.docker.com/machine/drivers/azure/#options) for finding more parameters.
## Connecting your local environment with docker host running on the VM
Using docker-machine you control the remote VM from your local development environment (you don't need to use ssh to login to remote VM).
Connecting your local environment to a remote host is using by setting some environment variables, but the easiest way is to use again the docker-machine command. Just type `docker-machine env machine_name` (where machine_name is the name you gave when you created the VM). That command **do not change anything**, so do'nt do really nothing, but **outputs the environment variables you have to set**. This is the output of the command (running on a windows workstation):
```
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://104.42.236.237:2376
SET DOCKER_CERT_PATH=C:\Users\etoma\.docker\machine\machines\ufohost
SET DOCKER_MACHINE_NAME=ufohost
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('docker-machine env ufohost') DO @%i
```
You have to set all these environment variables, or (as the command suggest) just copy and paste the last line in your terminal.
Once you did this, your local development machine is connected to VM running Docker on Azure: all docker and docker-compose commands will run in the VM instead of your local Docker machine!

+ 199
- 0
deploy/az/vms/linux-vm/linuxvm.json View File

@ -0,0 +1,199 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"newStorageAccountName": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsNameForPublicIP": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "14.04.4-LTS",
"metadata": {
"description": "The Ubuntu version for deploying the Docker containers. This will pick a fully patched image of this given Ubuntu version. Allowed values: 14.04.4-LTS, 15.10, 16.04.0-LTS"
},
"allowedValues": [
"14.04.4-LTS",
"15.10",
"16.04.0-LTS"
]
},
"VMName": {
"type": "string",
"metadata": {
"description": "Name of VM in Azure"
}
}
},
"variables": {
"newStorageAccountName": "[take(concat(parameters('newStorageAccountName'), uniqueString(resourceGroup().id)), 23)]",
"dnsNameForPublicIP": "[concat(parameters('dnsNameForPublicIP'), uniqueString(resourceGroup().id))]",
"imagePublisher": "Canonical",
"imageOffer": "UbuntuServer",
"OSDiskName": "osdiskfordockersimple",
"nicName": "myVMNicD",
"extensionName": "DockerExtension",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"storageAccountType": "Standard_LRS",
"publicIPAddressName": "myPublicIPD",
"publicIPAddressType": "Dynamic",
"vmStorageAccountContainerName": "vhds",
"vmName": "[parameters('VMName')]",
"vmSize": "Standard_F1",
"virtualNetworkName": "MyVNETD",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('newStorageAccountName')]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "[variables('storageAccountType')]"
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsNameForPublicIP')]"
}
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk1",
"vhd": {
"uri": "[concat('http://',variables('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/', variables('extensionName'))]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "DockerExtension",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": { }
}
}
]
}

+ 7
- 0
deploy/az/vms/linux-vm/linuxvm.parameters.json View File

@ -0,0 +1,7 @@
{
"newStorageAccountName": { "value": "eshopsrvmvstorage" },
"adminUsername": { "value": "eshop" },
"adminPassword": { "value": "Pass@word" },
"dnsNameForPublicIP": { "value": "eshop-srv" },
"VMName": {"value": "MyDockerVM2"}
}

+ 77
- 0
deploy/az/vms/plain-vm.md View File

@ -0,0 +1,77 @@
# Deploy a VM to run the services
Follow these instructions to deploy a Linux-based VM with the Docker Host installed, or a VM with Windows Server 2016 plus
windows containers and Docker Daemon.
**Note**: Use this option, only if you want to provide an environment using images pulled from DockerHub (for example, to create a test environment). If you want to
be able to deploy images built by yourself (but not pushed to DockerHub) follow the [instructions about using docker-machine](./docker-machine.md).
You can use this machine to install the microservices and having a "development" environment (useful to develop and test the client apps).
Please note that this deployment is not a production deployment. In a production-based scenario, you should deploy all containers in ACS.
## Create the VM
Ensure you are logged in the desired subscription (use `az login` and `az account set` if needed. Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details.
Go to `linux-vm` or `win-vm` folder (based on if you want a Linux or Windows VM). Then:
1. Edit the file `linuxvm.parameters.json` or `windowsvm.parameters.json` (based on what VM do you want to create) with your desired values
2. Run the [create-resources script](../readme.md) to deploy the desired template (`linux-vm/linuxvm.json` or `win-vm/windowsvm.json`).
I. e. if you are in Windows and want to deploy a linux based VM, in a new resourcegroup located in westus, go to `deploy\az` folder and type:
```
create-resources.cmd vms\linux-vm\linuxvm newResourceGroup -c westus
```
**Note:** To avoid errors, ARM template used generates unique names for:
1. VM used storage
2. Public DNS
Those public names are based on the parameters set in the parameters file.
### The parameters file (linuxvm.parameters.json or winsowsvm.parameters.json)
Both files are identical and contains the minimum set of parameters needed by the ARM template to deploy the VM. ARM template accepts some other parameters (set with default values). Look the template for more info.
The parameters defined are:
1. `newStorageAccountName`: Name of the storage created for the VM. To ensure uniqueness a unique suffix will be added to this value.
2. `adminUsername`: Admin login
3. `adminPassword`: Admin password
4. `dnsNameForPublicIP`: DNS of the VM. To ensure uniqueness a unique suffix will be added to this value.
5. `VMName`: Name of the VM inside Azure
## Finding the IP and DNS of the VM
To find the IP and FQDN of the VM you can type `az vm list --resource-group <resourcegroup> --output table --show-details` (where resourcegroup is the
name of the resourcegroup where you created the VM). This command will generate output like:
```
Name ResourceGroup PowerState PublicIps Fqdns Location
---------- --------------- ------------ ------------- ------------------------------------------------ ----------
MyDockerVM MyResourceGroup VM running xx.xx.xxx.xxx eshop-srvxxxxxxxxxxxxx.westus.cloudapp.azure.com westus
```
You can use this information to connect your new VM.
## Deploy services in the VM
We are providing public images of the services in DockerHub (https://hub.docker.com/u/eshop/). To use these images, just create a folder in the VM and copy
following files to it (those files are in the root of the repo):
1. `docker-compose.nobuild.yml`
2. `docker-compose.prod.yml`
**Note:** The `docker-compose.nobuild.yml` is just a version of the `docker-compose.yml` without the `build` section. Is neede due [docker-compose bug](https://github.com/docker/compose/issues/2945).
Then log into the VM and run the command `docker-compose -f docker-compose.nobuild.yml -f docker-compose.prod.yml up --no-build -d` to start all the microservices.

+ 10
- 0
deploy/az/vms/readme.md View File

@ -0,0 +1,10 @@
## Create VM with Docker installed
There are two options for creating VM machines with Docker installed:
1. [Deploying a Linux VM to run single-server development environment using docker-machine (**Recommended for development environments**)](./docker-machine.md)
2. [Deploying a Linux VM or Windows Server 2016 to run a single-server development environment using ARM template (**Recommended for creating testing environments**)](./plain-vm.md)
If you want to create a VM for deploying images you build locally, then use the first option.
If you want to create a VM to run images deployed to DockerHub (to provide some test environment) then use the second option.

+ 290
- 0
deploy/az/vms/win-vm/windowsvm.json View File

@ -0,0 +1,290 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VMName": {
"type": "string",
"metadata": {
"description": "This name will also be used to prefix the network security group, storage, virtual network, network card, subnet and public IP address name."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsNameForPublicIP": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"newStorageAccountName": {
"type": "string",
"metadata": {
"description": "Storage name for the Virtual Machine."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D1",
"metadata": {
"description": "VM Size"
}
}
},
"variables": {
"newStorageAccountName": "[take(concat(parameters('newStorageAccountName'), uniqueString(resourceGroup().id)), 23)]",
"dnsNameForPublicIP": "[concat(parameters('dnsNameForPublicIP'), uniqueString(resourceGroup().id))]",
"windowsOSVersion": "2016-Datacenter",
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"OSDiskName": "[concat(parameters('VMName'),'_osdisk')]",
"nicName": "[concat(parameters('VMName'),'_nic')]",
"addressPrefix": "10.0.0.0/16",
"subnetName": "[concat(parameters('VMName'),'_subnet')]",
"subnetPrefix": "10.0.0.0/24",
"networkSecurityGroupName": "[concat(parameters('VMName'),'_nsg')]",
"storageAccountType": "Standard_LRS",
"publicIPAddressName": "[concat(parameters('VMName'),'_pubip')]",
"publicIPAddressType": "Dynamic",
"vmStorageAccountContainerName": "vhds",
"apiVersion": "2015-05-01-preview",
"virtualNetworkName": "[concat(parameters('VMName'),'_vnet')]",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": [
{
"name": "HTTP",
"properties": {
"description": "HTTP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "80",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
},
{
"name": "RDP",
"properties": {
"description": "RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 200,
"direction": "Inbound"
}
},
{
"name": "Docker",
"properties": {
"description": "Docker",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "2375",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 300,
"direction": "Inbound"
}
}
]
}
},
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('newStorageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "StorageAccount"
},
"properties": {
"accountType": "[variables('storageAccountType')]"
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "PublicIPAddress"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[tolower(variables('dnsNameForPublicIP'))]"
}
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
],
"tags": {
"displayName": "VirtualNetwork"
},
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "NetworkInterface"
},
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('VMName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computername": "[parameters('VMName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[variables('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
}
},
"resources": [
{
"name": "containerConfiguration",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2015-06-15",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('VMName'))]"
],
"tags": {
"displayName": "containerConfiguration"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.2",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/windows-server-containers-preview/azure-containers.ps1"
],
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File azure-containers.ps1 -adminuser ',parameters('adminUsername'))]"
}
}
}
]
}
]
}

+ 7
- 0
deploy/az/vms/win-vm/windowsvm.parameters.json View File

@ -0,0 +1,7 @@
{
"newStorageAccountName": { "value": "eshopsrvmvstoragewin" },
"adminUsername": { "value": "eshop" },
"adminPassword": { "value": "Pass@word" },
"dnsNameForPublicIP": { "value": "eshop-srv-win" },
"VMName": {"value": "eshop-srv-win"}
}

+ 27
- 0
deploy/readme.md View File

@ -0,0 +1,27 @@
# Deploying Resources On Azure
## Pre-requisites
1. [Azure CLI 2.0 Installed](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
2. Azure subscription created
Login into your azure subscription by typing `az login` (note that you maybe need to use `az account set` to set the subscription to use). Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details
## Deploying using CLI
## Deploying Virtual machines to host the services
1. [Deploying a Linux VM to run single-server development environment using docker-machine (**Recommended for development environments**)](az/vms/docker-machine.md)
2. [Deploying a Linux VM or Windows Server 2016 to run a single-server development environment using ARM template (**Recommended for creating testing environments**)](az/vms/plain-vm.md)
Using `docker-machine` is the recommended way to create a VM with docker installed. But it is limited to Linux based VMs.
## Deploying Azure resources used by the services
1. [Deploying SQL Server and databases](az/sql/readme.md)
2. [Deploying Azure Service Bus](az/servicebus/readme.md)
3. [Deploying Redis Cache](az/redis/readme.md)

+ 5
- 5
docker-compose.override.yml View File

@ -16,9 +16,9 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=basket.data
- ConnectionString=${ESHOP_AZURE_REDIS:-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=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5103:80"
@ -27,8 +27,8 @@ services:
- 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
- ExternalCatalogBaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=rabbitmq
- 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}
- UseCustomizationData=True
ports:
- "5101:80"
@ -51,7 +51,7 @@ services:
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=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=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
- UseCustomizationData=True
ports:
- "5102:80"


+ 4
- 4
docker-compose.prod.yml View File

@ -17,9 +17,9 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=basket.data
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5103:80"
@ -29,7 +29,7 @@ services:
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
- ExternalCatalogBaseUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5101:80"
@ -50,7 +50,7 @@ services:
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
- EventBusConnection=rabbitmq
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
ports:
- "5102:80"


+ 52
- 1
eShopOnContainers-ServicesAndWebApps.sln View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.12
VisualStudioVersion = 15.0.26430.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{FEA0C318-FFED-4D39-8781-265718CA43DD}"
EndProject
@ -96,6 +96,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Marketing", "Marketing", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marketing.API", "src\Services\Marketing\Marketing.API\Marketing.API.csproj", "{DF395F85-B010-465D-857A-7EBCC512C0C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventBusServiceBus", "src\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj", "{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@ -1262,6 +1264,54 @@ Global
{DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x64.Build.0 = Release|Any CPU
{DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x86.ActiveCfg = Release|Any CPU
{DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x86.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|ARM.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhone.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x64.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x64.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x86.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x86.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|ARM.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhone.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x64.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x64.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x86.ActiveCfg = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x86.Build.0 = Debug|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|Any CPU.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|ARM.ActiveCfg = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|ARM.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhone.ActiveCfg = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhone.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x64.ActiveCfg = Release|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1308,5 +1358,6 @@ Global
{23A33F9B-7672-426D-ACF9-FF8436ADC81A} = {88B22DBB-AA8F-4290-A454-2C109352C345}
{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}
EndGlobalSection
EndGlobal

+ 1
- 0
src/BuildingBlocks/EventBus/EventBus/EventBus.csproj View File

@ -10,6 +10,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
</ItemGroup>

+ 45
- 0
src/BuildingBlocks/EventBus/EventBusServiceBus/DefaultServiceBusPersisterConnection.cs View File

@ -0,0 +1,45 @@
using Microsoft.Azure.ServiceBus;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
{
public class DefaultServiceBusPersisterConnection :IServiceBusPersisterConnection
{
private readonly ILogger<DefaultServiceBusPersisterConnection> _logger;
private readonly ServiceBusConnectionStringBuilder _serviceBusConnectionStringBuilder;
private ITopicClient _topicClient;
bool _disposed;
public DefaultServiceBusPersisterConnection(ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder,
ILogger<DefaultServiceBusPersisterConnection> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_serviceBusConnectionStringBuilder = serviceBusConnectionStringBuilder ??
throw new ArgumentNullException(nameof(serviceBusConnectionStringBuilder));
_topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default);
}
public ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder => _serviceBusConnectionStringBuilder;
public ITopicClient CreateModel()
{
if(_topicClient.IsClosedOrClosing)
{
_topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default);
}
return _topicClient;
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
}
}
}

+ 180
- 0
src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs View File

@ -0,0 +1,180 @@
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
{
using System;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.ServiceBus;
using Newtonsoft.Json;
using System.Text;
using System.Threading.Tasks;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using System.Reflection;
using Microsoft.Azure.ServiceBus.Filters;
using Autofac;
using Newtonsoft.Json.Linq;
public class EventBusServiceBus : IEventBus
{
private readonly IServiceBusPersisterConnection _serviceBusPersisterConnection;
private readonly ILogger<EventBusServiceBus> _logger;
private readonly IEventBusSubscriptionsManager _subsManager;
private readonly SubscriptionClient _subscriptionClient;
private readonly ILifetimeScope _autofac;
private readonly string AUTOFAC_SCOPE_NAME = "eshop_event_bus";
public EventBusServiceBus(IServiceBusPersisterConnection serviceBusPersisterConnection,
ILogger<EventBusServiceBus> logger, IEventBusSubscriptionsManager subsManager, string subscriptionClientName,
ILifetimeScope autofac)
{
_serviceBusPersisterConnection = serviceBusPersisterConnection;
_logger = logger;
_subsManager = subsManager ?? new InMemoryEventBusSubscriptionsManager();
_subscriptionClient = new SubscriptionClient(serviceBusPersisterConnection.ServiceBusConnectionStringBuilder,
subscriptionClientName);
_autofac = autofac;
RemoveDefaultRule();
RegisterSubscriptionClientMessageHandler();
}
public void Publish(IntegrationEvent @event)
{
var eventName = @event.GetType().Name;
var jsonMessage = JsonConvert.SerializeObject(@event);
var body = Encoding.UTF8.GetBytes(jsonMessage);
var message = new Message
{
MessageId = new Guid().ToString(),
Body = Encoding.UTF8.GetBytes(jsonMessage),
Label = eventName,
};
var topicClient = _serviceBusPersisterConnection.CreateModel();
topicClient.SendAsync(message)
.GetAwaiter()
.GetResult();
}
public void SubscribeDynamic<TH>(string eventName)
where TH : IDynamicIntegrationEventHandler
{
_subsManager.AddDynamicSubscription<TH>(eventName);
}
public void Subscribe<T, TH>()
where T : IntegrationEvent
where TH : IIntegrationEventHandler<T>
{
var eventName = typeof(T).Name;
var containsKey = _subsManager.HasSubscriptionsForEvent<T>();
if (!containsKey)
{
try
{
_subscriptionClient.AddRuleAsync(new RuleDescription
{
Filter = new CorrelationFilter { Label = eventName },
Name = eventName
}).GetAwaiter().GetResult();
}
catch(ServiceBusException)
{
_logger.LogInformation($"The messaging entity {eventName} already exists.");
}
}
_subsManager.AddSubscription<T, TH>();
}
public void Unsubscribe<T, TH>()
where T : IntegrationEvent
where TH : IIntegrationEventHandler<T>
{
var eventName = typeof(T).Name;
try
{
_subscriptionClient
.RemoveRuleAsync(eventName)
.GetAwaiter()
.GetResult();
}
catch (MessagingEntityNotFoundException)
{
_logger.LogInformation($"The messaging entity {eventName} Could not be found.");
}
_subsManager.RemoveSubscription<T, TH>();
}
public void UnsubscribeDynamic<TH>(string eventName)
where TH : IDynamicIntegrationEventHandler
{
_subsManager.RemoveDynamicSubscription<TH>(eventName);
}
public void Dispose()
{
_subsManager.Clear();
}
private void RegisterSubscriptionClientMessageHandler()
{
_subscriptionClient.RegisterMessageHandler(
async (message, token) =>
{
var eventName = message.Label;
var messageData = Encoding.UTF8.GetString(message.Body);
await ProcessEvent(eventName, messageData);
},
new MessageHandlerOptions() { MaxConcurrentCalls = 10, AutoComplete = true });
}
private async Task ProcessEvent(string eventName, string message)
{
if (_subsManager.HasSubscriptionsForEvent(eventName))
{
using (var scope = _autofac.BeginLifetimeScope(AUTOFAC_SCOPE_NAME))
{
var subscriptions = _subsManager.GetHandlersForEvent(eventName);
foreach (var subscription in subscriptions)
{
if (subscription.IsDynamic)
{
var handler = scope.ResolveOptional(subscription.HandlerType) as IDynamicIntegrationEventHandler;
dynamic eventData = JObject.Parse(message);
await handler.Handle(eventData);
}
else
{
var eventType = _subsManager.GetEventTypeByName(eventName);
var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
var handler = scope.ResolveOptional(subscription.HandlerType);
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
}
}
}
}
}
private void RemoveDefaultRule()
{
try
{
_subscriptionClient
.RemoveRuleAsync(SubscriptionClient.DefaultRule)
.GetAwaiter()
.GetResult();
}
catch (MessagingEntityNotFoundException)
{
_logger.LogInformation($"The messaging entity {SubscriptionClient.DefaultRule} Could not be found.");
}
}
}
}

+ 17
- 0
src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RootNamespace>Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.5-preview" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventBus\EventBus.csproj" />
</ItemGroup>
</Project>

+ 12
- 0
src/BuildingBlocks/EventBus/EventBusServiceBus/IServiceBusPersisterConnection.cs View File

@ -0,0 +1,12 @@
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus
{
using System;
using Microsoft.Azure.ServiceBus;
public interface IServiceBusPersisterConnection : IDisposable
{
ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder { get; }
ITopicClient CreateModel();
}
}

+ 0
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs View File


+ 0
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Windows/project.json View File


+ 2
- 0
src/Services/Basket/Basket.API/Basket.API.csproj View File

@ -20,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
<PackageReference Include="StackExchange.Redis" Version="1.2.3" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.2" />
@ -38,6 +39,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\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />


+ 6
- 18
src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs View File

@ -4,7 +4,6 @@ using Newtonsoft.Json;
using StackExchange.Redis;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
@ -16,12 +15,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
private ConnectionMultiplexer _redis;
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
{
_settings = options.Value;
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
}
public async Task<bool> DeleteBasketAsync(string id)
@ -93,21 +90,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
}
private async Task ConnectToRedisAsync()
{
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
if (IPAddress.TryParse(_settings.ConnectionString, out var ip))
{
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString());
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}");
}
else
{
// workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString);
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}");
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString());
}
{
var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true);
configuration.ResolveDns = true;
_logger.LogInformation($"Connecting to database {configuration.SslHost}.");
_redis = await ConnectionMultiplexer.ConnectAsync(configuration);
}
}
}

+ 52
- 13
src/Services/Basket/Basket.API/Startup.cs View File

@ -26,6 +26,9 @@ using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.Azure.ServiceBus;
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
public class Startup
@ -68,23 +71,40 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSingleton<ConnectionMultiplexer>(sp =>
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var ips = Dns.GetHostAddressesAsync(settings.ConnectionString).Result;
ConfigurationOptions configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
configuration.ResolveDns = true;
return ConnectionMultiplexer.Connect(ips.First().ToString());
return ConnectionMultiplexer.Connect(configuration);
});
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
HostName = settings.EventBusConnection
};
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = settings.EventBusConnection
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
services.AddSwaggerGen(options =>
{
@ -109,7 +129,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIdentityService, IdentityService>();
RegisterServiceBus(services);
RegisterEventBus(services);
services.AddOptions();
var container = new ContainerBuilder();
@ -117,9 +138,27 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
return new AutofacServiceProvider(container.Build());
}
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>();
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();


+ 4
- 2
src/Services/Basket/Basket.API/appsettings.json View File

@ -8,5 +8,7 @@
}
},
"IdentityUrl": "http://localhost:5105",
"ConnectionString": "127.0.0.1"
}
"ConnectionString": "127.0.0.1",
"AzureServiceBusEnabled": false,
"SubscriptionClientName": "Basket"
}

+ 1
- 0
src/Services/Catalog/Catalog.API/Catalog.API.csproj View File

@ -64,6 +64,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\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.Extensions.HealthChecks.SqlServer\Microsoft.Extensions.HealthChecks.SqlServer.csproj" />


+ 2
- 1
src/Services/Catalog/Catalog.API/CatalogSettings.cs View File

@ -2,10 +2,11 @@
{
public class CatalogSettings
{
public string ExternalCatalogBaseUrl {get;set;}
public string PicBaseUrl { get;set;}
public string EventBusConnection { get; set; }
public bool UseCustomizationData { get; set; }
public bool AzureStorageEnabled { get; set; }
}
}

+ 8
- 8
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -200,7 +200,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
CatalogTypeId = product.CatalogTypeId,
Description = product.Description,
Name = product.Name,
PictureUri = product.PictureUri,
PictureFileName = product.PictureFileName,
Price = product.Price
};
_catalogContext.CatalogItems.Add(item);
@ -231,14 +231,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
private List<CatalogItem> ChangeUriPlaceholder(List<CatalogItem> items)
{
var baseUri = _settings.ExternalCatalogBaseUrl;
items.ForEach(x =>
var baseUri = _settings.PicBaseUrl;
items.ForEach(catalogItem =>
{
if (!x.PictureUri.Contains('/'))
{
x.PictureUri = $"{baseUri}/api/v1/pic/{x.PictureUri}";
}
catalogItem.PictureUri = _settings.AzureStorageEnabled
? baseUri + catalogItem.PictureFileName
: baseUri + catalogItem.Id;
});
return items;


+ 8
- 1
src/Services/Catalog/Catalog.API/Controllers/PicController.cs View File

@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using System.IO;
using System.Threading.Tasks;
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
@ -10,9 +13,13 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
public class PicController : Controller
{
private readonly IHostingEnvironment _env;
public PicController(IHostingEnvironment env)
private readonly CatalogContext _catalogContext;
public PicController(IHostingEnvironment env,
CatalogContext catalogContext)
{
_env = env;
_catalogContext = catalogContext;
}
[HttpGet("{filename}")]


+ 3
- 1
src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs View File

@ -36,9 +36,11 @@
builder.Property(ci => ci.Price)
.IsRequired(true);
builder.Property(ci => ci.PictureUri)
builder.Property(ci => ci.PictureFileName)
.IsRequired(false);
builder.Ignore(ci => ci.PictureUri);
builder.HasOne(ci => ci.CatalogBrand)
.WithMany()
.HasForeignKey(ci => ci.CatalogBrandId);


+ 99
- 0
src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.Designer.cs View File

@ -0,0 +1,99 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
namespace Catalog.API.Infrastructure.Migrations
{
[DbContext(typeof(CatalogContext))]
[Migration("20170530133114_AddPictureFile")]
partial class AddPictureFile
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50);
b.Property<string>("PictureFileName");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogType");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

+ 25
- 0
src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.cs View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Catalog.API.Infrastructure.Migrations
{
public partial class AddPictureFile : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "PictureUri",
table: "Catalog",
newName: "PictureFileName");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "PictureFileName",
table: "Catalog",
newName: "PictureUri");
}
}
}

+ 2
- 0
src/Services/Catalog/Catalog.API/Model/CatalogItem.cs View File

@ -13,6 +13,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
public decimal Price { get; set; }
public string PictureFileName { get; set; }
public string PictureUri { get; set; }
public int CatalogTypeId { get; set; }


+ 49
- 19
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -6,11 +6,13 @@
using global::Catalog.API.IntegrationEvents;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
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.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
@ -114,23 +116,39 @@
services.AddTransient<ICatalogIntegrationEventService, CatalogIntegrationEventService>();
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var settings = sp.GetRequiredService<IOptions<CatalogSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
HostName = settings.EventBusConnection
};
var settings = sp.GetRequiredService<IOptions<CatalogSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection);
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<CatalogSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = settings.EventBusConnection
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterServiceBus(services);
RegisterEventBus(services);
var container = new ContainerBuilder();
container.Populate(services);
return new AutofacServiceProvider(container.Build());
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
@ -189,25 +207,37 @@
);
}
private void RegisterServiceBus(IServiceCollection services)
private void RegisterEventBus(IServiceCollection services)
{
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
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>();
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>,
OrderStatusChangedToAwaitingValidationIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>,
OrderStatusChangedToPaidIntegrationEventHandler>();
}
private void ConfigureEventBus(IApplicationBuilder app)
protected virtual void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent,
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>>();
eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent,
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>>();
}
}
}

+ 5
- 2
src/Services/Catalog/Catalog.API/settings.json View File

@ -1,6 +1,6 @@
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
"ExternalCatalogBaseUrl": "http://localhost:5101",
"PicBaseUrl": "http://localhost:5101",
"UseCustomizationData": true,
"Logging": {
"IncludeScopes": false,
@ -9,5 +9,8 @@
"System": "Information",
"Microsoft": "Information"
}
}
},
"AzureServiceBusEnabled": false,
"AzureStorageEnabled": true,
"SubscriptionClientName": "Catalog"
}

+ 1
- 0
src/Services/Ordering/Ordering.API/Ordering.API.csproj View File

@ -23,6 +23,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="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />


+ 50
- 15
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -14,10 +14,12 @@
using Infrastructure.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.ServiceBus;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.Extensions.Configuration;
@ -118,19 +120,35 @@
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
var serviceBusConnectionString = Configuration["EventBusConnection"];
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
var factory = new ConnectionFactory()
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
});
}
else
{
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
HostName = Configuration["EventBusConnection"]
};
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
var factory = new ConnectionFactory()
{
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
}
RegisterEventBus(services);
RegisterServiceBus(services);
services.AddOptions();
//configure autofac
@ -162,7 +180,6 @@
});
WaitForSqlAvailabilityAsync(loggerFactory, app, env).Wait();
ConfigureEventBus(app);
var integrationEventLogContext = new IntegrationEventLogContext(
new DbContextOptionsBuilder<IntegrationEventLogContext>()
@ -170,12 +187,7 @@
.Options);
integrationEventLogContext.Database.Migrate();
}
private void RegisterServiceBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
ConfigureEventBus(app);
}
private void ConfigureEventBus(IApplicationBuilder app)
@ -201,6 +213,29 @@
});
}
private void RegisterEventBus(IServiceCollection services)
{
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>();
}
private async Task WaitForSqlAvailabilityAsync(ILoggerFactory loggerFactory, IApplicationBuilder app, IHostingEnvironment env, int retries = 0)
{


+ 3
- 1
src/Services/Ordering/Ordering.API/settings.json View File

@ -9,5 +9,7 @@
"System": "Information",
"Microsoft": "Information"
}
}
},
"AzureServiceBusEnabled": false,
"SubscriptionClientName": "Ordering"
}

Loading…
Cancel
Save