[英]How to launch multiple instance of a long running service on Azure Service Fabric dynamically
I am very new to Azure Service Fabric. 我是Azure Service Fabric的新手。
My scenario is that I have a long-running service that I need to launch/stop multiple instances dynamically, and the launch should be non-block. 我的情况是我有一个长期运行的服务,需要动态启动/停止多个实例,并且启动应该是非阻塞的。 Each of the instance will process 1 data entry independently.
每个实例将独立处理1个数据输入。 For example:
例如:
Say I have a weather service that keeps pulling weather data for each city, and is long-running. 假设我有一个气象服务,可以持续获取每个城市的天气数据,并且运行时间很长。 And I have a list of cities that can change.
我有一个可以更改的城市列表。 So, I want to do the following thing:
因此,我想做以下事情:
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;
}
I've looked into Actor model, but seems like Actors are not suited for long-running task, and also it's hard to start/stop them. 我已经研究了Actor模型,但似乎Actor不适合长时间运行的任务,而且很难启动/停止它们。 Any idea what service/programming model I should use?
知道我应该使用哪种服务/编程模型?
Consider using a task queue here. 考虑在此处使用任务队列。
When called, the Weather Service would en-queue a task to pull weather data. 当被调用时,天气服务将排队任务以提取天气数据。 It would also run an infinite loop (
RunAsync
), this loop de-queues and executes tasks. 它还将运行一个无限循环(
RunAsync
),该循环使队RunAsync
队并执行任务。
This way the service calls will return quickly, while the work is performed in the background. 这样,服务调用将在后台执行的同时迅速返回。
Some code for inspirational purposes here . 一些代码,鼓舞人心的目的这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.