Microsoft.Azure.WebJobs.Extensions.EventHubs 6.3.5
Prefix ReservedSee the version list below for details.
dotnet add package Microsoft.Azure.WebJobs.Extensions.EventHubs --version 6.3.5
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.EventHubs -Version 6.3.5
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="6.3.5" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="6.3.5" />Directory.Packages.props
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" />Project file
paket add Microsoft.Azure.WebJobs.Extensions.EventHubs --version 6.3.5
#r "nuget: Microsoft.Azure.WebJobs.Extensions.EventHubs, 6.3.5"
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.EventHubs&version=6.3.5Install as a Cake Addin
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.EventHubs&version=6.3.5Install as a Cake Tool
Azure WebJobs Event Hubs client library for .NET
This extension provides functionality for accessing Azure Event Hubs from an Azure Function.
Getting started
Install the package
Install the Event Hubs extension withNuGet:
dotnet add package Microsoft.Azure.WebJobs.Extensions.EventHubs
Prerequisites
Azure Subscription: To use Azure services, including Azure Event Hubs, you'll need a subscription. If you do not have an existing Azure account, you may sign up for afree trial or use yourVisual Studio Subscription benefits when youcreate an account.
Event Hubs namespace with an Event Hub: To interact with Azure Event Hubs, you'll also need to have a namespace and Event Hub available. If you are not familiar with creating Azure resources, you may wish to follow the step-by-step guide forcreating an Event Hub using the Azure portal. There, you can also find detailed instructions for using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM) templates to create an Event Hub.
Azure Storage account with blob storage: To persist checkpoints as blobs in Azure Storage, you'll need to have an Azure Storage account with blobs available. If you are not familiar with Azure Storage accounts, you may wish to follow the step-by-step guide forcreating a storage account using the Azure portal. There, you can also find detailed instructions for using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM) templates to create storage accounts.
Authenticate the Client
For the Event Hubs client library to interact with an Event Hub, it will need to understand how to connect and authorize with it. The easiest means for doing so is to use a connection string, which is created automatically when creating an Event Hubs namespace. If you aren't familiar with using connection strings with Event Hubs, you may wish to follow the step-by-step guide toget an Event Hubs connection string.
TheConnection
property ofEventHubAttribute
andEventHubTriggerAttribute
is used to specify the configuration property that stores the connection string.
TheAzureWebJobsStorage
connection string is used to preserve the processing checkpoint information.
For the local development use thelocal.settings.json
file to store the connection string:
{ "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "<connection_name>": "Endpoint=sb://<event_hubs_namespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Jya7Eh76HU92ibsxuk1ITN8CM8Bt76YLKf5ISjU3jZ8=" }}
When deployed use theapplication settings to set the connection string.
Identity-based authentication
If your environment hasmanaged identity enabled you can use it to authenticate the Event Hubs extension. Before doing so, you will need to ensure that permissions have been configured as described in theAzure Functions developer guide.
To use identity-based authentication provide the<connection_name>__fullyQualifiedNamespace
configuration setting.
{ "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "<connection_name>__fullyQualifiedNamespace": "{event_hubs_namespace}.servicebus.windows.net" }}
Or in the case of deployed app set the same setting inapplication settings:
<connection_name>__fullyQualifiedNamespace={event_hubs_namespace}.servicebus.windows.net
More details about configuring an identity-based connection can be foundhere.
Key concepts
Event Hub Trigger
The Event Hub Trigger allows a function to be executed when a message is sent to an Event Hub.
Please follow theAzure Event Hubs trigger tutorial to learn more about Event Hub triggers.
Event Hub Output Binding
The Event Hub Output Binding allows a function to send Event Hub events.
Please follow theAzure Event Hubs output binding to learn more about Event Hub bindings.
Supported types
The following types are supported for trigger and output bindings:
EventData
string
- value would be encoded using UTF8 encodingBinaryData
byte[]
- Custom model types will be JSON-serialized using Newtonsoft.Json
IAsyncCollector<T>
of any of the above types for batch triggersEventHubProducerClient
for output bindings
Examples
Sending individual event
You can send individual events to an Event Hub by applying theEventHubAttribute
the function return value. The return value can be ofstring
orEventData
type. A partition keys may not be specified when using a return value; to do so, you'll need to bind to theIAsyncCollector<EventData>
, as shown inSending multiple events.
[FunctionName("BindingToReturnValue")][return: EventHub("<event_hub_name>", Connection = "<connection_name>")]public static string Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer){ // This value would get stored in EventHub event body. // The string would be UTF8 encoded return $"C# Timer trigger function executed at: {DateTime.Now}";}
Sending multiple events
To send multiple events from a single Azure Function invocation you can apply theEventHubAttribute
to theIAsyncCollector<string>
orIAsyncCollector<EventData>
parameter. Partition keys may only be used when binding toIAsyncCollector<EventData>
.
[FunctionName("BindingToCollector")]public static async Task Run( [TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, [EventHub("<event_hub_name>", Connection = "<connection_name>")] IAsyncCollector<EventData> collector){ // When no partition key is used, partitions will be assigned per-batch via round-robin. await collector.AddAsync(new EventData($"Event 1 added at: {DateTime.Now}")); await collector.AddAsync(new EventData($"Event 2 added at: {DateTime.Now}")); // Using a partition key will help group events together; events with the same key // will always be assigned to the same partition. await collector.AddAsync(new EventData($"Event 3 added at: {DateTime.Now}"), "sample-key"); await collector.AddAsync(new EventData($"Event 4 added at: {DateTime.Now}"), "sample-key");}
Using binding to strongly-typed models
To use strongly-typed model classes with the EventHub binding apply theEventHubAttribute
to the model parameter.
[FunctionName("TriggerSingleModel")]public static void Run( [EventHubTrigger("<event_hub_name>", Connection = "<connection_name>")] Dog dog, ILogger logger){ logger.LogInformation($"Who's a good dog? {dog.Name} is!");}
Sending multiple events using EventHubProducerClient
You can also bind to theEventHubProducerClient
directly to have the most control over the event sending.
[FunctionName("BindingToProducerClient")]public static async Task Run( [TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, [EventHub("<event_hub_name>", Connection = "<connection_name>")] EventHubProducerClient eventHubProducerClient){ // IAsyncCollector allows sending multiple events in a single function invocation await eventHubProducerClient.SendAsync(new[] { new EventData($"Event 1 added at: {DateTime.Now}"), new EventData($"Event 2 added at: {DateTime.Now}") });}
Per-event triggers
To run a function every time an event is sent to Event Hub apply theEventHubTriggerAttribute
to astring
orEventData
parameter.
[FunctionName("TriggerSingle")]public static void Run( [EventHubTrigger("<event_hub_name>", Connection = "<connection_name>")] string eventBodyAsString, ILogger logger){ logger.LogInformation($"C# function triggered to process a message: {eventBodyAsString}");}
Batch triggers
To run a function for a batch of received events apply theEventHubTriggerAttribute
to astring[]
orEventData[]
parameter.
[FunctionName("TriggerBatch")]public static void Run( [EventHubTrigger("<event_hub_name>", Connection = "<connection_name>")] EventData[] events, ILogger logger){ foreach (var e in events) { logger.LogInformation($"C# function triggered to process a message: {e.EventBody}"); logger.LogInformation($"EnqueuedTime={e.EnqueuedTime}"); }}
Troubleshooting
Please refer toMonitor Azure Functions for troubleshooting guidance.
Next steps
Read theintroduction to Azure Functions orcreating an Azure Function guide.
Contributing
See ourCONTRIBUTING.md for details on building,testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions requireyou to agree to a Contributor License Agreement (CLA) declaring that you havethe right to, and actually do, grant us the rights to use your contribution. Fordetails, visitcla.microsoft.com.
This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQor contactopencode@microsoft.com with anyadditional questions or comments.
Product | VersionsCompatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
.NETStandard 2.0
- Azure.Messaging.EventHubs(>= 5.11.5)
- Azure.Storage.Blobs(>= 12.21.1)
- Microsoft.Azure.WebJobs(>= 3.0.37)
- Microsoft.Extensions.Azure(>= 1.7.4)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Microsoft.Azure.WebJobs.Extensions.EventHubs:
Package | Downloads |
---|---|
MassTransit.WebJobs.EventHubs MassTransit Azure WebJobs Event Hubs support; MassTransit provides a developer-focused, modern platform for creating distributed applications without complexity. | |
Microsoft.Azure.Workflows.WebJobs.Extension Extensions for running workflows in Azure Functions | |
RedQuick Package Description | |
Amido.Stacks.Messaging.Azure.EventHub Package Description | |
Beef.Events.EventHubs Business Entity Execution Framework (Beef) Event Hubs framework. |
GitHub repositories (11)
Showing the top 11 popular GitHub repositories that depend on Microsoft.Azure.WebJobs.Extensions.EventHubs:
Repository | Stars |
---|---|
MassTransit/MassTransit Distributed Application Framework for .NET | |
Azure/azure-webjobs-sdk Azure WebJobs SDK | |
Azure-Samples/saga-orchestration-serverless An orchestration-based saga implementation reference in a serverless architecture | |
JamesRandall/FunctionMonkey Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com | |
ProfessionalCSharp/MoreSamples Additional code samples the book series Professional C#, Wrox Press | |
Azure-Samples/streaming-at-scale How to implement a streaming at scale solution in Azure | |
microsoft/durabletask-netherite A new engine for Durable Functions. https://microsoft.github.io/durabletask-netherite | |
solliancenet/tech-immersion-data-ai | |
Daniel-Krzyczkowski/MicrosoftAzure Microsoft Azure code samples. | |
Azure-Samples/azure-digital-twins-unreal-integration Sample project demonstrating the Unreal Engine plug-in for Azure Digital Twins | |
Azure-Samples/azure-sql-db-change-stream-debezium SQL Server Change Stream sample using Debezium |
Version | Downloads | Last Updated |
---|---|---|
6.5.2 | 11,324 | 6/17/2025 |
6.5.1 | 50,456 | 4/9/2025 |
6.5.0 | 1,108 | 4/8/2025 |
6.4.0-beta.1 | 490 | 3/14/2025 |
6.3.5 | 1,018,143 | 8/2/2024 |
6.3.4 | 7,849 | 7/25/2024 |
6.3.3 | 106,180 | 6/13/2024 |
6.3.2 | 348,913 | 4/29/2024 |
6.3.1 | 84,441 | 4/17/2024 |
6.3.0 | 15,129 | 4/10/2024 |
6.2.0 | 297,354 | 3/5/2024 |
6.1.0 | 35,582 | 2/14/2024 |
6.0.2 | 402,898 | 11/13/2023 |
6.0.1 | 326,662 | 10/11/2023 |
6.0.0 | 80,667 | 9/12/2023 |
5.5.0 | 287,747 | 8/14/2023 |
5.4.0 | 481,344 | 6/6/2023 |
5.3.0 | 333,148 | 4/11/2023 |
5.2.0 | 188,144 | 2/23/2023 |
5.1.2 | 1,088,418 | 8/10/2022 |
5.1.1 | 886,903 | 6/21/2022 |
5.1.0 | 459,184 | 4/21/2022 |
5.0.1 | 231,645 | 3/9/2022 |
5.0.0 | 820,494 | 10/26/2021 |
5.0.0-beta.7 | 69,622 | 7/9/2021 |
5.0.0-beta.6 | 44,819 | 6/9/2021 |
5.0.0-beta.5 | 19,594 | 5/18/2021 |
5.0.0-beta.4 | 17,775 | 4/6/2021 |
5.0.0-beta.3 | 17,580 | 3/11/2021 |
5.0.0-beta.2 | 18,639 | 3/9/2021 |
5.0.0-beta.1 | 22,524 | 2/10/2021 |
4.3.1 | 409,179 | 2/15/2022 |
4.3.0 | 578,232 | 10/26/2021 |
4.2.0 | 889,064 | 12/11/2020 |
4.1.1 | 1,401,393 | 2/5/2020 |
4.1.0 | 185,105 | 10/31/2019 |
4.0.1 | 437,392 | 10/1/2019 |
4.0.0 | 144,799 | 9/19/2019 |
4.0.0-beta2 | 1,085 | 8/5/2019 |
4.0.0-beta1 | 12,247 | 5/14/2019 |
3.0.6 | 308,446 | 7/23/2019 |
3.0.5 | 230,321 | 5/3/2019 |
3.0.4 | 69,277 | 3/29/2019 |
3.0.3 | 254,299 | 3/7/2019 |
3.0.2 | 50,450 | 1/25/2019 |
3.0.1 | 127,399 | 10/17/2018 |
3.0.0 | 141,834 | 9/19/2018 |
3.0.0-rc1 | 3,082 | 9/14/2018 |
3.0.0-beta8 | 8,791 | 8/30/2018 |
3.0.0-beta5 | 15,417 | 3/26/2018 |
3.0.0-beta4 | 5,518 | 11/28/2017 |
3.0.0-beta3 | 1,690 | 9/15/2017 |
- Last updated8/2/2024
- Project website
- Source repository
- MIT license
- Download package (107.98 KB)
- Open in NuGet Package Explorer
Open in NuGet Trends
- Report package
© Microsoft Corporation. All rights reserved.