Publish an Event to Azure Queues using Rules
This Page Demonstrates How to Use Rules To Publish an Event to Azure Storage Queues
Last updated
This Page Demonstrates How to Use Rules To Publish an Event to Azure Storage Queues
Last updated
This documentation is based on the FoodCrunch use case. Please open the link below alongside this page to understand the examples.
Azure Storage Queues, part of the Azure Storage offering, is a service that provides scalable storage capabilities for messages. A single message in an Azure Storage Queue can be upto 64KB in size and there can be millions of messages in a queue.
To read more about Azure Storage Account and its services including Queues refer to the link below:
This tutorial does not cover the basics of Azure. It is highly recommended that one be familiar with Azure, Azure Storage, Azure Queues etc to understand this use case and the instructions better. We have attempted to keep the instructions simple enough so they can be followed by anyone.
In order to create this rule you will need the following:
An Azure Subscription
For the purposes of this example, we will quickly create a Storage Account without getting into the details of configuring all the properties. Select an Azure Subscription (1), create or select a Resource group (2), provide a unique Storage account name (3), choose a Region (4) and finally click on Review (5).
Click Create (6) to submit the form.
To create an Azure Storage Queue, select the Azure Storage account created earlier (1) and then choose Queues (2) from the list. Click + Queue (3), provide a Queue name (4) and click OK (5) to create the Queue.
Make a note of this Queue name as it will be required later.
We will need the connection string of the Azure Storage Account as well, so Squidex can authenticate to it and push messages to the Queue.
To gather the connection string, within the Storage Account (1) select Access keys (2). There are two keys provided for each Storage Account. Click Show (3) next to any one of them and then use the copy button (4) to copy the connection string. Make a note of it for use in the next steps.
To demonstrate this example consider a scenario where you have a dashboard that shows the count of assets created and the count of assets deleted. So, every time an asset is created or deleted you want a message to be sent to an Azure Queue which will then be picked up by the dashboard application to update the counter.
Navigate to Rules (1) in the Squidex App and select + New Rule (2).
Select Asset changed (3) as the trigger for this event. This will load additional settings for the trigger that can be configured such as Conditions.
Add the following custom condition (4):
Next, select Azure Queue (5) as the action.
In the following step, enter the Connection String (6) and the Queue name (7) noted down from earlier. Click Save (8) to save the rule.
After the rule is created, one can use the Simulator feature to simulate the rule using the last 100 events.
To simulate the rule, from the Rules page, click Simulator (1) next to the rule and click Simulate (2) to execute.
This will display whether an event will be published to Azure Queues or not. An event that is will trigger the publish is shown as Success.
You may not see any successful event if there are no relevant operations that meet the conditions of the rule. Or there may be events that are skipped because they are wrong events for this rule.
To test the rule perform an asset create or asset delete operation. For this example, we can upload an image to Squidex that will register an event of type AssetCreated. (Steps for uploading assets is not demonstrated as this is a very fundamental operation)
On successful trigger, you will see a status message similar to the screenshot below.
In a real world there will be applications that will consume the messages published to the Azure Storage Queue. For this demonstration, we can navigate to the Queue in Azure and see the messages.
To do so, navigate to the Azure Storage Account (1), click Queues (2) and then select the Queue (3) i.e. squidexqueue in this example, from the list.
You should now see the messages on the screen. The below screenshot is an example of an AssetCreated event and the message (without any customizations) that gets published to the Queue.
You can choose to customize the payload in order to customize the message that is pushed to the Queue. We support plain Text, Script and Liquid syntax.
Below is an example of custom payload that posts a message whether the asset is an image or not. It is written in the Liquid syntax. You must create a valid JSON string, therefore it is good to use the escape formatter.
Refer to the formatting documentation in the link below:
Below is an example of the custom payload message in Azure Queue.