Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
737 stars 358 forks source link

EventHubTriggerBindingStrategy Throws when partitionkey is not set. #1625

Open TWith2Sugars opened 6 years ago

TWith2Sugars commented 6 years ago

When binding to an evenhub that contains events that where sent without a partitionkey set this package is unable to bind and instead throws an exception.

It looks like in the EventHubTriggerBindingStrategy when trying to get the partition key is where this exception happens.

Repro steps

Provide the steps required to reproduce the problem

  1. Use Microsoft.Azure.WebJobs.Extensions.EventHubs (3.0.0-beta4) package
  2. Binding to an eventhub
  3. Send event to that eventhub with out setting the partition key

Expected behavior

Not throw an exception and bind the event data.

Actual behavior

Throws an exception

Known workarounds

Use Microsoft.Azure.EventHubs.Processor directly and bypass the webjobs package

Related information

function I used:

let storeEvents ([<EventHubTrigger("someeventhub" ConsumerGroup="testevents")>] events:EventData [],partitionContext:PartitionContext) = async { printfn "%A" events.Length } |> Async.StartAsTask :> Task

Stack trace snippet:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: ProfileEventStorage.storeEvents ---> System.AggregateException : One or more errors occurred. (Exception binding parameter 'data') (Exception binding parameter 'partitionContext') ---> Exception binding parameter 'data' ---> System property 'x-opt-partition-key' is missing in the event. at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw() at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DelayedException.cs : 27 at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 511 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 477 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 264 ---> (Inner Exception #0) System.InvalidOperationException : Exception binding parameter 'data' ---> System.ArgumentException : System property 'x-opt-partition-key' is missing in the event. at Microsoft.Azure.EventHubs.EventData.SystemPropertiesCollection.get_PartitionKey() at Microsoft.Azure.WebJobs.ServiceBus.EventHubTriggerBindingStrategy.AddBindingData(Dictionary2 bindingData,EventData[] events) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.ServiceBus\EventHubs\EventHubTriggerInputBindingStrategy.cs : 111 at Microsoft.Azure.WebJobs.ServiceBus.EventHubTriggerBindingStrategy.GetBindingData(EventHubTriggerInput value) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.ServiceBus\EventHubs\EventHubTriggerInputBindingStrategy.cs : 86 at Microsoft.Azure.WebJobs.Host.ArrayTriggerArgumentBinding2.BindAsync(TTriggerValue value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggerArgumentBinding\ArraryTriggerArgumentBinding.cs : 26 at Microsoft.Azure.WebJobs.Host.Triggers.StrategyTriggerBinding2.BindAsync(Object value,ValueBindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\StrategyTriggerBinding.cs : 62 at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.cs : 57 End of inner exception<---

---> (Inner Exception #1) System.InvalidOperationException : Exception binding parameter 'partitionContext' ---> System.InvalidOperationException : Binding data does not contain expected value 'partitionContext'. at Microsoft.Azure.WebJobs.Host.Bindings.Data.ClassDataBinding1.BindAsync(BindingContext context) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\Data\ClassDataBinding.cs : 62 at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.cs : 98 End of inner exception<---

End of inner exception

TWith2Sugars commented 6 years ago

You can see here in the EventData source where/why this exception happens.