多个短期TPL数据流与一个长期运行的流 [英] Multiple Short-lived TPL Dataflows versus Single Long-Running Flow

查看:62
本文介绍了多个短期TPL数据流与一个长期运行的流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TPL数据流在Azure辅助角色中处理队列外的项目.我应该只运行一个长期运行的数据流,还是为收到的每条消息生成一个新的流?

I'm using TPL dataflow to process items off a queue in an Azure worker role. Should I have a single long running dataflow, or spawn a new flow for every messages I receive?

如果块中引发错误,则该块将停止接受新消息.这意味着,如果块中存在异常,则整个数据流将停止处理.

If an error is thrown in a block, that block will stop accepting new messages. That means if there is an exception in a block, the whole dataflow will stop processing.

我需要能够承受诸如无效队列输入之类的异常而不会锁定我的数据流.我看到两个选项之一:

I need to be able to withstand exception from something like invalid queue inputs without locking my dataflow. I see one of two options:

  1. 我从一个单一的数据流开始,并在它们离开队列时向其发送消息.每个块的内容都包装在try-catch块中,该块记录了异常,然后继续进行处理.这似乎很笨拙,我认为有更好的方法.
  2. 对于每条消息,我都会启动一个新的数据流并处理队列消息.如果在任何块中引发异常,则数据流将完成,并且我仅恢复一条消息.我见过的大多数Dataflow示例都发送多条消息,因此感觉也不对.

我看过很多有关如何在异常后完成数据流的文档,但是关于如何从异常中恢复的文档很少.

I've seen lots of documentation on how to complete a dataflow after an exception, but very little on how to recover from exceptions.

推荐答案

您绝对应该选择第一个选项,并且只有一个流程.

You should definitely go with the first option and have only one flow.

在第二个选项中,使用数据流并没有一个附加的价值,而只是一个接一个地调用多个方法.为每个项目创建完整的数据流流也有开销.

In the second option there isn't any added value of using a dataflow over just calling several methods one after the other. There is also an overhead of creating a full dataflow flow for each and every item.

最好只构建一次流程,并在应用程序的整个生命周期中使用它.我认为处理每个块的异常没有任何问题,但是如果您想让整个流程失败,然后再创建一个新的流程.

It's better to build the flow once, and use it throughout the app's lifetime. I don't think there's anything wrong with handling exceptions per blocks, but if you want to can let the whole flow fail and only then create a new one.

这篇关于多个短期TPL数据流与一个长期运行的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