'How to Pass EventData to Durable Functions?

I want to run durable function from EventHubTrigger azure function.

        public async Task<bool> Activities(
            [EventHubTrigger(EventHubName, Connection = EventHubConnStrName)] EventData[] events,
            [DurableClient] IDurableOrchestrationClient durableClient,
            ILogger logger)
        {
                // chaining pattern durable function
                 await durableClient.StartNewAsync<string>(
                       FunctionNames.BatchEvents,
                       JsonConvertUtil.SerializeObject(events));
           
        } 

        [FunctionName(FunctionNames.BatchEvents)]
        public static async Task<bool> Run(
           [OrchestrationTrigger] IDurableOrchestrationContext context,
            ILogger logger)
        {
            try
            {
                var events = 
                    JsonConvertUtil.DeserializeObject<EventData[]>(context.GetInput<string>()));

                ....
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
        }

Let me know how can i pass events to durable function or i can design it better way ?



Solution 1:[1]

I believe the way you written the workflow to pass Event data in Azure Durable Functions makes sense after reading this event-based-workflows-with-durable-function.

 var events = 
             JsonConvertUtil.DeserializeObject<EventData[]>(context.GetInput<string>()));

In your code, as you have used context.GetInput<string> Method unpacks the event data you passed and also with deserialization to JSON.

In the above article, there is some information regarding the workflows usage of Event based Triggered Data using in Azure Durable Functions which might help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HariKrishnaRajoli-MT