简体   繁体   English

在Service Fabric中使用参数创建服务实例

[英]Create service instances with parameters in Service Fabric

I'm using Service Fabric on Azure for a project at work where, put simply, I have a service whose function is to read data from IoT Hub. 我正在使用Azure上的Service Fabric进行工作的项目,简单来说,我有一项服务,其功能是从IoT中心读取数据。

As it stands, that service is reading data from 32 partitions at the same time (multiple threads), but I'm trying to refactor it into one service intance per partition. 就目前而言,该服务正在同时从32个分区(多个线程)读取数据,但是我试图将其重构为每个分区一个服务实例。 The problem is I can't find a way to create 32 instances of a service and inform each instance of the Hub partition it should read (paramethers perhaps?). 问题是我找不到创建服务的32个实例并通知每个应该读取的Hub分区实例的方法(也许是参数)。

I can provide code samples if needed, but I feel the problem is pretty self-explanatory. 如果需要,我可以提供代码示例,但是我觉得这个问题不言自明。

You could create a stateful service with 32 partitions. 您可以创建具有32个分区的有状态服务。 Each partition in the service would read from a single partition in your IoT hub. 服务中的每个分区将从IoT中心中的单个分区读取。 You could also do this as a stateless service that is a background worker (not a web api) that has 32 instances. 您也可以将其作为具有32个实例的后台工作程序(不是Web API)作为无状态服务来执行。 You would need some way of coordinating which instance/partition is communicating with each IoT partition. 您将需要某种方式来协调哪个实例/分区正在与每个IoT分区通信。

If you insist on have 32 instances of the service then you would just need to make sure that each instance of the service has a unique name. 如果您坚持要有32个服务实例,则只需确保该服务的每个实例都具有唯一的名称。 You could put these services in the section of your ApplicationManifest: 您可以将这些服务放在ApplicationManifest的部分中:

<DefaultServices>
    <Service Name="Service01">
        <StatelessService ServiceTypeName="MyServiceType" InstanceCount="1">
            <SingletonPartition />
        </StatelessService>
    </Service>
    <Service Name="Service02">
        <StatelessService ServiceTypeName="MyServiceType" InstanceCount="1">
            <SingletonPartition />
        </StatelessService>
    </Service>
    ...
</DefaultServices>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM