|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [Parameter()] |
| 4 | + [string]$Prefix = 'sbtools-test', |
| 5 | + |
| 6 | + [Parameter()] |
| 7 | + [string]$Location = 'eastus2', |
| 8 | + |
| 9 | + [Parameter()] |
| 10 | + [string]$SubscriptionId |
| 11 | +) |
| 12 | + |
| 13 | +$ErrorActionPreference = 'Stop' |
| 14 | + |
| 15 | +$resourceGroup = "$Prefix-rg" |
| 16 | + |
| 17 | +# Set subscription if provided |
| 18 | +if ($SubscriptionId) { |
| 19 | + Write-Host "Setting subscription to $SubscriptionId..." |
| 20 | + az account set --subscription $SubscriptionId |
| 21 | +} |
| 22 | + |
| 23 | +# Create resource group |
| 24 | +Write-Host "Creating resource group '$resourceGroup' in '$Location'..." |
| 25 | +az group create --name $resourceGroup --location $Location --output none |
| 26 | + |
| 27 | +# Deploy Bicep template |
| 28 | +Write-Host "Deploying infrastructure..." |
| 29 | +$deployment = az deployment group create ` |
| 30 | + --resource-group $resourceGroup ` |
| 31 | + --template-file "$PSScriptRoot/main.bicep" ` |
| 32 | + --parameters "$PSScriptRoot/main.bicepparam" ` |
| 33 | + --parameters prefix=$Prefix location=$Location ` |
| 34 | + --output json | ConvertFrom-Json |
| 35 | + |
| 36 | +$fqdn = $deployment.properties.outputs.serviceBusFqdn.value |
| 37 | +$queueName = $deployment.properties.outputs.queueName.value |
| 38 | +$appInsightsConnectionString = $deployment.properties.outputs.appInsightsConnectionString.value |
| 39 | +$appInsightsResourceId = $deployment.properties.outputs.appInsightsResourceId.value |
| 40 | + |
| 41 | +# Assign Service Bus Data Owner role to current user |
| 42 | +Write-Host "Assigning 'Azure Service Bus Data Owner' role..." |
| 43 | +$currentUser = az ad signed-in-user show --query id --output tsv |
| 44 | +$serviceBusId = az servicebus namespace show --resource-group $resourceGroup --name "$Prefix-sbns" --query id --output tsv |
| 45 | + |
| 46 | +az role assignment create ` |
| 47 | + --assignee $currentUser ` |
| 48 | + --role "Azure Service Bus Data Owner" ` |
| 49 | + --scope $serviceBusId ` |
| 50 | + --output none 2>$null |
| 51 | + |
| 52 | +Write-Host "" |
| 53 | +Write-Host "======================================" -ForegroundColor Green |
| 54 | +Write-Host " Infrastructure deployed successfully" -ForegroundColor Green |
| 55 | +Write-Host "======================================" -ForegroundColor Green |
| 56 | +Write-Host "" |
| 57 | +Write-Host "Service Bus FQDN : $fqdn" |
| 58 | +Write-Host "Queue Name : $queueName" |
| 59 | +Write-Host "App Insights Connection String: $appInsightsConnectionString" |
| 60 | +Write-Host "App Insights Resource ID : $appInsightsResourceId" |
| 61 | +Write-Host "" |
| 62 | +Write-Host "Example commands:" -ForegroundColor Cyan |
| 63 | +Write-Host " # Generate DLQ messages with correlated App Insights telemetry:" |
| 64 | +Write-Host " dotnet run --project src/ServiceBusToolset.TestHarness -- generate-dlq -n $fqdn -q $queueName -c 100 --app-insights-connection-string `"$appInsightsConnectionString`"" |
| 65 | +Write-Host "" |
| 66 | +Write-Host " # Generate DLQ messages without telemetry:" |
| 67 | +Write-Host " dotnet run --project src/ServiceBusToolset.TestHarness -- generate-dlq -n $fqdn -q $queueName -c 100" |
| 68 | +Write-Host "" |
| 69 | +Write-Host " # Diagnose DLQ messages (wait 2-5 min after generate-dlq for telemetry ingestion):" |
| 70 | +Write-Host " dotnet run --project src/ServiceBusToolset.CLI -- diagnose-dlq -n $fqdn -q $queueName -a $appInsightsResourceId" |
| 71 | +Write-Host "" |
| 72 | +Write-Host " # Dump DLQ messages:" |
| 73 | +Write-Host " dotnet run --project src/ServiceBusToolset.CLI -- dump-dlq -n $fqdn -q $queueName -i --merge-similar -o dump.json" |
0 commit comments