如何将 EventData 传递给持久函数?

发布于 2025-01-12 08:43:37 字数 1172 浏览 4 评论 0原文

我想从 EventHubTrigger azure 函数运行持久函数。

        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;
            }
        }

让我知道如何将事件传递给持久函数或者我可以更好地设计它?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2025-01-19 08:43:37

我相信在阅读此内容后,您编写在 Azure Durable Functions 中传递事件数据的工作流程的方式是有意义的 基于事件的带有持久功能的工作流程

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

在您的代码中,您使用了 context.GetInput 方法来解压您传递的事件数据,并反序列化为 JSON。

在上面的文章中,有一些有关在 Azure Durable Functions 中使用基于事件的触发数据的工作流程的信息,可能会对您有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文