Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event...

107
1 @ChadGreen Getting Started with Azure Event Hubs Getting Started with Azure Event Hubs DevUp Chad Green October 16, 2019

Transcript of Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event...

Page 1: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

1@ChadGreen Getting Started with Azure Event Hubs

Getting Started with Azure Event HubsDevUp

Chad GreenOctober 16, 2019

Page 2: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

Silver Sponsors

Platinum Sponsors

Celebration Sponsor Lanyards Sponsor

Notebook Sponsor Registration Sponsor

Page 3: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

3@ChadGreen Getting Started with Azure Event Hubs

u)

2

#

[email protected]

Chad GreenDirector of Software DevelopmentScholarRx

chadwickegreenChadGreenChadGreen.com

Page 4: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

4@ChadGreen Getting Started with Azure Event Hubs

Introduction to Event HubsGetting Started with Azure Event Hubs

Page 5: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

5@ChadGreen Getting Started with Azure Event Hubs

Azure Event HubsSimple, secure, and scalable real-time data ingestion

Fully managed, real-time data ingestion service that is

simple, trusted, and scalable.

Page 6: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

6@ChadGreen Getting Started with Azure Event Hubs

Simple Secure

Scalable Open

Azure Event HubsSimple, secure, and scalable real-time data ingestion

Page 7: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

7@ChadGreen Getting Started with Azure Event Hubs

Azure Event Hubs

Key Architecture Components

Page 8: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

8@ChadGreen Getting Started with Azure Event Hubs

Event ProducersKey Architecture Components

Page 9: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

9@ChadGreen Getting Started with Azure Event Hubs

PartitionsKey Architecture Components

Page 10: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

10@ChadGreen Getting Started with Azure Event Hubs

PartitionsKey Architecture Components

Page 11: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

11@ChadGreen Getting Started with Azure Event Hubs

Consumer GroupsKey Architecture Components

Page 12: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

12@ChadGreen Getting Started with Azure Event Hubs

Throughput UnitsKey Architecture Components

Page 13: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

13@ChadGreen Getting Started with Azure Event Hubs

Event ReceiversKey Architecture Components

Page 14: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

14@ChadGreen Getting Started with Azure Event Hubs

Use CasesAzure Event Hubs

• Anomaly detection• Application logging• Analytics pipelines• Live dashboarding• Archiving data• Transaction processing• User telemetry processing• Device telemetry streaming

Page 15: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

15@ChadGreen Getting Started with Azure Event Hubs

DemosGetting Started with Azure Event Hubs

Page 16: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

16@ChadGreen Getting Started with Azure Event Hubs

Azure Event Hubs Demos

• Setup Azure Event Hubs• Send and Receive Events in .NET Core• Send Event from an Azure Function• Trigger Azure Function• Trigger Azure Logic App• Archive Events for Long-Time Storage• Real-Time Dashboard

Page 17: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

17@ChadGreen Getting Started with Azure Event Hubs

Setup Azure Event HubsGetting Started with Azure Event Hubs

Page 18: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

18@ChadGreen Getting Started with Azure Event Hubs

Setup Azure Event HubsAzure Event Hubs Demos

• Create an Event Hubs namespace• Create an event hub

Page 19: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

19@ChadGreen Getting Started with Azure Event Hubs

Send and Receive Events from an ApplicationGetting Started with Azure Event Hubs

Page 20: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

20@ChadGreen Getting Started with Azure Event Hubs

Send and receive events from an applicationAzure Event Hubs Demos

Available APIs• .NET Core• .NET Framework• Java• Python• Node.js• Go• C (send only)• Apache Storm (receive only)

Page 21: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

21@ChadGreen Getting Started with Azure Event Hubs

Send and receive events from an applicationAzure Event Hubs Demos

Page 22: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

22@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 23: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

23@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 24: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

24@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 25: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

25@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 26: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

26@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Microsoft.Azure.EventHubs

Page 27: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

27@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 28: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

28@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 29: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

29@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 30: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

30@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

using Microsoft.Azure.EventHubs;using System;using System.Text;using System.Threading.Tasks;

Page 31: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

31@ChadGreen Getting Started with Azure Event Hubs

public static async Task Main(string[] args){

}

Write code to send messages to Event HubSend Events from a .NET Core Application

