This repository contains supplemental material to compliment my Pluralsight course Getting Started with Azure Event Hubs with C#. This includes a custom C# library, designed to interface with Event Hubs, a series of Unit Tests, and a sample Console Application.
var eventHubConnectionString =
ConfigurationManager.AppSettings["EventHubConnectionString"];
EventHubToolbox.Instance.Connect(eventHubConnectionString);
if (EventHubToolbox.Instance.IsConnected)
{
Console.WriteLine(@"Connected OK!");
}
await EventHubToolbox.Instance.SendAsync("TEST");
var eventReceiver = new EventReceiver(TimeSpan.FromMinutes(5));
eventReceiver.Notification += EventReceiver_Notification;
eventReceiver.EventReceived += EventReceiverEventReceived;
var eventProcessorOptions = new EventProcessorOptions();
eventProcessorOptions.ExceptionReceived += EventProcessorOptions_ExceptionReceived;
await EventHubToolbox.Instance.SubscribeAsync(
"MyEventHost",
eventHubConnectionStringShort,
eventHubName,
storageAccountName,
storageAccountKey,
eventReceiver,
EventHubToolbox.UnRegisterAsync,
EventHubToolbox.RegisterAsync,
false,
eventProcessorOptions);
if (EventHubToolbox.Instance.IsSubscribedToAny)
{
Console.WriteLine(@"Subscribed!");
}
private static void EventReceiver_Notification(object sender,
EventReceiverEventArgs e)
{
Console.WriteLine(@"Notification received: {0}", e.Message);
}
private static void EventReceiverEventReceived(object sender,
EventReceiverEventArgs e)
{
Console.WriteLine(@"Event received: {0}", e.Message);
}
private static void EventProcessorOptions_ExceptionReceived(
object sender,
ExceptionReceivedEventArgs e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Exception.Message);
Console.ForegroundColor = ConsoleColor.Green;
}
await EventHubToolbox.Instance.UnsubscribeAllAsync(EventHubToolbox.UnRegisterAsync);
Please reach out and contact me for questions, suggestions, or to just talk tech in general.