简体   繁体   English

每个服务结构实例的配置

[英]Configuration per Service Fabric Instance

I'm designing a service fabric stateless service, which requires configuration data for each instance. 我正在设计一种服务结构无状态服务,它需要每个实例的配置数据。 My initial thought was creating named partitions, and using PartitionInfo to get the named key, with a shared read only dictionary to load settings per instance. 我最初的想法是创建命名分区,并使用PartitionInfo获取命名密钥,使用共享只读字典来加载每个实例的设置。 Problem is, now accessing this instance internally (From other services) requires a partition key. 问题是,现在在内部访问此实例(来自其他服务)需要一个分区键。 Since all partitions using this method will serve the same data internally, it doesn't matter which partition I connect to (I'd want it to be random). 由于使用此方法的所有分区都将在内部提供相同的数据,因此我连接到哪个分区并不重要(我希望它是随机的)。 So, this gives me many possible ways to fix this problem: 所以,这给了我许多可能的方法来解决这个问题:

The following solutions that don't involve partitions: 以下解决方案不涉及分区:

  • A configuration based per instance. 基于每个实例的配置。 This post doesn't give much help in coming up with a solution. 这篇文章对于提出解决方案没有太大帮助。 A configuration section unique to each instance would be the most ideal solution. 每个实例独有的配置部分将是最理想的解决方案。
  • Create named instances, and use the name as the username (Basically attach a string to a non-partitioned instance) 创建命名实例,并使用该名称作为用户名(基本上将字符串附加到非分区实例)
  • Get an instance by index, and use the index against a shared read-only dictionary to get the username. 通过索引获取实例,并对共享的只读字典使用索引来获取用户名。
  • Somehow use InitializationData (See this post ) to get a username string (If InitializationData can be unique per instance). 以某种方式使用InitializationData(请参阅此文章 )获取用户名字符串(如果InitializationData每个实例可以是唯一的)。

All of the above will solve my issue. 以上所有都将解决我的问题。 Is any of these ways possible? 这些方法有可能吗?

EDIT: An example of a service I'm trying to create: 编辑:我正在尝试创建的服务示例:

Let's say we have a stackoverflow question service (SOQS for short). 假设我们有一个stackoverflow问题服务(简称SOQS)。 For the sake of this example, let's say that one user can be connected to stackoverflow's websocket at any one time. 为了这个例子,假设一个用户可以在任何时候连接到stackoverflow的websocket。 SOQS internal methods (Published to my service fabric) has one method: GetQuestions() . SOQS内部方法(发布到我的服务结构)有一个方法: GetQuestions() Each SOQS would need to connect to stackoverflow with a unique username/password, and as new questions are pushed through the websocket, they added to an internal list of questions. 每个SOQS都需要使用唯一的用户名/密码连接到stackoverflow,并且当通过websocket推送新问题时,它们会添加到内部问题列表中。 SOQS's GetQuestions() method (Called internally from my service fabric), would then give the same question list. SOQS的GetQuestions()方法(从我的服务结构内部调用)将提供相同的问题列表。 I can then load balance by adding more instances (As long as I have more username/passwords) and the load internally to my fabric could then be distributed. 然后,我可以通过添加更多实例来加载平衡(只要我有更多的用户名/密码),然后可以分发我的结构内部的负载。 I could call ServiceProxy.Create<SOQS>() to connect to a random instance to get my question list. 我可以调用ServiceProxy.Create<SOQS>()连接到一个随机实例来获取我的问题列表。

It sounds like what you are looking for to have a service type that has multiple actors with each actor having its own configuration. 听起来你正在寻找拥有多个actor的服务类型,每个actor都有自己的配置。 They wouldn't be multiple copies of the same service with unique configurations, it would be one (with replicas of course) instance of the service as a singleton, and individual actors for each instance. 它们不是具有唯一配置的相同服务的多个副本,它将是一个(当然具有副本)服务实例作为单例,以及每个实例的各个actor。

As an example you could have the User Service (guessing what it is since you mention username string) read from some external storage mechanism the list of usernames and longs for instance ids for each to use for internal tracking. 作为一个例子,您可以拥有用户服务(猜测自提及用户名字符串后的内容)从某些外部存储机制读取的用户名列表以及每个用于内部跟踪的实例ID的长度。 The service would then create an actor for each, with its own configuration information. 然后,该服务将为每个创建一个actor,并具有自己的配置信息。 Then the User Service would be the router for messaging to and from the individual actors. 然后,用户服务将成为与各个参与者之间进行消息传递的路由器。

I'm not entirely sure that this is what you're looking for, but one alternative might be to create an additional configuration service to provide the unique configs per instance. 我不完全确定这是你正在寻找的,但另一种选择可能是创建一个额外的配置服务来为每个实例提供独特的配置。 On startup of your stateless service, you simply request a random (or non-random) configuration object such as a json string, and bootstrap the service during initialization. 在启动无状态服务时,您只需请求一个随机(或非随机)配置对象(如json字符串),并在初始化期间引导服务。 That way, you don't have to mess with partitions, since each stateless instance will fire it's own Startup.cs (or equivalent). 这样,您就不必乱用分区,因为每个无状态实例都会触发它自己的Startup.cs(或等效的)。

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

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