13  Week 12 (18-Dec-2025)


13.1 Use Azure Cli to manage Azure Resources

13.1.1 Download Azure Cli

  • Access the following site to download the tool for your operating system and install it.

13.1.2 Run the Azure client

  • Check the client version
az version
  • If you have already, just upgrade to the latest version.
az upgrade

13.1.3 Download this exercise files

  • Download the files needed to run this exercise from here.
  • Expand the zip file.
  • Move into the directory created by expanding the zip file.

13.1.4 Login to Azure

  • Make sure you are able to login to Azure.
  • Enter your username and password in the browser and return to the command line.
az login

13.1.5 Create a Resource Group

  • You need to create a resource group (in this example named ul-eventhubs-rg) in a specific location to contain your hardware/software resources.
  • If you don’t know the possible locations execute: az account list-locations -o tableand then pick the name you want.
az group create --name ul-eventhubs-rg --location westeurope # In this example we are using  westeurope
Figura 13.1: Azure Portal - After Creating the Resource Group

13.1.6 Deploy and instantiate an Event Hub

  • Define the name of your template (downloaded file event-hub-template.json) file in a variable. In this case, templateFile.
  • In the same directory, run the following command, taking into account that the resource group name must be the one (ul-eventhubs-rg) that you created in the previous step.
  • Answer the question for the project name (ex: arit-eventhub1), and check in the Azure Portal within the resource groups the result of this command.
  • The execution of the command may take some minutes.
templateFile="event-hub-template.json"
az deployment group create --name ul-eventhub-template --resource-group ul-eventhubs-rg --template-file $templateFile

# As an alternative, you can also run the above command without defining a variable like this:
az deployment group create --name ul-eventhub-template --resource-group ul-eventhubs-rg --template-file event-hub-template.json

Azure Portal - After Creating the Event Hub

Azure Portal - After Creating the Event Hub

13.2 Generating Data for the Azure Event Hub

13.2.1 Download and Install NodeJS

  • Download NodeJS for your OS here.
  • Install NodeJS.
  • After installation, test it with this command.
node -v
  • Positioned in the directory containing the files for this exercise, run the following command.
# On Windows
npm install

# If your are on Linux run
sudo npm install

13.2.2 Configure a connection string

  • To send/receive events to/from the Azure Event Hub you need to get a connection string from the Azure Portal.
  • In the Azure Portal, within the resource group and event hub namespace section, expand Settings and then Shared access policies.
  • Drill down in RootManagedSharedAccessKey and copy the value of Connection string-primary key variable.
Figura 13.2: Azure Portal - Getting the Event Hub Connection String
Figura 13.3: Azure Portal - Getting the Event Hub Connection String
Figura 13.4: Azure Portal - Getting the Event Hub Connection String
  • Replace the connection string in the files send-azure.js and receive-azure.js. In variable connectionString put the value copied from the Portal in Connection string-primary key. Variable eventHubName should have the value you enter when running the template, which is the name of your Event hub.
Figura 13.5: Azure Portal - Getting the Event Hub Connection String

13.2.3 Send Events to Azure

  • To send events (random data and random intervals) to Azure event Hub run the following.
node send-azure.js
  • Check the results in the Azure Portal.
Figura 13.6: Azure Portal - Getting the Event Hub Connection String

13.2.4 Receive Events from Azure

  • To receive the same events from the Azure Event Hub run the following.
node receive-azure.js

13.3 Removing Resources

  • If you want to delete everything, delete your resource group. Everything within will be removed. Use the following command.
az group delete --name ul-eventhubs-rg --yes