在 Service Fabric 中对应用程序建模Model an application in Service Fabric

本文概述 Azure Service Fabric 应用程序模型以及如何通过清单文件定义应用程序和服务。This article provides an overview of the Azure Service Fabric application model and how to define an application and service via manifest files.

了解应用程序模型Understand the application model

应用程序是由执行一个或多个特定功能的成分服务组成的集合。An application is a collection of constituent services that perform a certain function or functions. 服务执行完整且独立的功能,可以独立于其他服务启动和运行。A service performs a complete and standalone function and can start and run independently of other services. 服务由代码、配置和数据组成。A service is composed of code, configuration, and data. 对于每个服务,代码由可执行二进制文件组成,配置由可在运行时加载的服务设置组成,数据则由可供该服务使用的任意静态数据组成。For each service, code consists of the executable binaries, configuration consists of service settings that can be loaded at run time, and data consists of arbitrary static data to be consumed by the service. 可对此层次应用程序模型中的每个组件进行独立的版本控制和升级。Each component in this hierarchical application model can be versioned and upgraded independently.

Service Fabric 应用程序模型

应用程序类型是一个应用程序分类,包含大量服务类型。An application type is a categorization of an application and consists of a bundle of service types. 服务类型是一个服务分类。A service type is a categorization of a service. 该分类可以具有不同的设置和配置,但核心功能保持相同。The categorization can have different settings and configurations, but the core functionality remains the same. 服务实例是相同服务类型的不同服务配置变体。The instances of a service are the different service configuration variations of the same service type.

通过 XML 文件(应用程序清单和服务清单)描述应用程序和服务的类(或“类型”)。Classes (or "types") of applications and services are described through XML files (application manifests and service manifests). 清单描述应用程序和服务,它们是模板,可依据这样的模板从群集的映像存储区中使应用程序实例化。The manifests describe applications and services and are the templates against which applications can be instantiated from the cluster's image store. 应用程序和服务清单中详细介绍了清单。Manifests are covered in detail in Application and service manifests. ServiceManifest.xml 和 ApplicationManifest.xml 文件的架构定义随 Service Fabric SDK 和工具一起安装到 C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsdThe schema definition for the ServiceManifest.xml and ApplicationManifest.xml file is installed with the Service Fabric SDK and tools to C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsd. ServiceFabricServiceModel.xsd 架构文档中记录了 XML 架构。The XML schema is documented in ServiceFabricServiceModel.xsd schema documentation.

即使由同一 Service Fabric 节点托管时,不同应用程序实例的代码也将作为单独的进程运行。The code for different application instances run as separate processes even when hosted by the same Service Fabric node. 此外,可以独立管理每个应用程序实例的生命周期(如升级)。Furthermore, the lifecycle of each application instance can be managed (for example, upgraded) independently. 下图显示了应用程序类型如何由服务类型组成,而服务类型又如何由代码、配置和数据包组成。The following diagram shows how application types are composed of service types, which in turn are composed of code, configuration, and data packages. 为了简化示意图,这里只显示了 ServiceType4 的代码/配置/数据包,不过每个服务类型包括其中的部分或全部包类型。To simplify the diagram, only the code/config/data packages for ServiceType4 are shown, though each service type would include some or all those package types.

Service Fabric 应用程序类型和服务类型

群集中可以有某一服务类型一个或多个实例处于活动状态。There can be one or more instances of a service type active in the cluster. 例如,有状态服务实例(或称副本)通过在群集中不同节点上的副本之间复制状态实现高可靠性。For example, stateful service instances, or replicas, achieve high reliability by replicating state between replicas located on different nodes in the cluster. 复制本质上是提供冗余,使服务即使在群集中的一个节点失败时也可用。Replication essentially provides redundancy for the service to be available even if one node in a cluster fails. 分区服务进一步跨群集中的节点划分其状态(和该状态的访问模式)。A partitioned service further divides its state (and access patterns to that state) across nodes in the cluster.

下图显示应用程序和服务实例、分区与副本之间的关系。The following diagram shows the relationship between applications and service instances, partitions, and replicas.

服务中的分区和副本

Tip

可以使用 http://<yourclusteraddress>:19080/Explorer 上提供的 Service Fabric Explorer 工具查看群集中应用程序的布局。You can view the layout of applications in a cluster using the Service Fabric Explorer tool available at http://<yourclusteraddress>:19080/Explorer. 有关详细信息,请参阅使用 Service Fabric Explorer 可视化群集For more information, see Visualizing your cluster with Service Fabric Explorer.

后续步骤Next steps