This sample demonstrates a C# Windows Service (Topshelf) that launches a Powershell script using Azcopy to download a blob. The download process is triggered when a new file is added to blob storage, Event Grid is used to route the event to a service bus queue that is consumed by the C# app.
For details on setting up Event Grid please review the following documentation page, Reacting to Blob storage events. It provides guidance on:
- Publishing events from blob storage
- Filtering events to ensure events are raised only once the blob is fully committed
The appsettings.json provides the following:
- Powershell script to run, must be located in same folder as dll/executable
- Service bus queue name Event Grid is routing blob storage events to
- Folder to download the blob to
- Service bus connection string
- SaS token for blob storage, this is the query string component (can be generated using Azure Storage Explorer)
Here is a sample appsettings.json:
{
"BlobEventConfig": {
"PowershellScript": "download_blob.ps1",
"QueueName": "filearrived",
"DestinationFolder": "c:\\temp\\blobdestination\\"
},
"ConnectionStrings": {
"ServiceBus": "Endpoint=sb://<sb name>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<sas key>",
"BlobSaSTokenQueryString": "?sv=2019-02-02&si=files-1724F37AF21&sr=c&sig=nx94H7WcoA1%2BTcLuaAjgKrJicnSTR97jEGPPzkEkDa4%3D"
}
}
This sample is provided as-is to demonstrate concepts, error handling, security, performance and other essential attributes are not explicitly included.