0

我对 Azure Service Fabric 非常陌生。

我的场景是我有一个长时间运行的服务,我需要动态启动/停止多个实例,并且启动应该是非阻塞的。每个实例将独立处理 1 个数据条目。例如:

假设我有一个气象服务,它不断提取每个城市的气象数据,并且长期运行。我有一个可以改变的城市列表。所以,我想做以下事情:

var weatherSvcList = new List...
var currentCities = [];
while (true) 
{
    var newCities = FetchCities();

    var addedCities = newCities.Except(currentCities);
    weatherSvcList  = LaunchSvc(addedCities); // launch and return, non-blocking

    var removedCities = currentCities.Except(newCities);
    weatherSvcList  = StopSvc(removedCities);

    weatherSvcList  = RelaunchErrorSvc(cities);

    currentCities = newCities;
}

我研究了 Actor 模型,但似乎 Actor 不适合长时间运行的任务,而且很难启动/停止它们。知道我应该使用什么服务/编程模型吗?

4

1 回答 1

0

考虑在此处使用任务队列。

当被调用时,气象服务会将一项任务排入队列以提取气象数据。它还会运行一个无限循环 ( RunAsync),这个循环会取消队列并执行任务。

这样,服务调用将快速返回,而工作在后台执行。

这里有一些用于鼓舞人心的代码。

于 2017-11-24T07:36:41.747 回答