Page 32: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

32@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString){EntityPath = EventHubName

};EventHubClient eventHubClient =

EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

Page 33: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

33@ChadGreen Getting Started with Azure Event Hubs

do{

Console.Clear();

do{

Console.WriteLine("How many messages do you want to send to the Event Hub?");input = Console.ReadLine();

} while (!int.TryParse(input, out numberOfMessagesToSend));

} while (numberOfMessagesToSend > 0);

Write code to send messages to Event HubSend Events from a .NET Core Application

Page 34: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

34@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

for (var i = 0; i < numberOfMessagesToSend; i++){try{

var message = $"Message {i}";Console.WriteLine($"Sending message: {message}");await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));

}catch (Exception exception){

Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");}

await Task.Delay(10);}

Page 35: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

35@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

Console.WriteLine($"{numberOfMessagesToSend} messages sent.");Console.WriteLine("Press any key to continue...");Console.ReadKey();

Page 36: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

36@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

await eventHubClient.CloseAsync();

Page 37: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

37@ChadGreen Getting Started with Azure Event Hubs

public class Program{

private const string EventHubConnectionString = "{Event Hubs connection string}";private const string EventHubName = "{Event Hub path/name}";

public static async Task Main(string[] args){

var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString){EntityPath = EventHubName

};EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

int numberOfMessagesToSend;string input;

do{

Console.Clear();

do{

Console.WriteLine("How many messages do you want to send to the Event Hub?");input = Console.ReadLine();

} while (!int.TryParse(input, out numberOfMessagesToSend));

for (var i = 0; i < numberOfMessagesToSend; i++){

try{var message = $"Message {i}";Console.WriteLine($"Sending message: {message}");await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));

}catch (Exception exception){Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");

}

await Task.Delay(10);}

Console.WriteLine($"{numberOfMessagesToSend} messages sent.");Console.WriteLine("Press any key to continue...");Console.ReadKey();

} while (numberOfMessagesToSend > 0);

await eventHubClient.CloseAsync();}

}

Page 38: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

38@ChadGreen Getting Started with Azure Event Hubs

Write code to send messages to Event HubSend Events from a .NET Core Application

private const string EventHubConnectionString = "{Connection String}";private const string EventHubName = "{Event Hub path/name}";

Page 39: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

39@ChadGreen Getting Started with Azure Event Hubs

Send and receive events from an applicationAzure Event Hubs Demos

Page 40: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

40@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 41: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

41@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 42: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

42@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 43: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

43@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 44: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

44@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Microsoft.Azure.EventHubs

Page 45: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

45@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 46: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

46@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 47: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

47@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 48: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

48@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Microsoft.Azure.EventHubs.Processor

Page 49: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

49@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 50: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

50@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 51: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

51@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 52: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

52@ChadGreen Getting Started with Azure Event Hubs

Initialize the .NET Core ApplicationSend Events from a .NET Core Application

Page 53: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

53@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

Page 54: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

54@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

SimpleEventProcessor.cs

Page 55: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

55@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Applicationpublic class SimpleEventProcessor : IEventProcessor{

public Task CloseAsync(PartitionContext context, CloseReason reason){

Console.WriteLine($"Processor Shutting Down. Partition '{context.PartitionId}', Reason: '{reason}'.");return Task.CompletedTask;

}

public Task OpenAsync(PartitionContext context){

Console.WriteLine($"SimpleEventProcessor initialized. Partition: '{context.PartitionId}’”);return Task.CompletedTask;

}

public Task ProcessErrorAsync(PartitionContext context, Exception error){

Console.WriteLine($"Error on Partition: {context.PartitionId}, Error: {error.Message}");return Task.CompletedTask;

}

public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages){

foreach (var eventData in messages){

var data = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);Console.WriteLine($"Message received. Partition: '{context.PartitionId}', Data: '{data}’”);

}return context.CheckpointAsync();

}}

Page 56: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

56@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

using Microsoft.Azure.EventHubs;using Microsoft.Azure.EventHubs.Processor;using System;using System.Threading.Tasks;

namespace ReceiveEvents{

class Program{

}}

Page 57: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

57@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

