Author : MD TAREQ HASSAN | Updated : 2020/10/29
The app we are gonna build
- There will be a queue storage in Azure Storage Account
- For each new entry in queue, Logic App will be triggered
- Logic App will process JSON data in the queue and create a CSV file
- The output CSV file will be stored into Azure File Share
Prerequisites
See: Azure Logic Apps Tools for Visual Studio
File share and Queue storage
- Go to Azure portal > Resource groups > Storage accounts
- Link: https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Storage%2FStorageAccounts
- Create new Storage account or use existing one
- ‘File service’ section > Create file share (i.e. orderfileshare)
- ‘Queue service’ section > Create queue (i.e. orderqueue)
Logic app visual studio project
- Visual Studio > Create a new project
- Search: ‘Resource group’ > Next
- Set project name > Create
- Select Azure template > Logic App > OK
- Right click on ‘
LogicApp.json
’ > Open with Logic app designer - Select Subscription, Resource group, Location > OK
- Templates > Blank Logic App
- Search ‘Azure Queues’ > When there are message in the queue
- Set connection name, select storage account > Create
- Queue name: select from drop down > Set time (30 sec.) > Click on the top bar to collapse step
- ’+ New step’ > Search Data operations > Select > Parse JSON
- Content: Message text
- Schema: Use sample payload to generate schema (sample json given below) > Done
- New step > Search Data operations > Select > Create CSV table
- From: Items
- Columns: Automatic
- Next step > Search ‘Azure file storage’ > Create file
- Set connection name
- Select storage account
- Create
- Set folder path
- File name: ‘Message ID’ .txt
- File content: Output
- Next step > Search ‘Azure queues’ > Select > Delete message
- Queue name: select from drop down
- Message ID: Select message id
- Pop receipt: pop receipt
- Save
Payload JSON to generate schema
{"Items": [
{"Id":"hovermind-12b956b90de4", "Name":"ABC", "Quantity": 1, "Size":"M"},
{"Id":"hovermind-eb4f9fc8f907", "Name":"PQR", "Quantity": 3, "Size":"L"},
{"Id":"hovermind-e9ffc8bebb1e", "Name":"UVW", "Quantity": 6, "Size":"S"}
]}
Publish logic app
- Right click on the project > Deploy > Select Resource Group
- Select account, subscription, resource group, templates etc. > Deploy
- Edit parameters
- Set Logic app name i.e. ‘OrderLogicApp’
- azurequeues_1_sharedkey and azurefile_1_accessKey:
- Go to azure portal > storage account > select storage account
- Under settings section > Access keys
- Copy key1
- Enter key > save
- Deploy
- PowerShell window eill open and ask for key > use same key1 again
- Visual Studio > Output window > ‘Successfully deployed template …’ should be shown
Checking published Logic App in Auzre Portal
- Go to Azure portal > Resource group > select resource group
- Logic app should be shown > Wait and Refresh if now shown
Testing published logic app
- The published logic app will check queue in every 30 seconds (we set in that way when creating logic app)
- After inserting sample data into queue, there should be file in File share and data should be deleted from queue (Delete action at the end of the flow)
Inserting sample JSON into queue
- Go to storage account: https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Storage%2FStorageAccounts
- Storage Explorer (preview) > QUEUES: Select Queue
- ’+ Add Message’
- Paste JSON (sample json given above)
- OK
- After some time, the queue should be empty and there should be file in file shares
Note: Don’t forget to cleanup logic app and related resources, logic app is cheking queue in every 30 sec. (cost)