Practice Exams:

AZ-204 Microsoft Azure Developer Associate – Connect to and consume Azure and third-party services part 4

  1. AZ-203/ 204 – Lab – Azure Event Grid – Azure Functions

Hi and welcome back. Now in this lab, let’s look at how we can actually integrate Azure functions with the Azure Event Grid service. So, I have a function app in place, so let me go on to it. I’m going to go ahead and create a new function. I’ll choose more templates. So over here we should be having a trigger for the Azure Event Grid. So let’s choose use it as your Event Grid trigger. Let’s install these extensions that’s required. Once the extension is installed, let’s hit on Continue. We can leave the name hazardous. Let’s hit on create. So we got our function in place. So automatically now in the code, we can get the event Grid data and then send it to our log. If you go on to the files, if you go on to function JSON, so you can see that you have a binding that’s of the type Event Grid trigger. So let’s go back onto our function. Now we need to ensure thatwe subscribe to the event itself.

So let’s go ahead and add an Event Grid subscription. We can give a name. We have the topic types. So let’s choose resource groups. We can choose our subscription. We can choose Azure Demo Resource Group. And again here we can filter on the events. So let’s choose again a Write success, a Delete success. And action. Success. Now we have the end point over here, so let’s leave it hazardous and let’s hit on Create. So now we have our Azure function that has subscribed to some of the events in the Event Grid service. And now you can see that you’re automatically getting information of anything that’s changing as part of that resource group, right? Just a quick lap to show you that you can also integrate or make sure that Azure functions is able to capture the events from the event bengrid service.

  1. AZ-203/ 204 – Exam Extra – Azure Event Grid – Important Points

Hi and welcome back. Now this chapter will go through some important points when it comes to the Azure Event Grid from the exam perspective. So some important points to understand when you look at the basic concepts of the Azure Event Grid are so remember that a publisher is a user or an organization that sends data on to the Event Grid service. The event source is where the event occurs. The event source sends the events on to something known as a topic. The subscriber can then subscribe to a topic to get the events. You can also create your own custom topics so that you could send events onto the custom topic itself. You can have several topics. Each topic could be related to a separate category of events. Now, this is an example wherein you can use several topics. So let’s say your application generates an event when a user signs in or when an order is being processed.

It’s better to have two separate topics for each type of event. So we’ve already seen how events occur from resources in Azure itself, and those events are then sent on to the Azure Event Grid service. You can also go ahead and create your own topic. You could then have your application send events onto the topic. And then you could have other consumers that could subscribe to the topic itself. So look at an example of how it works for events for Azure resources. So, we’ve already seen this earlier. So first you have your event source. So let’s say you’re adding a Blob object onto a container in an Azure storage account. So this will go ahead and trigger an event. So Microsoft then publishes that event onto the Azure Event Grid service.

Now, in order for that event to be available, it will be sent onto a topic. So in Azure event grid, you have multiple topics. So for example, you would have one topic specifically for storage accounts. You would have another topic for resource groups. So these events could be sent on to these different topics. And then you have your application that can be used to subscribe to the desired topic and then get the events. So this is how it works in a nutshell. Now here we are back in Azure. Now, in an earlier chapter, we had seen how we could use or create an Azure function with an Event Grid subscription. Now, apart from looking at the data itself, so this is the data object which comes as part of the Event Grid object. You can also get the ID, the event type, the subject and the topic.

So if I go up, I’ve actually performed some events on a zero and I’ve got some data that I’ve got onto the logs. Now over here, I’m just showing an example of one of the events. Now in this event itself, so you could get the event ID, what is the event topic, what is the event subject? And what is the type of event. So this event is basically of the type Microsoft Resources Resource Action Success. So this means that an action has been performed on a resource and it’s a success. Now in the data object itself, so this entire thing is your data object. So the first part is basically details about the event itself and then you have the data object. Now in the data object you have various things such as what is the action that’s being performed and if we scroll all the way down you can see what is the operation name.

