Azure Service Fabric多租户 [英] Azure Service Fabric Multi-Tenancy

查看:94
本文介绍了Azure Service Fabric多租户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对已经得到解答的这个问题进行一些跟进...

I'm trying to get a little follow up to this question that's already been answered...

服务结构多租户

如果将租户设置为Azure Service Fabric无状态服务(它们将带外状态),如何在群集中的每个节点上放置多个租户?在测试中,如果尝试使实例计数大于节点计数,似乎Service Fabric会阻塞.

If I were to setup my tenants as Azure Service Fabric Stateless Services (they'll get their state out-of-band), how can I put more than one tenant on each node in the cluster? In testing, it seems that Service Fabric gags if you try and make your instance count greater than the node count.

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

These tenants are very lightweight, so I should be able to run dozens of them on each node (we will have hundreds overall), and I don't want to have to do a node for each one. Specifically, the tenants are more-or-less just opening a long-polling HTTP connection to an external customer service and streaming that data back into our system - so there's no public endpoints in play here. I just need the ability to spin up a lot of these workers that'll each open up their own long-polling connection.

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

Can somebody point me in the right direction?

仅供参考,在这里我已经解释了一些内容...

FYI, I've explained a little bit more here... https://social.msdn.microsoft.com/Forums/en-US/efd172e2-0783-489b-b3ab-ec62fb7b8ee4/multiple-instances-per-node?forum=AzureServiceFabric

提前谢谢!

推荐答案

您需要以某种方式对服务进行分区.

You'll need to somehow partition your service.

有几个选项,但是两个选项在这里很好(以及与您链接的SO问题相对应):

There is several options, but the two that aligns good here (and also with the SO question you linked are):

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

Have a SF application where each tenant gets an instance of your service. You will then need to have a shared service in front to route requests to the correct service. It should look something like this.

MyAwesomeApp
    SharedStatelessApi <- External API points here
    MyTenantService_Tenant1 <- ServiceType: MyTenantService
    MyTenantService_Tenant2 <- ServiceType: MyTenantService
    ...

另一种解决方案是每个租户拥有一个(或多个)服务结构应用程序,并且看起来与以下内容类似:

The other solution is to have one (or more) service fabric application per tenant, and would look something along the lines of:

MySharedApp
    SharedStatelessApi <- External API points here
Tenant1 <- ApplicationType: MyTenantApp
    MyTenantService <- ServiceType: MyTenantService
Tenant2 <- ApplicationType: MyTenantApp
    MyTenantService <- ServiceType: MyTenantService

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

It's the same concept as the first example, but the partition is done on a higher lever.

我个人比较喜欢第二种情况.感觉更对. 在这两种情况下,您都必须在新客户注册时手动创建服务/应用程序,或者在代码中进行操作.如果要在代码中执行此操作,则应查看FabricClient.如果您需要一个示例,请告诉我.

Personally, I prefer the second case. It feels more right. In both cases, you'll have to either create the services/application manually when a new customer signs up, or do it in code. If you want to do it in code, you should look at the FabricClient. If you need an example of that, let me know.

此外,如您所见,您应该拥有一个共享的公共端点,并且在该端点中,您应基于某种内容(标头,身份验证令牌,uri,以及与您的应用内联的任何内容)将请求路由到正确的服务.

Also, as you can see, you should have a shared public endpoint, and in that endpoint route the request to the correct service based on something (header, auth token, uri, whatever is inline with your app).

使用FabricClient创建服务的示例:

Example of using FabricClient to create a service:

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

First you need a FabricClient. For a unsecured cluster (your local dev cluster), the following is enough:

var fabricClient = new FabricClient("localhost:19000");

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

When you have deployed to a secured cluster (for example in Azure), you need to authenticate the FabricClient, like so:

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);

然后,当您拥有FabricClient时,可以像这样创建无状态服务:

Then, when you have a FabricClient, you can create a stateless service like this:

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)

如果您在"InitializationData"道具中传递了任何数据,则该数据将在服务中以ServiceInitializationParameters.InitializationData的形式提供

If you passed any data in the "InitializationData" prop, it will be available in the service as ServiceInitializationParameters.InitializationData

这篇关于Azure Service Fabric多租户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