private const string EventHubConnectionString = "{Event Hubs connection string}";private const string EventHubName = "{Event Hub path/name}";private const string StorageContainerName = "{Storage account container name}";private const string StorageAccountName = "{Storage account name}";private const string StorageAccountKey = "{Storage account key}";private static readonly string StorageConnectionString

= string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",StorageAccountName,StorageAccountKey);

Page 58: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

58@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

static async Task Main(string[] args){

Console.WriteLine("Registering EventProcessor...");var eventProcessorHost = new EventProcessorHost(

EventHubName,PartitionReceiver.DefaultConsumerGroupName,EventHubConnectionString,StorageConnectionString,StorageContainerName);

// Registers the Event Processor Host and starts receiving messagesawait eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();

Console.WriteLine("Receiving. Press ENTER to stop worker.");Console.ReadLine();

// Disposes of the Event Processor Hostawait eventProcessorHost.UnregisterEventProcessorAsync();

}

Page 59: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

59@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

using Microsoft.Azure.EventHubs;using Microsoft.Azure.EventHubs.Processor;using System; using System.Threading.Tasks;

namespace ReceiveEvents{

class Program{

private const string EventHubConnectionString = "{Event Hubs connection string}";private const string EventHubName = "{Event Hub path/name}";private const string StorageContainerName = "{Storage account container name}";private const string StorageAccountName = "{Storage account name}";private const string StorageAccountKey = "{Storage account key}";private static readonly string StorageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, StorageAccountKey);

static async Task Main(string[] args){

Console.WriteLine("Registering EventProcessor...");var eventProcessorHost = new EventProcessorHost(

EventHubName,PartitionReceiver.DefaultConsumerGroupName,EventHubConnectionString,StorageConnectionString,StorageContainerName);

// Registers the Event Processor Host and starts receiving messagesawait eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();

Console.WriteLine("Receiving. Press ENTER to stop worker.");Console.ReadLine();

// Disposes of the Event Processor Hostawait eventProcessorHost.UnregisterEventProcessorAsync();

}

}}

Page 60: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

60@ChadGreen Getting Started with Azure Event Hubs

Write code to receive messages to Event HubSend Events from a .NET Core Application

private const string EventHubConnectionString = "{Event Hubs connection string}";

private const string EventHubName = "{Event Hub path/name}";

private const string StorageContainerName = "{Storage account container name}";

private const string StorageAccountName = "{Storage account name}";

private const string StorageAccountKey = "{Storage account key}";

Page 61: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

61@ChadGreen Getting Started with Azure Event Hubs

Send Events from Azure FunctionsGetting Started with Azure Event Hubs

Page 62: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

62@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 63: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

63@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 64: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

64@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Send Events

Page 65: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

65@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 66: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

66@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 67: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

67@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Microsoft.Azure.WebJobs.Extensions.EventHubs

Page 68: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

68@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 69: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

69@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 70: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

70@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 71: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

71@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppSend Events from an Azure Function

Page 72: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

72@ChadGreen Getting Started with Azure Event Hubs

Write Code for the Azure FunctionSend Events from an Azure Function

[FunctionName("SendEvent")]public static async Task<IActionResult> Run(

[HttpTrigger(AuthorizationLevel.Anonymous,"get", "post",Route = null)] HttpRequest req,

[EventHub("sendandreceive",Connection = "EventHubConnection")]IAsyncCollector<string> outputEvents,

ILogger log){

}

Page 73: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

73@ChadGreen Getting Started with Azure Event Hubs

Write Code for the Azure FunctionSend Events from an Azure Function