So what exactly was the operation that was performed on the resource. So from here we can see that it was an action of regenerating keys on a storage account. You can also go ahead and see the status of succeeded. Now why is this important is because let’s say you have a consumer that’s actually getting the event. So this is your JSON data which you get as part of the event. So it is up to the application to pass the JSON object and get the required data. And from the exam perspective, it’s important to understand concepts as getting the operation name, getting the status, also getting various information about the events itself. Now you could also go ahead and create your own application to send events. So remember, in a zero the different resources send events onto the Event Grid Service.

But you can go ahead and even send your own events onto the Azure Event Grid Service. Now for this, this is the schema that you have to use when you’re sending an event. So you have to send an ID and Event type subject, the event type and the data itself. If you want to go ahead and send your own custom events, you first have to go ahead and create an Event Grid topic. So you can create an EventGrid topic, click on Create. And then after you create the topic itself, your application can send the events on to this topic. And then you could have a subscriber such as an Azure function that could subscribe to the topic, right? So just some important points when it comes to the Event Grid service.

  1. AZ-203/ 204 – Lab – Azure Event Hub

Hi and welcome back. So let’s look at a lab on the Azure Event Hub. So before that, let’s have a quick introduction on the Azure Event Hub. So this is a big data streaming platform and event ingestion service. It can be used to receive and process millions of events per second. So you can use the Event Hub to store data for the following use cases. So for clickstream analysis. So let’s say you want to store the data for a site wherein you want to know which parts of the site users have clicked. So you want to analyze that click stream at a later point in time. So you can send all of the data onto the Event Hub. You can use it even for application logging, for creating Live Dashboards, and for telemetry processing. There’s some of the use cases which is also given in the Microsoft documentation.

Now again, giving a reference from the Microsoft documentation on the exact architecture of the Azure Event Hub. So on the left hand side you have your Event producer. So these are the devices or what are the producers sending the events onto your Event Hub? Now please know this is different from the Event Grid service. In the Event Grid Service, you have the resources in Azure sending events. And based on those events, it would trigger something. The event would be going on to an Azure function. That Azure function would do something with an event. These are based on triggers. Here we’re looking at event producers which actually send things like telemetry data, things like I said, quick stream analysis. So these are events which are happening in your application or happening on devices, and you send them all onto the Azure Event Hub.

These are a lot of events going into your Event Hub. So I said this Event Hub can actually process millions and millions of events. You then have the Azure event. Hub. So this is a resource that you create in Azure. It’s split into multiple partitions. You then have your event receivers. So you could have a program on the right hand side that’s actually consuming these events. You could then have your receivers receiving the events from a partition in the Azure Event Hub instance. So what are we going to see in our lab? So first we’re going to create an Event Hub namespace. We are going to create an Event Hub in the namespace, then use a dotnet program to send a message, and then use another program to receive the message. So let’s go ahead with our lab. So here we are now zero. So let’s go ahead and create a resource.

We can search for event hubs. Let’s choose that hit on Create. So let’s give a name for the namespace in the pricing tier, I’ll just choose the basic. This is enough for a demo. The resource group I’ll choose, I’ll choose the location as Central US. And then go ahead and hit on Create. Now once the event hub namespace is in place, you can go on to it. You can go on to event Hubs. You can create a new event Hub. Let’s go ahead and hit on Create, right? So now we have our Hub in place. Let’s go head on to our program and let’s look at the program for sending and receiving messages from the event hub. So here we are with our program. Now we’re going to have two programs. One is basic to send messages to the event hub and the other is to receive messages from the event hub. So now let’s look at the program which will be used to send a message to the event hub. So first you give the Hub name and then you give the connection string.

