Understanding Event Grids & Event Viewer in Azure

Title: Understanding Event Grids & Event Viewer in Azure

Introduction: All my articles are compiled into simple steps with detailed screen shots and elaborative description. By following these steps even, a novice programmer should be able to replicate scenario. Please go through the steps and provide your valuable feedback to make my next articles more clearer and intent.

Note: I took help of various internet sources while researching this item. Credit goes to internet and Microsoft communities. This is one of the topics in Azure certification.

This is my third article on Azure. Please follow below links for my previous Azure articles

Azure WebApps

Azure Logic App

Follow below mentioned 16 steps to publish & subscribe events to event grids in azure.

What is Event Grid in Azure? – Azure Event Grids allow us to build applications with event driven architecture. Applications which need to update data on timely manner needs this kind of architecture. Examples are share market site – need to update data accurately when there is a change in server. When there is a change, server will notify all the users with updated data. And applications will receive that data and display on screen with out any user action. This is also called as Pub/sub event.

After completing this blog, you will be able to do

  • You will understand the concept of Event Grid Topic
  • How to bind Event Grid Topic with web apps
  • Dot net code to submit messages to event grid topic

Step 1: Open Azure portal (https://portal.azure.com)

Step 2: Create a new resource group by clicking on Resource Groups icon on home page.

What is Resource Group? – Resource group is a container which holds all resources for an azure application. It’s a kind of grouping and managing resources.

Give a unique group name and use the region whichever is near to you.

Step 3: Create a new Event grid topic. Click on Create Resource> Search with Event Grid Topic and Click on Create.

Step 4: In next tab select Event Grid Schema for Event Schema parameter.

Event Schema has 3 possible options. Internal mechanism is in json format.

Event grid schema – Microsoft provided

Cloud event schema – Open source

Custom schema – You can define your own schema.

Step 5: Create a new web application in Azure.

This time I choose docker container/linux to deploy my application.

Step 6: Select web application created in previous step. Go to the settings and properties pane. Copy the value from URL box. This value we will use in later steps.

Step 7: Launch the URL copied in previous step and observe interface. This application is going to be the listener which subscribes the event we created previously.

Step 8: Now its time to subscribe the event with the application we created. Select the Event Grid Topic we created in step 3. And click on New Event Subscription. While creating the event subscription select Endtype as web hook. That means we are subscribing the event by using web hook.

Prefix https and suffix /api/updates to the url we copied in previous steps. Add this value to the Endpoint while creating the subscription.

Step 9: See the JSON view for the event we created and review the json data.

Step 10: Now we need to collect some data from the event grid. Select the event grid and copy the Topic Endpoint value, we will use this later in code. After that go to the Settings> Access Keys and copy value from Key 1

Step 11: Now we need to work on data net code part. Create a new dot net core application.

In program.cs create 2 parameters and assign the values we copied from topic end point and access key in previous step.

Step 12: Add below code which connects to the event grid we created and adds events to it.

Step 13: To simplify the things, I added simple code. If you want, you can create an interactive application which takes input from user and submit that data to event grid.

Step 14: Now build application and deploy. As shown below

Step 15: Now you deploy the application. After deployment a message will be written to event grid and that will be displayed in the web application we created. Please open the web application we created earlier.

Step 16: Now your web application is updated with the messages we submitted to event grid. There is no user intervention required to see the updated data.

Please feel free to define your own dot net code to make it more interactive.

Happy Coding!!!