在服务结构应用程序中动态创建服务 [英] Dynamically creating services in an service fabric application

查看:101
本文介绍了在服务结构应用程序中动态创建服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有点描述性,请耐心等待. :)

在我要构建的应用程序中,产品具有独特的功能.用户可以选择加入功能A,B,D,但不能选择加入C.我构建此功能的方式是,每个独特的功能都是服务(无状态,我正在考虑将数据存储在Azure SQL中数据库,并从每个服务公开REST API).将所有服务捆绑在一起是一个ApplicationType.对于正在创建的每个客户租户(将其视为一组用户的共享帐户),我正在考虑使用TenantManagementService创建一个新的已注册ApplicationType的具体实例,并在FabricClient实例上调用client.ApplicationManager.CreateApplicationAsync()我可以在该租户的节点上运行一个专用的应用程序实例.但是,正如我所提到的,租户可以选择仅选择加入映射到服务子集的特定功能.如果租户仅选择我的应用程序的服务A,则对应于功能B,C,D的其余服务实例不应在节点上空闲运行.

我曾考虑为每个服务创建参与者,但是我正在创建的服务是无状态的,我想让它们的多个实例主动在多个节点上运行以实现负载平衡,而不是拥有状态服务的空闲副本./p>

类似于我对应用程序类型所做的操作,即将应用程序类型作为新的租户注册生成,当租户希望选择加入/退出产品功能时,我可以生成/删除服务吗?

这是我尝试过的: 打包我的应用程序时,我尝试将服务的InstanceCount设置为0.在我的ApplicationParameters XML文件中:

<Parameters>
    <Parameter Name="FeatureAService_InstanceCount" Value="0" />
    <Parameter Name="FeatureBService_InstanceCount" Value="0" />
</Parameters>

但是,从此类应用程序类型实例化应用程序时,Service Fabric资源管理器会启动.错误是这样的:

但是,另一方面,当在结构上部署服务时,它为我提供了一个删除它的选项,因此这种情况应该是有效的.

欢迎提出任何建议!

我的要求类似于在这里的anderso提到的方法- https://stackoverflow.com/a/35248349/1842699 ,但是,我要特别解决的问题是,使用一个或多个实例计数为零的打包服务上载创建应用程序实例!

解决方案

@uplnCloud

我希望我没事.

您的情况如下:

  • 每个客户应该有一个单独的应用程序(从相同的ApplicationType创建).
  • 每个客户应仅拥有服务的子集(在ApplicationType中定义).

如果我做对了,那么开箱即用即可.

首先,您应该从ApplicationManifest.xml中删除<DefaultServices />部分.这将指示Service Fabric不要使用该应用程序自动创建服务.

现在,算法如下:

  1. 使用FabricClient.ApplicationManager.CreateApplicationAsync()
  2. 创建应用
  3. 使用FabricClient.ServiceManager.CreateServiceAsync()为每个必需功能创建一个新的对应服务(您需要指定新创建的应用程序的应用程序名称)

还请注意,CreateServiceAsync()接受

However, Service Fabric Explorer cribs when instantiating the application out of such application type. The error is this:

But on the other hand, when a service is deployed on the fabric, it gives me an option to delete it specifically, so this scenario should be valid.

Any suggestions are welcome!

EDIT: My requirement is similar to the approach mentioned by anderso in here - https://stackoverflow.com/a/35248349/1842699, However, the problem that I'm specifically trying to solve is to upload create an application instance with one or more packaged services having zero instance count!

解决方案

@uplnCloud

I hope I understand everything right.

Your situation is the following:

  • Each customer should have separate Application (created from the same ApplicationType).
  • Each customer should have only subset of Services (defined in ApplicationType).

If I get it right then this is supported out of the box.

First of all you should remove <DefaultServices /> section from the ApplicationManifest.xml. This will instruct Service Fabric to don't create services automatically with the application.

Now the algorithm is the following:

  1. Create application using FabricClient.ApplicationManager.CreateApplicationAsync()
  2. For each required feature create a new corresponding Service using FabricClient.ServiceManager.CreateServiceAsync() (you need to specify the Application name of newly created Application)

Also note that CreateServiceAsync() accepts ServiceDescriptor that you can configure all service related parameters - starting from partitioning schema and ending up with instance count.

这篇关于在服务结构应用程序中动态创建服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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