Again, to get the connection string, you can go on to your namespace, you can go on to Shared Access Policy and you can take the connection string from here. Once you have that in place, again, just looking at our NuGet solution. So in the NuGet packages, I install Windows Azure Service Bus so you can use the same packages to actually send messages onto the event hub. So going back to our program again, I’m creating a client of the event hub from the connection string. And then I’m going ahead and just creating simple messages. I’m using the send method to send event data, I’m encoding the message and then sending it to the event hub. How simple is that? Nothing complicated over here. Now we come to the program which is actually used to receive the messages.

Now, when you want to receive the messages, there is a special class that’s available in net so that’s known as the event processor. So if I go on to the event processor so there’s an interface known as I event processor. So this class is specially used for receiving messages from the event hub. Now, the advantage of using this class is that it understands how best to receive messages from your event Hub. It also uses a storage account in order to track the messages which have been received. So if you are looking at receiving messages from the event Hub, look at implementing the I even processor. Now, what I’ve done is that I’ve gone to the Microsoft documentation and I’ve gone ahead and taken the code that’s used to implement the I event processor.

So if you look at the main method which is there, so the process event sync, this is part of the event processor. Over here, we’re fetching the event data and again, for each event data, we’re using the encoding and then making sure that we send the message to the console. Now, if you go on to our main program so again, we have a Hub, we have the connection string for the Hub namespace, we also have a connection string for a storage account. So please make sure that you have a storage account also in place. So this can be a general purpose V two storage account, and it can be locally redundant storage. It can be of the hot access TL.

So once you have the storage account in place, again, take the connection string for the storage account. And then finally, we’re making sure that our event processor runs so that it will start getting messages from the event hub. So let’s go ahead, let’s run the program. So now I’m going to go ahead and run the program for setting messages to our event Hub. So it’s going ahead and sending the message onto event hub. If I go on to the program for receiving messages, let me go ahead and run that program. You can see now it’s going to start receiving the message. So it’s receiving the message messages has it’s being sent from the event hub, right? So this marks the end of this lab in which we have looked at how to use Azure Event Hubs.

  1. AZ-203/ 204 – Lab – Azure Notification Hub

Hi and welcome back. Now, in this lab, let’s look at the Azio Notification Hub. So what exactly is the Azio Notification hub? Well, this provides a platform to send notifications onto any platform iOS, Android, or Windows. Now, some use case scenarios. So let’s say you want to send promotional content to your users. You can actually use the Azure Notification Hub to send that content to users who have different devices. Or maybe you want to send codes for multifactor authentication. Or maybe you want to send news to millions of users with low latency. All of these are use cases for using the Azure Notification Hub. Now, in our lab, what we’re going to do is that we’re going to create a simple Windows universal app in Visual Studio.

We’ll create a notification namespace and hub. In Azure, we’ll create a new app in Windows Store. We’ll associate the Windows Studio project with our Windows Store. With the application we have in Visual Studio. We’ll use it to register our device that’s our workstation with Windows Store. And then you could also send a quick test message via the Windows Store itself from the Azure Portal. So let’s go ahead with our lab. So here we are in Azure. So let’s go ahead and first create a notification hub so we can choose Notification Hub. Click on create. Let’s give the Notification hub name and the namespace. So after giving the hub name and the namespace name, specifying the location. Let’s choose the resource group. So these are the pricing tiers that we have so we can choose the free one. Let’s hit on create. Now, in the meantime, we can go ahead and just create a new project in Visual Studio 2019.

So I’m going to choose a blank app for universal Windows. On Csharp, click on Next, give an app name and hit on Create. I’ll leave the target version and the minimum version has it is and click on OK. Now, in order to get that universal app in place in Visual, the template, if you go on to the Visual Studio installer, I’ve actually gone ahead and installed the universal Windows platform development. So I’ve ensured this is in place. Now, apart from that, you need to have access to the Windows Dev Center. Now, in order to actually have access to the store create an app, you have to do a registration. Now, currently I know that there is a fee for the registration. If you have a subscription, such as a Visual Studio subscription, it might give you free access to the Windows Store.

