0

When using the Azure Event Hubs output binding for Azure Functions, is it possible to specify a partition key?

I have code similar to the below, but I don't see any way to specify a partition key prior to send.

Alternatively, is there any way I could use the Function parameters to bind an EventHubProducerClient, with an identity-based connection? This would be useful as the client allows for multiple ways to specify a partitionId.

I'm aware that it's possible to wire up dependency injection, and to use that to get the client, but I was curious if I could avoid that.

[FunctionName("EventHubOutput")]
[return: EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")]
public static string Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    return $"{DateTime.Now}";
}
derekbaker783
  • 8,109
  • 4
  • 36
  • 50
  • I guess a valid question would be why would you want to specify the partition? – Matt Douhan Sep 02 '22 at 08:25
  • @MattDouhan "For example, you may want your back-end system to process an update command before a delete command. In this scenario, a client application sends events to a specific partition so that the ordering is preserved. When a consumer application consumes these events from the partition, they are read in order." [The Docs](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-availability-and-consistency?tabs=dotnet#consistency) – derekbaker783 Sep 02 '22 at 11:32
  • It might be possible that there's some setting that could be manipulated at startup, but I haven't checked: https://stackoverflow.com/questions/40274359/offset-in-azure-eventhubtrigger-function-app – derekbaker783 Sep 02 '22 at 14:34
  • 1
    DO not think this can be done without DI since you cannot control many client options – Matt Douhan Sep 12 '22 at 12:43

0 Answers0