在Curator中将选择策略与缓存一起使用 [英] Using selection strategies with a cache in Curator

查看:163
本文介绍了在Curator中将选择策略与缓存一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apache策展人( https://github.com/Netflix/curator/wiki/Service-Discovery )引入了以下概念:

The page on Service Discovery using apache curator (https://github.com/Netflix/curator/wiki/Service-Discovery) introduces the following concepts:

主要的抽象类是ServiceProvider.它封装了针对特定命名服务的发现服务以及提供者策略.提供者策略是一种用于为给定服务从一组实例中选择一个实例的方案.共有三种捆绑策略:Round Robin,Random和Sticky(始终选择相同的策略).通过使用ServiceProviderBuilder分配ServiceProvider.

The main abstraction class is ServiceProvider. It encapsulates the discovery service for a particular named service along with a provider strategy. A provider strategy is a scheme for selecting one instance from a set of instances for a given service. There are three bundled strategies: Round Robin, Random and Sticky (always selects the same one). ServiceProviders are allocated by using a ServiceProviderBuilder.

  • 以上每种查询方法都直接调用ZooKeeper.如果您不仅仅需要偶尔查询服务,还可以使用ServiceCache.它将特定服务的实例列表缓存在内存中.它使用监视程序来使列表保持最新.您可以通过ServiceDiscovery.serviceCacheBuilder()返回的构建器分配ServiceCache.

    Each of the above query methods calls ZooKeeper directly. If you need more than occasional querying of services you can use the ServiceCache. It caches in memory the list of instances for a particular service. It uses a Watcher to keep the list up to date. You allocate a ServiceCache via the builder returned by ServiceDiscovery.serviceCacheBuilder().

  • 我可以看到如何在ServiceProviderBuilder上使用提供者策略,但是ServiceCacheBuilder上没有等效方法,并且ServiceCache类本身唯一可用的相关方法是getInstances(),该方法得到所有实例.

    I can see how to use the Provider strategies with a ServiceProviderBuilder, but there's no equivalent method on the ServiceCacheBuilder, and the only relevant method available on the ServiceCache class itself is getInstances(), which gets all instances.

    如何在ServiceCache中使用提供者策略?

    How can I use a provider strategy with a ServiceCache?

    推荐答案

    @ simonalexander2005我只是在看代码,结果发现ServiceProvider内部已经使用了serviceCacheBuilder. TBH-我已经忘了这个,或者它已经被另一个提交者提交了-我不确定.无论如何,对于此处的解决方法,我感到非常抱歉.另外,必须更新文档以反映这一点-我今天将为此发布一个问题.我敢肯定这会让你发疯,对此再次感到抱歉.好消息是,使用ServiceProvider您会自动获得缓存.

    @simonalexander2005 I was just looking in the code and it turns out that ServiceProvider internally already uses a serviceCacheBuilder. TBH - I've either forgotten about this or it got put in by another committer - I'm not sure. Anyway, I'm very sorry about the runaround here. Also, the documentation must be updated to reflect this - I'll open an issue for this today. I'm sure this be maddening to you, again sorry for this. The good news, though, is that with ServiceProvider you automatically get caching.

    这篇关于在Curator中将选择策略与缓存一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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