From dd6107c31531d142f3f11f37bab2c346dbab4838 Mon Sep 17 00:00:00 2001 From: bgarcia Date: Fri, 3 Dec 2021 10:41:27 +0100 Subject: [PATCH 1/4] 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) From 6f9dab79709ce196a81a5c14ddf3e63d84ee100e Mon Sep 17 00:00:00 2001 From: bgarcia Date: Fri, 3 Dec 2021 10:53:41 +0100 Subject: [PATCH 2/4] queue name as argument --- docs/demos/azurecontainerapps/MessageCount.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/demos/azurecontainerapps/MessageCount.ps1 b/docs/demos/azurecontainerapps/MessageCount.ps1 index 4c749a9..b4dc8b3 100644 --- a/docs/demos/azurecontainerapps/MessageCount.ps1 +++ b/docs/demos/azurecontainerapps/MessageCount.ps1 @@ -1,14 +1,15 @@ Param( [parameter(Mandatory=$true)][string]$storageAccount, - [parameter(Mandatory=$true)][string]$accesskey + [parameter(Mandatory=$true)][string]$accesskey, + [parameter(Mandatory=$false)][string]$queueName = "feed-queue" ) -function GetMessages($storageAccount, $accesskey){ +function GetMessageCount($storageAccount, $accesskey, $queueName){ $method = "GET" $contenttype = "application/x-www-form-urlencoded" $version = "2017-04-17" - $resource = "$QueueName/?comp=metadata" + $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" @@ -27,5 +28,5 @@ function GetMessages($storageAccount, $accesskey){ return $response.Headers["x-ms-approximate-messages-count"] } -$messageCount = GetMessages -storageAccount $storageAccount -accesskey $accesskey +$messageCount = GetMessageCount -storageAccount $storageAccount -accesskey $accesskey -queueName $queueName Write-Output "Feed Queue Messages: $messageCount" \ No newline at end of file From 83396317ebe4728a385d2894064e2b452a36ae2a Mon Sep 17 00:00:00 2001 From: bgarcia Date: Fri, 3 Dec 2021 10:56:25 +0100 Subject: [PATCH 3/4] Message output --- docs/demos/azurecontainerapps/MessageCount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/demos/azurecontainerapps/MessageCount.ps1 b/docs/demos/azurecontainerapps/MessageCount.ps1 index b4dc8b3..5024eb3 100644 --- a/docs/demos/azurecontainerapps/MessageCount.ps1 +++ b/docs/demos/azurecontainerapps/MessageCount.ps1 @@ -29,4 +29,4 @@ function GetMessageCount($storageAccount, $accesskey, $queueName){ } $messageCount = GetMessageCount -storageAccount $storageAccount -accesskey $accesskey -queueName $queueName -Write-Output "Feed Queue Messages: $messageCount" \ No newline at end of file +Write-Output "Queue Messages: $messageCount" \ No newline at end of file From 3e086a3e91b22159c1880d046590cd6c9ea6b30e Mon Sep 17 00:00:00 2001 From: bgarcia Date: Fri, 3 Dec 2021 11:03:26 +0100 Subject: [PATCH 4/4] Remove accept header --- docs/demos/azurecontainerapps/MessageCount.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/demos/azurecontainerapps/MessageCount.ps1 b/docs/demos/azurecontainerapps/MessageCount.ps1 index 5024eb3..7501d23 100644 --- a/docs/demos/azurecontainerapps/MessageCount.ps1 +++ b/docs/demos/azurecontainerapps/MessageCount.ps1 @@ -22,11 +22,10 @@ function GetMessageCount($storageAccount, $accesskey, $queueName){ '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 = GetMessageCount -storageAccount $storageAccount -accesskey $accesskey -queueName $queueName -Write-Output "Queue Messages: $messageCount" \ No newline at end of file +Write-Output "Messages count: $messageCount" \ No newline at end of file