But what I’ve gone ahead is that I have gone ahead and paid $19, that’s 19 USD for an account. So let me go ahead and sign in with an account. Once I’ve signed in, I can go on to my dashboard here. I only have an app in place. If you only can go ahead and create a new app, you can give a name for the app, check the availability. If you say, you can go ahead and reserve the product name. Once you have the app in place, you can go on to your products, you can go on to Product Management, you can go on to WNS. So this is the Windows Push notification from Microsoft Azure mobile apps and the Microsoft Push notification. You can then go on to the Live Services site. So over here you get your application ID and you get an application secret. So once a notification hub is in place, you can go on to the hub itself.

You can go on to Windows WNS. Over here, you need to enter that application ID and take the application secret. So this allows the Notification hub to authorize itself to use that application which is present in your Windows tobe. So let’s go ahead and click on Save. Now, the next step is to go into Visual Studio. Let’s rightclick our project, let’s go on to Publish and let’s associate our app with the store. We’ll go on to next. So we’ll choose our Notify app. Go onto Next and go ahead and click on Associate. So this is done. Now let’s go ahead and add the following nugget package so Windows Azure Messaging Manage so let me go ahead and install this package. Now, once the packages are in place, you can go on to your app Xangl file if you scroll down. So I’ve entered the method which is also available in the Microsoft documentation.

So this allows the device on which this code is running on to register itself with the Notification hub. So here you specify what is the name of the hub and then we have the signature itself. So to get the signature, if you go on to Notify Hub, if you go on to Access Policies, you can take the default Listen shared Access signature from here. So copy this and then place it over here. And then you can go on top. Make sure that in the on launch method you are actually calling that notification a sync method. So let’s go ahead and run our application. So here the application has run. It has also successfully registered this device with the Notification Hub. So we can click on OK. And if you just want to send a test message, you can go on to Test Send, you can choose Windows, you can choose the notification type as a toast. So this is a message and then you can click on Send. You’ll then go ahead and send a test message, right? So this is just a quick lab on how you can actually use the Notification Hub.

  1. AZ-203/ 204 – Introduction to Azure Service Bus

Hi and welcome back. Now let’s have an introduction on to the Azio Service Bus service. So what is the exact definition of the service? Well, it’s quite a handful. It’s a fully managed enterprise integration message broker. So, just to explain the key concepts of this definition, let’s look at a use case scenario. Now, let’s say that you have an application that allows users to upload a set of videos. Let’s say that you have a module which is used for processing this set of videos. So your front end application would allow the users to upload the videos. And then you have a Processing module which will be used to process the videos. Now, without a messaging service in between, what you normally do is that the application would tell the processing module or maybe the processing module could pull the application for the videos that need to be processed.

But what happens if the application goes offline or the module goes offline? How does either one know what are the videos that still need to be processed or those videos which are already processed? So this is basically a tightly coupled application. It’s always a good design practice to decouple the components of an application. In such a case, you would always make use of a message broker. So in such a case, you would have a messaging service in between your processing module and your application. So whenever your application has a video that has been uploaded by a user, the application could then send a message to a message service. So this message is very small. All it could say is that what is the location of the video that needs to be processed? That’s it.

You then have the Processing module which can pull the messaging service, pull out the message from the messaging service. After opening the message, it would find the location of the video, process the video and then go ahead and delete the message. So in such a case, for each video you could have a message in the messaging service. So even if your application had to go down or the module had to go down, later on when the module is up and running, it could still go ahead process the messaging. It could still go ahead. So when the module comes back up, it could go head on to the messaging service, find the messages and then go ahead and process the remaining videos. So this is on an enterprise level and it’s used to integrate your application components.

Now, in Azure, this is also a fully managed service where the messaging service itself is a service managed service for you. So you don’t have to go ahead and install any messaging components. You can just go ahead and directly start using the service. Now, in the Azure Service Bus, you can create two types of messaging services. So one is a queue and the other is a topic. And we are going to be touching upon both of these in subsequent chapters. In this chapter, I just want to have an introduction on to the asia service pass service.