Azure Service Fabric多租户

cwi*_*pan 6 multi-tenant azure-service-fabric

我正试图对这个问题进行一些跟进,这个问题已经得到了解答......

Service Fabric多租户

如果我将我的租户设置为Azure Service Fabric无状态服务(他们将获得带外状态),我如何在群集中的每个节点上放置多个租户?在测试中,如果您尝试使实例计数大于节点数,则似乎Service Fabric会出现问题.

这些租户非常轻量级,所以我应该能够在每个节点上运行几十个(我们总共有几百个),我不想为每个节点做一个节点.具体来说,租户或多或少只是打开与外部客户服务的长轮询HTTP连接并将数据流回我们的系统 - 因此这里没有公共端点.我只需要能够激活很多这些工作人员,他们每个人都会打开他们自己的长轮询连接.

有人能指出我正确的方向吗?

仅供参考,我在这里解释了一下...... https://social.msdn.microsoft.com/Forums/en-US/efd172e2-0783-489b-b3ab-ec62fb7b8ee4/multiple-instances-per-node?论坛= AzureServiceFabric

提前致谢!

and*_*rso 8

你需要以某种方式划分你的服务.

有几个选项,但这两个在这里很好地对齐(以及你链接的SO问题):

有一个SF应用程序,每个租户都可以获得您的服务实例.然后,您需要在前面使用共享服务将请求路由到正确的服务.看起来应该是这样的.

MyAwesomeApp
    SharedStatelessApi <- External API points here
    MyTenantService_Tenant1 <- ServiceType: MyTenantService
    MyTenantService_Tenant2 <- ServiceType: MyTenantService
    ...
Run Code Online (Sandbox Code Playgroud)

另一种解决方案是为每个租户提供一个(或多个)服务结构应用程序,并且看起来像以下内容:

MySharedApp
    SharedStatelessApi <- External API points here
Tenant1 <- ApplicationType: MyTenantApp
    MyTenantService <- ServiceType: MyTenantService
Tenant2 <- ApplicationType: MyTenantApp
    MyTenantService <- ServiceType: MyTenantService
Run Code Online (Sandbox Code Playgroud)

它与第一个示例的概念相同,但分区是在更高的杠杆上完成的.

就个人而言,我更喜欢第二种情况.感觉更对.在这两种情况下,您都必须在新客户注册时手动创建服务/应用程序,或者在代码中执行.如果你想在代码中这样做,你应该看看FabricClient.如果你需要一个例子,请告诉我.

此外,正如您所看到的,您应该有一个共享的公共端点,并在该端点中根据某些内容(标头,身份验证令牌,uri,与您的应用程序内联的任何内容)将请求路由到正确的服务.

使用FabricClient创建服务的示例:

首先,您需要FabricClient.对于不安全的群集(您的本地开发群集),以下内容就足够了:

var fabricClient = new FabricClient("localhost:19000");
Run Code Online (Sandbox Code Playgroud)

部署到安全集群后(例如在Azure中),您需要对FabricClient进行身份验证,如下所示:

var creds = new X509Credentials
{
    FindType = X509FindType.FindByThumbprint,
    FindValue = clientCertThumbprint,
    RemoteCertThumbprints = {clientCertThumbprint},
    StoreLocation = StoreLocation.LocalMachine,
    StoreName = "My"
};

var clusterEndpoint = "CLUSTERNAME.LOCATION.cloudapp.azure.com:19000"
// or whatever your cluster endpoint is

var fabricClient = new FabricClient(creds, clusterEndpoint);
Run Code Online (Sandbox Code Playgroud)

然后,当您拥有FabricClient时,您可以创建如下的无状态服务:

var statelessDescriptor = new StatelessServiceDescription
{
    ApplicationName = new Uri("fabric:/MYAPP"),
    InstanceCount = 1, // How many instances.
    PartitionSchemeDescription = new SingletonPartitionSchemeDescription(),
    ServiceName = new Uri("fabric:/MYAPP/TenantA"),
    ServiceTypeName = "YourServiceTypeName",
    InitializationData = DATA_TO_PASS_TO_SERVICE_BYTE[] // Only if needed.
};

await _client.ServiceManager.CreateServiceAsync(statelessDescriptor)
Run Code Online (Sandbox Code Playgroud)

如果您传递了"InitializationData"道具中的任何数据,它将在服务中作为ServiceInitializationParameters.InitializationData提供.