横向扩展 azure 连续 webjob

Scale out azure continuous webjob

我正在尝试横向扩展一个连续的网络作业。我的服务计划是按标准设置的,因此我能够扩展 10 个实例。问题是 webjob 没有横向扩展,在任何时候,只有一个是 运行.

实例数:

函数:

函数代码:

根据这个article可以找到原因,请参考

Behind the scenes, TimerTrigger uses the Singleton feature of the WebJobs SDK to ensure that only a single instance of your triggered function is running at any given time. When the JobHost starts up, for each of your TimerTrigger functions a blob lease (the Singleton Lock) is taken. This distrubuted lock ensures that only a single instance of your scheduled function is running at any time.

我会使用 Continuous WebJob 而不是具有 TimerTrigger 的 WebJob(TimerTrigger 表示作业不是连续的)。您必须从代码中删除 TimerTrigger

默认情况下,Continuous WebJob 将在所有可用实例上执行。

在 WebJob 代码中,您必须注意消息已正确锁定和完成以避免并发问题。

Peek()方法不太适合并行处理,因为消息没有被锁定或完成,它不关心其他锁。使用 Receive() 或基于事件的 RegisterMessageHandler() 模式。

这里有一些相关的文档: