Skip to content

Commit

Permalink
Merge pull request #58 from robinsh/robinsh-0503
Browse files Browse the repository at this point in the history
Update script.
  • Loading branch information
robinsh committed May 10, 2019
2 parents 84790f9 + eb3c4a3 commit 4ea0f9d
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This command retrieves the subscription id of the current Azure account.
# This command retrieves the subscription id of the current Azure account.
# This field is used when setting up the routing rules.
subscriptionID=$(az account show --query id -o tsv)

Expand All @@ -9,14 +9,14 @@ randomValue=$RANDOM

# This command installs the IOT Extension for Azure CLI.
# You only need to install this the first time.
# You need it to create the device identity.
# You need it to create the device identity.
az extension add --name azure-cli-iot-ext

# Set the values for the resource names that
# Set the values for the resource names that
# don't have to be globally unique.
location=westus2
resourceGroup=ContosoResourcesMsgEn
containerName1=original
containerName1=original
containerName2=enriched
iotDeviceName=Contoso-Test-Device

Expand All @@ -25,9 +25,9 @@ iotDeviceName=Contoso-Test-Device
az group create --name $resourceGroup \
--location $location

# The IoT hub name must be globally unique,
# The IoT hub name must be globally unique,
# so add a random value to the end.
iotHubName=ContosoTestHubMsgEn$randomValue
iotHubName=ContosoTestHubMsgEn$randomValue
echo "IoT hub name = " $iotHubName

# Create the IoT hub.
Expand All @@ -36,9 +36,9 @@ az iot hub create --name $iotHubName \
--sku S1 --location $location

# You need a storage account that will have two containers
# -- one for the original messages and
# -- one for the original messages and
# one for the enriched messages.
# The storage account name must be globally unique,
# The storage account name must be globally unique,
# so add a random value to the end.
storageAccountName=contosostorage$randomValue
echo "Storage account name = " $storageAccountName
Expand All @@ -54,7 +54,7 @@ az storage account create --name $storageAccountName \
storageAccountKey=$(az storage account keys list \
--resource-group $resourceGroup \
--account-name $storageAccountName \
--query "[0].value" | tr -d '"')
--query "[0].value" | tr -d '"')

# See the value of the storage account key.
echo "storage account key = " $storageAccountKey
Expand All @@ -76,32 +76,36 @@ az iot hub device-identity create --device-id $iotDeviceName \

# Retrieve the information about the device identity, then copy the primary key to
# Notepad. You need this to run the device simulation during the testing phase.
# If you are using Cloud Shell, you can scroll the window back up to retrieve this value.
az iot hub device-identity show --device-id $iotDeviceName \
--hub-name $iotHubName

##### ROUTING FOR STORAGE #####
##### ROUTING FOR STORAGE #####

# You're going to have two routes and two endpoints.
# One points to container1 in the storage account.
# The other points to container2 in the same storage account.
# One points to container1 in the storage account
# and includes all messages.
# The other points to container2 in the same storage account
# and only includes enriched messages.

endpointType="azurestoragecontainer"
endpointName1="ContosoStorageEndpointOriginal"
endpointName2="ContosoStorageEndpointMsgEn"
#
endpointName1="ContosoStorageEndpointOriginal"
endpointName2="ContosoStorageEndpointEnriched"
routeName1="ContosoStorageRouteOriginal"
routeName2="ContosoStorageRouteEnriched"
# for first endpoint, retrieve all messages
condition1="true"
# for second endpoint, retrieve only the enriched messages
condition2='level="storage"'

# for both endpoints, retrieve the messages going to storage
condition='level="storage"'

# Get the connection string for the storage account.
# Adding the "-o tsv" makes it be returned without the default double quotes around it.
storageConnectionString=$(az storage account show-connection-string \
--name $storageAccountName --query connectionString -o tsv)

# Create the routing endpoints for storage.
# Create the routing endpoints and routes.
# Set the encoding format to either avro or json.

# This is the endpoint for container 1, for endpoint messages that are not enriched.
az iot hub routing-endpoint create \
--connection-string $storageConnectionString \
--endpoint-name $endpointName1 \
Expand All @@ -113,6 +117,7 @@ az iot hub routing-endpoint create \
--resource-group $resourceGroup \
--encoding json

# This is the endpoint for container 2, for endpoint messages that are enriched.
az iot hub routing-endpoint create \
--connection-string $storageConnectionString \
--endpoint-name $endpointName2 \
Expand All @@ -124,6 +129,7 @@ az iot hub routing-endpoint create \
--resource-group $resourceGroup \
--encoding json

# This is the route for messages that are not enriched.
# Create the route for the first storage endpoint.
az iot hub route create \
--name $routeName1 \
Expand All @@ -132,8 +138,9 @@ az iot hub route create \
--resource-group $resourceGroup \
--endpoint-name $endpointName1 \
--enabled \
--condition $condition1
--condition $condition

# This is the route for messages that are not enriched.
# Create the route for the second storage endpoint.
az iot hub route create \
--name $routeName2 \
Expand All @@ -142,4 +149,4 @@ az iot hub route create \
--resource-group $resourceGroup \
--endpoint-name $endpointName2 \
--enabled \
--condition $condition2
--condition $condition

0 comments on commit 4ea0f9d

Please sign in to comment.