From dd6107c31531d142f3f11f37bab2c346dbab4838 Mon Sep 17 00:00:00 2001 From: bgarcia Date: Fri, 3 Dec 2021 10:41:27 +0100 Subject: [PATCH] query messages --- .../demos/azurecontainerapps/MessageCount.ps1 | 31 +++++++++++++++++++ docs/demos/azurecontainerapps/Readme.md | 8 +++++ 2 files changed, 39 insertions(+) create mode 100644 docs/demos/azurecontainerapps/MessageCount.ps1 diff --git a/docs/demos/azurecontainerapps/MessageCount.ps1 b/docs/demos/azurecontainerapps/MessageCount.ps1 new file mode 100644 index 0000000..4c749a9 --- /dev/null +++ b/docs/demos/azurecontainerapps/MessageCount.ps1 @@ -0,0 +1,31 @@ + +Param( + [parameter(Mandatory=$true)][string]$storageAccount, + [parameter(Mandatory=$true)][string]$accesskey +) + +function GetMessages($storageAccount, $accesskey){ + $method = "GET" + $contenttype = "application/x-www-form-urlencoded" + $version = "2017-04-17" + $resource = "$QueueName/?comp=metadata" + $queue_url = "https://$storageAccount.queue.core.windows.net/$resource" + $GMTTime = (Get-Date).ToUniversalTime().toString('R') + $canonheaders = "x-ms-date:$GMTTime`nx-ms-version:$version`n" + $stringToSign = "$method`n`n$contenttype`n`n$canonheaders/$storageAccount/$resource" + $hmacsha = New-Object System.Security.Cryptography.HMACSHA256 + $hmacsha.key = [Convert]::FromBase64String($accesskey) + $signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign)) + $signature = [Convert]::ToBase64String($signature) + $headers = @{ + 'x-ms-date' = $GMTTime + Authorization = "SharedKeyLite " + $storageAccount + ":" + $signature + "x-ms-version" = $version + Accept = "text/xml" + } + $response = Invoke-WebRequest -Method $method -Uri $queue_url -Headers $headers -ContentType $contenttype + return $response.Headers["x-ms-approximate-messages-count"] +} + +$messageCount = GetMessages -storageAccount $storageAccount -accesskey $accesskey +Write-Output "Feed Queue Messages: $messageCount" \ No newline at end of file diff --git a/docs/demos/azurecontainerapps/Readme.md b/docs/demos/azurecontainerapps/Readme.md index eca063a..c66a960 100644 --- a/docs/demos/azurecontainerapps/Readme.md +++ b/docs/demos/azurecontainerapps/Readme.md @@ -89,6 +89,14 @@ This folder contains additional scripts needed for testing the Azure Container A sleep 2; } ``` + ```ps1 + while (1) { + $output = ./MessageCount.ps1 -storageAccount -accessKey + clear; + echo $output; + sleep 1; + } + ``` ![Initial replicas](./scale-out-demo-0.png)