Connect Part 2: Notify Event Grid from Azure Function and Read Event from Logic App

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
connecting event grid to Azure functions now it's very common for applications to talk to each other and in this diagram I have application a and it's calling application B in fact application B is going to take some period of time to process the information before it returns a response in these scenarios where that response could take seconds or hours uh application a can actually use something called event grit it's essentially a q so application a sends a message into the Q and The Q will invoke b as soon as that message comes in and in our uh demo today we're actually going to use an Azure function calling it a logic app and it's going to go through event grid so let's actually take a look at what event grid is event grid connects an event source to an event handler uh there are lots and lots of Event Source types uh that are available but in all cases they call a topic handpoint uh and on the subscription Side Event grid allows the message to Fan out it can go to a single event handler or it can go to multiple in parallel for this demo we're going to create an event grid topic and a logic app and we'll connect those two together after that we'll create an Azure function and then we're going to test the whole thing out by sending a message through the entire system so I already have a resource Group here for this demo and I'm going to create an event grid topic I just search for event grid topic there it is create it region is going to be us East no nothing nothing special here let's just create it okay so while that event grid is being created the next thing we need to do is we need to create a logic app and it looks like my event grid has uh been created successfully that's good so here I'm going to give it a name Us East we're going to use the consumption plan the next thing I'm going to do is I'm going to create a storage account the next thing I'd like to use lrs that's the cheapest option so I've got my topic created so let's go into my logic app start off with a uh a blank slate and I'm going to choose an operation so here I'm going to say event grid event grid there and here when a re resource event occurs I'm going to sign in now that I've signed in I select my subscription and my resource type is going to be event grid topic and my resource name now at this point I'm going to parse that message and get Json out of it and for the schema I'm just going to say there's a um ID and when I get this message uh I'm going to write uh uh just a a blank file into the storage account so I go to Azure file storage and I'm going to create a file let's give it a name or connection one which is a good suggestion and here my storage the one I just created it's going to ask me for uh folder path so I'm just going to say test and here I'm going to pick ID and the content the body body basically whatever content came in right that's it so save it so now that our logic APPA has been created let's create an Azure function which is going to send the message to the event grid now this is going to require a lot of cut and paste and so we're going to start with uh through the Azure docs um I've got this page opened up to the reference section on event grid output and I've selected python as my language here uh we basically need to copy this this binding section and hook it up so that's it let's try that going to create a new function my function's created and I'll go to the function Json and I'm going to add that parameter The Binding and the thing to note here is the name uh because we're going to need that uh so now we come over to our code and uh well let's get rid of all of this we don't need any of this stuff here okay so here we need to Define this in uh this parameter and again we'll go back to our docs this the way it's defined as this all right so this says when you call the function uh there's this parameter called output event it should have the data in it by the time the function returns Azure will have done all of the plumbing needed in order to send the message we'll go back and get the code to actually send the message all right now we need this datetime um so there's an import that I'm missing there's that save it we'll deploy this let's save the function too and we'll deploy this okay now that that's deployed uh let's just very quickly review how this message is actually sent all we had to do was add this code which is going to send the message into the event Hub sorry the event grid uh but there is one thing we have to configure further my event grid topic URI setting my event grid topic key setting so these are found in the event grid itself we can see that this is the topic URI let's copy that and we'll Define both of those in the configuration and I've already defined them so here's my topic key and my URI you can take a look at it um this is the actual this the actual URI that I got from the the the topic endpoint and then the access keys are here so you can copy this is the one I copied so I copied both of them in and save them okay now that those are in place we should be able to test it so I can click on test and I say run now this will connect to my logs we'll send it again yeah so I'm I'm seeing this this blue line and I don't see any Reds which means that it actually succeeded let's go see what happened in the logic app and looks like it failed let's go check out why it failed so uh if you click into the logic app you can actually see the history and I did run it twice um looks like it's the last one create file it did get the message um we can see tag one tag two uh that came in and here looks like it's complaining that the specified share test does not exist so if we if you recall the logic app itself was trying to create a file under this folder called test right so if we look at the create file it's using this folder path called test and so that file share does not exist we never created it so let's go quickly create that and then we'll test it all over again and we'll add one called test accept all the defaults we've created the file share let's try sending the message again now you see this says this is always said 200 because the message was sent into the event grid and then event grid called the logic app the logic app is what had the problem so where's our logic app and this time it succeeded and it took 1.84 seconds in the end and let's let's go look at the storage account test and sure enough I see this file in here here it is and it was just created so that was easy we created an event grid topic we created a logic app we connected those two together we created a function deployed it we borrowed some code from the documentation in Azure and then we tested it and we actually saw that it failed uh and but we were able to see the error message and as well as correct it and all of this was serverless
Info
Channel: Azure App Modernization
Views: 2,734
Rating: undefined out of 5
Keywords: Event Grid, Logic Apps, Azure Functions
Id: px4oJbNEGAA
Channel Id: undefined
Length: 9min 31sec (571 seconds)
Published: Tue Jun 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.