简体   繁体   English

Azure Service Fabric用法

[英]Azure Service Fabric usage

Service Fabric was just announced at the build conference. Service Fabric刚刚在构建会议上宣布。 I was reading the scarce documentation about it and I have a question. 我正在阅读有关它的稀缺文档,我有一个问题。

I'm evaluating Service Fabric for hosting CRUD like microservices that are at the moment built in ASP.NET WebApi. 我正在评估Service Fabric用于托管CRUD,就像目前在ASP.NET WebApi中构建的微服务一样。

Is Service Fabric geared towards hosting small pieces of functionality that receive data, process it and return the result, rather than hosting CRUD WebApi types of application? Service Fabric是否适合托管接收数据,处理数据并返回结果的小功能,而不是托管CRUD WebApi类型的应用程序?

Service Fabric enables the creation of both stateless and stateful microservices. Service Fabric可以创建无状态和有状态的微服务。

As the name suggests, any state maintained by an an instance of a stateless service will be lost if the node goes down. 顾名思义,如果节点出现故障,由无状态服务实例维护的任何状态都将丢失。 A new, fresh instance will simply be spun up elsewhere in the cluster. 一个新的,新的实例将简单地在集群中的其他地方旋转。

Stateful services offer the ability to persist state without relying on an external store. 有状态服务提供了在不依赖外部存储的情况下持久保存状态的能力。 Any data stored in a Reliable Collection will be automatically replicated across multiple nodes in the cluster, ensuring that the state is resilient to failures. 存储在Reliable Collection中的任何数据都将自动复制到群集中的多个节点,从而确保状态对故障具有弹性。

A common pattern is to use a stateless service as the client-facing gateway to the application and then have that service direct traffic to the app's partitioned stateful services. 常见的模式是使用无状态服务作为应用程序的面向客户端的网关,然后让该服务将流量引导到应用程序的分区有状态服务。 This hides the work of resolving partitions from clients, allowing them to to target one logical endpoint with all requests. 这隐藏了从客户端解析分区的工作,允许它们针对所有请求定位一个逻辑端点。

Take a look at the WordCount sample for an example of how this works. 看看WordCount示例 ,了解其工作原理示例。 The WordCount.WebService stateless service acts as the front end to the application. WordCount.WebService无状态服务充当应用程序的前端。 It simply resolves the partition based on the incoming request and then sends it on. 它只是根据传入的请求解析分区,然后将其发送。 The WordCount.Service stateful service (partitioned based on the first letter of the word) immediately puts those incoming requests in a ReliableQueue and then processes them in the background, storing the results in a ReliableDictionary. WordCount.Service有状态服务(基于单词的第一个字母分区)立即将这些传入请求放入ReliableQueue中,然后在后台处理它们,将结果存储在ReliableDictionary中。

For more details, see the Reliable Services Overview . 有关更多详细信息,请参阅可靠服务概述

Note: for now, the best way to expose WebAPI endpoints to clients is to self-host an OWIN server in the stateless service. 注意:目前,向客户端公开WebAPI端点的最佳方法是在无状态服务中自托管OWIN服务器。 ASP.NET 5 projects will soon be supported as well. 很快就会支持ASP.NET 5项目。

This video answers my own question: http://channel9.msdn.com/Events/Build/2015/2-704 . 该视频回答了我自己的问题: http//channel9.msdn.com/Events/Build/2015/2-704 In summary, we should use Stateless Services to host ASP.NET based sites or API's which persist data to external data stores. 总之,我们应该使用无状态服务来托管基于ASP.NET的站点或API,这些站点或API将数据保存到外部数据存储。

If you don't have state (or have it externally), Stateless Service is the way to start. 如果您没有状态(或者没有外部状态),则无状态服务是开始的方式。

Answer to the original question is "both". 对原始问题的回答是“两个”。 Basically, anything that have main() function (with couple of more extended contract methods to talk to Service Fabric) can be a service in Service Fabric world. 基本上,任何具有main()函数(具有几个扩展的合同方法与Service Fabric交谈)的东西都可以是Service Fabric世界中的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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