Reader small image

You're reading from  Hands-On Azure for Developers

Product typeBook
Published inNov 2018
PublisherPackt
ISBN-139781789340624
Edition1st Edition
Tools
Right arrow
Author (1)
Kamil Mrzygłód
Kamil Mrzygłód
author image
Kamil Mrzygłód

Kamil Mrzygłód is a technical lead and technology advisor, working with multiple companies on designing and implementing Azure-based systems and platforms. He's a former Microsoft Azure Microsoft Most Valuable Professional (MVP) and certified trainer, who shares his knowledge via various channels, including conference speeches and open source projects and contributions. Kamil lives in Poland with his two cats and one dog, dedicating some of his time to video games, cooking, and traveling.
Read more about Kamil Mrzygłód

Right arrow

Reactive Architecture with Event Grid

Azure Event Grid is another cloud component that represents serverless services in Azure. It can be considered an events gateway, able to both make our solution work faster and to reverse control, so our services don't have to wait for others, burning available resources just to be idle. It's also a great routing tool, able to quickly distribute load and multiply it, allowing jobs to be finished faster.

The following topics will be covered in this chapter:

  • Azure Event Grid and reactive architecture
  • Connecting to other services through Azure Event Grid
  • Security features of Azure Event Grid
  • Publishing custom events to Azure Event Grid
  • Integrating Azure Functions with Azure Event Grid

Technical requirements

To perform exercises from this chapter you will need:

  • An Azure subscription
  • An IDE compatible with Visual Studio 2017

Azure Event Grid and reactive architecture

When working with multiple services in the cloud, you often need to have a centralized service responsible for routing events to a different endpoint. This makes the exchange of data a piece of cake—you do not have to maintain different URLs of APIs, as you can leverage a common event schema and custom routing configuration based on, for example, event type. In Azure, such a service is called Azure Event Grid—a serverless event gateway, which is one of the newer cloud components available. With a pay-as-you-go pricing model, you can quickly build a reactive architecture that inverts communication between your services and makes them passive. In this chapter, you will learn how to work with Event Grid and integrate it with other Azure components.

...

Connecting services through Azure Event Grid

Now that you know something about what Azure Event Grid is and how it works, we will try to test it and create a working solution. We will start by creating an instance in Azure Portal and configuring it to accept and route events. You will see also what the schema of an event is and how to leverage it so you can send custom events that will be handled by Event Grid.

Creating Azure Event Grid in Azure Portal

To get started with Azure Event Grid, do the following in Azure Portal:

  1. Click on + Create a resource and search for Event Grid. From the list, select Event Grid Topic and click Create.
  2. You will see a really simple form, where you have to enter the name of an instance of a service...

Publishing custom events to Azure Event Grid

So far, we have talked about integrating Azure Event Grid with already built-in publishers and topics, using Resource Group as an example. I mentioned at the beginning of this chapter that this service is capable of handling custom topics, making it a really flexible solution that can act as an event gateway. In this section, we will cover this topic and try to use Event Grid as our router for handling and maintaining the routing of our events.

Event gateway concept

Let's look at the following diagram:

Here, you have a single events producer and four different handlers. Now, if you imagine that Publisher publishes only custom events, you can see that Event Grid is able to...

Integrating Azure Functions with Azure Event Grid

The last thing that we'll cover for Azure Event Grid is integration with Azure Functions. As mentioned earlier, if you use Event Grid to publish events to Azure Functions triggered by an HTTP trigger, you will have to validate an endpoint. This is not the best solution, but fortunately, it is possible to use EventGridTrigger, which allows us to skip the endpoint validation step when configuring services. This topic itself is quite big, so we will not cover each and every problem possible; however, I will point you to the specific parts of the documentation, which will help you understand the topic even better.

EventGridTrigger in Azure Functions

In general, the easiest...

Summary

In this chapter, you learned what reactive architecture is and how to use it with Azure Event Grid. You integrated different event producers with event handlers, and used custom topics to publish custom events. What is more, you now have the knowledge of how to integrate Azure Event Grid with Azure Functions and test it locally.

This chapter ends the second part of the book, which has been on serverless services and architectures. In the next part, we will cover different storage options and messaging and monitoring services, which will broaden your proficiency with Azure even more.

Questions

  1. What are the supported event schemas in Azure Event Grid?
  2. How can you authorize a request to an Event Grid endpoint when posting a custom event?
  3. What has to be returned when validating an endpoint?
  4. When will an endpoint not have to be validated?
  5. What happens if an endpoint doesn't return a success response?
  6. How can you filter events in Azure Event Grid?
  7. How can you test Event Grid integration with Azure Functions?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Azure for Developers
Published in: Nov 2018Publisher: PacktISBN-13: 9781789340624
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime

Author (1)

author image
Kamil Mrzygłód

Kamil Mrzygłód is a technical lead and technology advisor, working with multiple companies on designing and implementing Azure-based systems and platforms. He's a former Microsoft Azure Microsoft Most Valuable Professional (MVP) and certified trainer, who shares his knowledge via various channels, including conference speeches and open source projects and contributions. Kamil lives in Poland with his two cats and one dog, dedicating some of his time to video games, cooking, and traveling.
Read more about Kamil Mrzygłód