简体   繁体   English

谁应该拥有Service Fabric状态服务中的服务解析逻辑?

[英]Who should own the logic for service resolution in Service Fabric Stateful Services?

I am using Service Fabric stateful services to store state about users in the system. 我正在使用Service Fabric状态服务在系统中存储有关用户的状态。 My partitioning strategy is to use the normalized international string format phone number to address a named service instance, and the hash of the phone number to resolve a partition of that service. 我的分区策略是使用规范化的国际字符串格式电话号码来寻址已命名的服务实例,并使用电话号码的哈希值来解析该服务的分区。 EX: fabric:/myapp/users/1/718 (where the international phone number is +1718xxxxxxx) This allows me to geo-locate services based on their country (and further in the US/Canada markets by area code). 例如:fabric:/ myapp / users / 1/718(国际电话号码为+ 1718xxxxxxx),这使我可以根据服务所在的国家/地区(以及地区号在美国/加拿大市场)对服务进行地理位置定位。

My question is sort of theoretical, but also practical in nature. 我的问题是理论上的,但实际上也是实用的。 Who owns the logic for service resolution? 谁拥有服务解析逻辑? A simple approach is to just require anyone taking a dependency on this service to know how its partitioned, but that feels like a leaky abstraction to me. 一种简单的方法是仅要求依赖此服务的任何人都知道该服务的分区方式,但这对我来说就像是一个抽象的泄漏。 Furthermore, I would like to assign an Id to the user which is divorced from the concept of a phone number. 此外,我想为用户分配一个ID,该ID与电话号码的概念不同。

  1. My original approach was to make the Id a byte[] which included the service name, partition id, and local id of the user. 我最初的方法是使Id成为byte [],其中包括用户的服务名称,分区ID和本地ID。 I dropped this idea since the size of the ID was very large, and would add up over time. 我放弃了这个想法,因为ID的大小很大,并且随着时间的推移会增加。 (this is problematic because all keys in a Reliable Dictionary need to fit into memory and I'd rather not kill a ton of memory on ids) Also, it still carries with it the baggage of everyone using the id knowing how to interpret the id and use it accordingly. (这是有问题的,因为“可靠字典”中的所有键都需要容纳到内存中,而我宁愿不杀死id上的大量内存。)此外,它仍然携带着每个使用id的人的行李,他们知道如何解释id并据此使用。
  2. My next idea was to provide a client library to anyone consuming the service. 我的下一个想法是为使用该服务的任何人提供一个客户端库。 This also has the drawback of a binary dependency of a consuming service. 这也具有消费服务的二进制依赖性的缺点。 If i want to change the strategy in the future, I have to jump through a bunch of hoops to handle failures to correctly resolve the entity. 如果我想在将来更改策略,则必须跳过一堆箍来处理故障以正确解析实体。
  3. The last alternative i can think of is to have a stateless proxy in front of stateful service which handles the resolution for all services. 我能想到的最后一个选择是在有状态服务之前有一个无状态代理,该代理处理所有服务的解析。 This is the most appealing from a design perspective but also involves managing, building another service just for resolution. 从设计角度来看,这是最有吸引力的方法,但同时也涉及管理,构建另一个仅用于解决问题的服务。 Not opposed to it, but it is an additional consideration. 不反对它,但这是一个额外的考虑。 If i go this route, should I tread this service as a separate service fabric application, or is it advisable to keep everything as one application. 如果我走这条路,我应该将此服务作为单独的服务结构应用程序使用,还是建议将所有内容都保留为一个应用程序。

I also, am open to entertaining the idea that partitioning users this way is a bad idea. 我也乐于接受这样的想法:以这种方式对用户进行分区是个坏主意。 However, using the phone is advisable for a number of reasons. 但是,出于多种原因,建议使用电话。

I'd recommend keeping any knowledge about partitioning away from your service consumers, if possible. 如果可能的话,我建议远离您的服务使用者,保持对分区的任何了解。 This way you can change the service internals without changing anything at the consumer-side. 这样,您可以更改服务内部,而无需在用户端进行任何更改。

That leads to option 3, combined with the built-in reverse proxy service. 这导致选项3与内置的反向代理服务结合在一起。 In that extra service, you can look up the authenticated user and use its location to determine the service partition. 在该额外服务中,您可以查找经过身份验证的用户,并使用其位置来确定服务分区。

If you make it a new application, it can become the entrypoint (/proxy) for multiple bounded contexts 如果将其设为新应用程序,则它可以成为多个有界上下文的入口点(/ proxy)

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

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