简体   繁体   中英

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.

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. 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?).

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. Each partition in the service would read from a single partition in your IoT hub. You could also do this as a stateless service that is a background worker (not a web api) that has 32 instances. You would need some way of coordinating which instance/partition is communicating with each IoT partition.

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. You could put these services in the section of your 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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