每个服务结构实例的配置 [英] Configuration per Service Fabric Instance

查看:49
本文介绍了每个服务结构实例的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个服务结构无状态服务,该服务需要每个实例的配置数据.我最初的想法是创建命名分区,并使用PartitionInfo获取命名密钥,并使用共享的只读字典加载每个实例的设置.问题是,现在内部(从其他服务)访问此实例需要分区键.由于使用此方法的所有分区都将在内部提供相同的数据,因此我连接到哪个分区都没有关系(我希望它是随机的).因此,这给了我许多解决此问题的可能方法:

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. 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:

    • 基于实例的配置. 这篇文章在提出解决方案方面没有多大帮助.每个实例唯一的配置部分将是最理想的解决方案.
    • 创建命名实例,并将名称用作用户名(基本上将字符串附加到未分区的实例上)
    • 按索引获取实例,然后对共享的只读字典使用索引以获取用户名.
    • 以某种方式使用InitializationData(请参阅这篇文章)以获取用户名字符串(如果InitializationData在每个实例中可以是唯一的).
    • 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).

    以上所有内容都可以解决我的问题.这些方法有可能吗?

    All of the above will solve my issue. Is any of these ways possible?

    我正在尝试创建的服务示例:

    An example of a service I'm trying to create:

    假设我们有一个stackoverflow问题服务(简称SOQS).就本例而言,假设可以一次将一个用户连接到stackoverflow的websocket. SOQS内部方法(发布到我的服务结构)具有一种方法:GetQuestions().每个SOQS都需要使用唯一的用户名/密码连接到stackoverflow,随着新问题通过网络套接字推送,它们会添加到内部问题列表中. SOQS的GetQuestions()方法(从我的服务结构内部调用)将给出相同的问题列表.然后,我可以通过添加更多实例来平衡负载(只要我有更多的用户名/密码),然后就可以分配内部结构的负载.我可以调用ServiceProxy.Create<SOQS>()连接到随机实例以获取我的问题列表.

    Let's say we have a stackoverflow question service (SOQS for short). For the sake of this example, let's say that one user can be connected to stackoverflow's websocket at any one time. SOQS internal methods (Published to my service fabric) has one method: 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's GetQuestions() method (Called internally from my service fabric), would then give the same question list. 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.

    推荐答案

    我不完全确定这是您要寻找的东西,但是一种替代方法可能是创建一个额外的配置服务,以便为每个用户提供唯一的配置.实例.在启动无状态服务时,您只需要请求一个随机(或非随机)配置对象(例如json字符串),并在初始化期间引导该服务.这样,您就不必弄乱分区了,因为每个无状态实例都会触发它自己的Startup.cs(或等效的).

    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. That way, you don't have to mess with partitions, since each stateless instance will fire it's own Startup.cs (or equivalent).

    这篇关于每个服务结构实例的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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