"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Sunday, 17 January 2021

Power Automate and Azure Service Bus Queue Use Case

As you all know Power Automate is really cool!  It has got a lot of connectivities. This post aims to focus on Power Automate and also a scenario in which it can be utilized.

Consider a scenario. Payments are managed by another system and no payment / bank details are stored in Dynamics 365 CRM. But still need the capabiltiy to update it occasionally from Dynamics 365 CRM. Power Apps can be very handy in this context. An embedded Power App ( Canvas App) in Model Driven App is used here to capture the details. It triggers a Power Automate ( Flow) from a button. And then Power Automate publishes an Azure Service Bus message to the queue ( Azure Topics are also supported here in complex scenarios). An Azure function listens to Azure Service Bus queue and it gets triggered when a message arrives in the queue. Please note that it could be a console app as well. I chose Azure function for demo purpose. Azure function calls APIs of payment system and the details get updated there.

Obviously there are other ways to do it. This is just one option. Service bus is known for it'd resilience and also it has other features like retry message mechanism etc.These are just some guidelines, feel free to update as per your requirement / scenario.

Here is a small diagram to understand this sample scenario.

There are plenty of posts about Embedded Power Apps which triggers a Power Automate. So I am skipping screen shots for those. Assumption is that there is a bank wizard Canvas App and user access it when bank details need to be updated. On submission a Power Automate gets triggered from the button.

 First things first! Let's create a Service Bus and a queue. 

Navigate to htts://portal.azure.com/ and choose create new Service Bus option. Here , I chose a basic pricing tier.

 


  Important part of the Service bus is of course it's connection. This is required to establish a connection. It is  found in the Shared Access Policy section.


Primary connection string is what we need.

   
Next part is the queue. Select the Queues section.

 
Let's call the queue as bankwizardq. Properies of the queue is left as it is. But this can be changed accordingly.
Service Bus has a cool feature in preview - Service Bus explorer. This bit is interesting because I used to use a third party tool for this (https://github.com/paolosalvatori/ServiceBusExplorer). Now Microsoft provides this feature within the service bus.
 
Messages can be viewed using the Peek button. Currently no messages available. But it is ready to receive messages.

At this stage, assumption is that an Embedded canvas app triggers a flow with 4 Parameter values. Skipping this, as there are plenty of posts about this part. 

Next part is the Power Automate. It has mainly 3 steps. PowerApps is the trigger point of this Power Automate. Compose step forms a Json message from the values sent across. Send Message step is for sending a service bus message.

 

 Session Id is set to a new guid but feel free to set whichever you prefer. Output of the compose message is set to the Content. 

Service Bus connection part is shown below. Service bus connection from the Shared Access policy is provided here.
 


 
 
 Power Automate is triggered from the Power App and a message is received in the queue.

Power Automate run sample is below.

 

 Next part is to have an Azure function to gets triggered as soon as the message arrives in the queue. As mentioned earlier this could be a console app as well.

From Visual studio select a new project and choose azure function


Choose Service Bus Queue trigger and provide queue name and connection string values. This can be updated later as well. At this point, just put myqueue and mySBConnection.

 
 Connection string is updated in loal.settings.json file.

Queue name is updated as bankwizardq in the function. Next step is to run the function using the run button. When a message arrives in the service bus queue, function gets triggered.


 Console window output is below.

Azure function can call Third party APIs to udpate the details / Udpate DB as per the requirements. These are guidelines only. As per your requirement, things change.

 

No comments:

Post a Comment