I love Visual Studio Code and all the extensions that are available. It has become my preferred editor for almost everything (replacing Notepad++), except for when developing in Visual Studio.

Recently there is a new extension that was made available for working with Azure Event Grid. Typically when working with Azure Event Grid I use a tool called Postman to send test messages to my Azure Event Grid resource. But now with this latest extension you can use Visual Studio Code.

In this post I’ll walk through how to get started and use the Azure Event Grid extension for Visual Studio Code. Let’s get started.

Prerequisites

Before we can begin we need to make sure we have the following installed and setup:

  1. An Azure Subscription. If you don’t have an Azure Account, you can sign up for one today for free and receive $200 in credits by selecting "Create a Free Azure Account…" or selecting "View->Command Palette" and searching for "Azure: Create an Account"
  2. Install Visual Studio Code
  3. Visual Studio Code Extensions:
    • Install extension Azure Tools for Visual Studio Code
    • Install extension Azure Event Grid

Connecting to your Azure Subscription

First thing we need to do is connect to your Azure subscription. This will happen automatically when you go to the Azure tab in Visual Studio Code. You can also sign in from the Command palette and searching for “Azure: Login”.

image

image

image

Create an Event Grid Topic

Now that you’re signed in, let’s go ahead and create an Event Grid topic.

1. In the Event Grid Topics pane, click on the + button to create a new topic:

image

2. Then select your Azure Subscription to associate this topic with:

image

3. Now provide a topic name. I will use “VSCodeEventGridTopicDemo” for my demo:

image

4. Next select a resource group for your topic. I will use  “RGVSCodeEventGridDemo” for my demo:

image

5. Select your location for the resources:

sshot-636

6. Done. In a few seconds your Azure Event Grid will be created and displayed in Visual Studio Code:

image

image

You can login to your Azure Subscription and see everything we just created. Keep your Azure Subscription loaded in the browser as we’ll use it for the next section.

image

Create Event Grid Subscription

Now that we have an Event Grid Topic setup we need to create a subscription to receive the events we send it.

1. Here I will create a new Azure Function app:

image

2. Now create a new Event Grid Trigger function and after it’s created click on the Add Event Grid subscription link:

image

3. Fill in the details relating to the Azure Event Grid Topic we created earlier and then press the Create button:

image

Your Event Grid Topic now has an Event Grid Subscription and is ready to test!

Generating Mock Events

Apart from managing your Event Grids resources in Visual Studio Code, you can also generate and send mock events which is great for testing purposes. Instead of using Postman to do this, I find the Event Grid Extension better and mocking and sending events. So let’s get started now mocking some events.

1. To generate a mocked event, right click on your Event Grid Subscription in Visual Studio Code and select Create Mock Event Generator:

image

2. A new file will be created with all the details for generating mocked events for this subscription. The pattern property is defined with regex patterns for generating random data. You will noticed I changed the data section pattern value with regex pattern to generate the mocked data for my event:

image

3. At the top of the event generator file will be two links: Send Events and Preview Events. The actions do exactly as they say and are what you want to use when generating your mocked events.

image

4. If we click on Preview Events, another file is created with a preview of mocked event data to be sent. Notice the different values between the events. This is from the regex logic defined in the event generator. This can be customized to generate data appropriate for your needs.

image

5. Now click on Send Events link at the top of the event generator file and go to your Azure Portal where you previously defined your Azure Function for your Event Grid Topic, and you will see in the logs your mocked events:

sshot-647

As you can see the Azure Event Grid extension for Visual Studio Code is very powerful and is a handy tool to use in your Azure development.

Enjoy!

Reference

Create your free Azure account

Azure Event Grid Overview

Azure Event Grid Documentation

Introduction to Azure serverless with Azure Functions, Logic Apps and Azure Event Grid

Posted by Callon Campbell [MVP]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s