string message = req.Query["message"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();dynamic data = JsonConvert.DeserializeObject(requestBody);message = message ?? data?.name;

Page 74: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

74@ChadGreen Getting Started with Azure Event Hubs

Write Code for the Azure FunctionSend Events from an Azure Function

if (string.IsNullOrWhiteSpace(message)){log.LogInformation($"Sending the following message to the Event Hub: {message}");await outputEvents.AddAsync(message);

}

Page 75: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

75@ChadGreen Getting Started with Azure Event Hubs

Write Code for the Azure FunctionSend Events from an Azure Function

return message != null? (ActionResult)new OkObjectResult($"Sending the following message to the Event Hub: {message}"): new BadRequestObjectResult("Please pass a message on the query string or in the request body");

Page 76: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

76@ChadGreen Getting Started with Azure Event Hubs

Write Code for the Azure FunctionSend Events from an Azure Function

[FunctionName("SendEvent")]public static async Task<IActionResult> Run(

[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,[EventHub("sendandreceive", Connection = "EventHubConnection")]IAsyncCollector<string> outputEvents,ILogger log)

{string message = req.Query["message"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();dynamic data = JsonConvert.DeserializeObject(requestBody);message = message ?? data?.name;

if (string.IsNullOrWhiteSpace(message)){log.LogInformation($"Sending the following message to the Event Hub: {message}");await outputEvents.AddAsync(message);

}

return message != null? (ActionResult)new OkObjectResult($"Sending the following message to the Event Hub: {message}"): new BadRequestObjectResult("Please pass a message on the query string or in the request body");

}

Page 77: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

77@ChadGreen Getting Started with Azure Event Hubs

Trigger Azure Function from Event HubGetting Started with Azure Event Hubs

Page 78: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

78@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppTrigger Azure Function from Event Hub

Page 79: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

79@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppTrigger Azure Function from Event Hub

Page 80: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

80@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppTrigger Azure Function from Event Hub

Page 81: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

81@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppTrigger Azure Function from Event Hub

EventHubConnection

sendandreceive

Page 82: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

82@ChadGreen Getting Started with Azure Event Hubs

Create the Function AppTrigger Azure Function from Event Hub

Page 83: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

83@ChadGreen Getting Started with Azure Event Hubs

Write the Code for the Azure FunctionTrigger Azure Function from Event Hub[FunctionName("ReceiveEvents")]public static async Task Run(

[EventHubTrigger("sendandreceive", Connection = "EventHubConnection")] EventData[] events,ILogger log)

{

}

Page 84: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

84@ChadGreen Getting Started with Azure Event Hubs

Write the Code for the Azure FunctionTrigger Azure Function from Event Hub

var exceptions = new List<Exception>();

foreach (EventData eventData in events){

}

Page 85: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

85@ChadGreen Getting Started with Azure Event Hubs

Write the Code for the Azure FunctionTrigger Azure Function from Event Hub

try{string messageBody = Encoding.UTF8.GetString(eventData.Body.Array,

eventData.Body.Offset,eventData.Body.Count);

// Replace these two lines with your processing logic.log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");await Task.Yield();

}catch (Exception e){// We need to keep processing the rest of the batch - capture this exception and continue.// Also, consider capturing details of the message that failed processing so it can be// processed again later.exceptions.Add(e);

}

Page 86: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

86@ChadGreen Getting Started with Azure Event Hubs

Write the Code for the Azure FunctionTrigger Azure Function from Event Hub

// Once processing of the batch is complete, if any messages in the batch failed// processing throw an exception so that there is a record of the failure.

if (exceptions.Count > 1)throw new AggregateException(exceptions);

if (exceptions.Count == 1)throw exceptions.Single();

Page 87: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

87@ChadGreen Getting Started with Azure Event Hubs

Write the Code for the Azure FunctionTrigger Azure Function from Event Hub[FunctionName("ReceiveEvents")]public static async Task Run(

[EventHubTrigger("sendandreceive", Connection = "EventHubConnection")] EventData[] events,ILogger log)

{var exceptions = new List<Exception>();

foreach (EventData eventData in events){try{

string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);

// Replace these two lines with your processing logic.log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");await Task.Yield();

}catch (Exception e){

// We need to keep processing the rest of the batch - capture this exception and continue.// Also, consider capturing details of the message that failed processing so it can be processed again later.exceptions.Add(e);

}}

// Once processing of the batch is complete, if any messages in the batch failed// processing throw an exception so that there is a record of the failure.

if (exceptions.Count > 1)throw new AggregateException(exceptions);

if (exceptions.Count == 1)throw exceptions.Single();

}

Page 88: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

88@ChadGreen Getting Started with Azure Event Hubs

Run Multiple Azure Functions TogetherTrigger Azure Function from Event Hub

Page 89: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

89@ChadGreen Getting Started with Azure Event Hubs

Trigger Azure Logic App from Event HubGetting Started with Azure Event Hubs

Page 90: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

90@ChadGreen Getting Started with Azure Event Hubs

Real-Time DashboardGetting Started with Azure Event Hubs

Page 91: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

91@ChadGreen Getting Started with Azure Event Hubs

More DetailsReal-Time Dashboard

Page 92: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

92@ChadGreen Getting Started with Azure Event Hubs

Frequently Asked QuestionsGetting Started with Azure Event Hubs

Page 93: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

93@ChadGreen Getting Started with Azure Event Hubs

When do I create a new namespace vs using an existing namespace?Frequently Asked Questions

• Different Subscription• New Region• Distinct Capacity Allocation

Page 94: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

94@ChadGreen Getting Started with Azure Event Hubs

What is the difference between the Basic and Standard tiers?Frequently Asked Questions

• Longer event retention• Additional brokered connections• Multiple consumer groups• Capture• Kafka

Page 95: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

95@ChadGreen Getting Started with Azure Event Hubs

What is the maximum retention period for events?Frequently Asked Questions

• Basic Tier – 24 hours• Standard Tier – 7 days

Page 96: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

96@ChadGreen Getting Started with Azure Event Hubs

Do throughput units apply to all event hubs in a namespace?Frequently Asked Questions

• Ingress: 1-Mb or 1,000 events• Egress: 2-Mb or 4,096 events• Event Storage: 84-Gb

Page 97: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

97@ChadGreen Getting Started with Azure Event Hubs

How are throughput units billed?Frequently Asked Questions

• Hourly• Charged on highest value over hour

Page 98: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

98@ChadGreen Getting Started with Azure Event Hubs

How does the Auto-Inflate feature work?Frequently Asked Questions

• Scales up the throughput units• Cost effective• No additional cost• Does not scale down

Page 99: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

99@ChadGreen Getting Started with Azure Event Hubs

How are throughput limits enforced?Frequently Asked Questions

• Senders/Receivers receive errors• Ingress and Egress limits are separate

Page 100: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

100@ChadGreen Getting Started with Azure Event Hubs

Is there a limit on the number of throughput units that can be reserved/selected?Frequently Asked Questions

• 20-TUs within the portal

Page 101: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

101@ChadGreen Getting Started with Azure Event Hubs

Is there a limit on the number of throughput units that can be reserved/selected/Frequently Asked Questions

• 20-TUs within the portal• 40-TUs via support ticket

Page 102: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

102@ChadGreen Getting Started with Azure Event Hubs

Is there a limit on the number of throughput units that can be reserved/selected/Frequently Asked Questions

• 20-TUs within the portal• 40-TUs via support ticket• Need More? Event Hubs Cluster

Page 103: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

103@ChadGreen Getting Started with Azure Event Hubs

SummaryGetting Started with Azure Event Hubs

Page 104: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

104@ChadGreen Getting Started with Azure Event Hubs

Fully managed, real-time data ingestion service that is

simple, trusted, and scalable.

Azure Event HubsSummary

Simple Secure Scalable Open

Page 105: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

105@ChadGreen Getting Started with Azure Event Hubs

DemonstrationsSummary

• Setup Azure Event Hubs• Send and Receive Events in .NET Core• Send Event from an Azure Function• Trigger Azure Function• Trigger Azure Logic App• Real-Time Dashboard

Page 106: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

106@ChadGreen Getting Started with Azure Event Hubs

Frequently Asked QuestionsSummary

• Create a new namespace when needing a different region or distinct capacity allocation

• Standard tier gets you additional features including longer retention, multiple container groups, capture, and Kafka integration

• Maximum retention period is 24-hours/7-days• A throughput unit is capable of 1-Mb/1,000 events ingress and 2-Mb/4,096

egress events• Throughput units billed at highest rate per hour• Auto-inflate will scale up throughput units• Event Hubs throttles ingress and egress limits separately• You can have up to 20/40-TUs before going to Event Hub Clusters

Page 107: Getting Started with Azure Event Hubs · 2019-10-16 · @ChadGreen Getting Started with Azure Event Hubs 5 Azure Event Hubs Simple, secure, and scalable real-time data ingestion Fully

107@ChadGreen Getting Started with Azure Event Hubs

u)

2

#

[email protected]

Chad GreenDirector of Software DevelopmentScholarRx

chadwickegreenChadGreenChadGreen.com