简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM