简体   繁体   English

服务发现模式

[英]Service discovery pattern

I m actually studying the service discovery pattern but I dont really understand the way how it works. 我实际上正在研究服务发现模式,但我并不真正了解它的工作方式。

I have read an article using a library with nodejs called etcd ( http://lukebond.ghost.io/service-discovery-with-etcd-and-node-js/ ) and it seems easy to use like only setting a pattern url lile /my/service. 我已经阅读了一篇文章,该文章使用的节点库名为etcd( http://lukebond.ghost.io/service-discovery-with-etcd-and-node-js/ ),使用起来似乎很容易,就像仅设置模式网址一样lile /我/服务。

Then I have some questions : 然后我有一些问题:

  • how can I access this service from another nodejs app ? 如何从另一个nodejs应用程序访问此服务?
  • how can I do if I want to access /my/service/something, knowing that it s not defined in the service registry and that we admit I dont know at all the API ? 知道服务注册表中未定义/ my / service / something,并且我承认我根本不知道该API怎么办?

After reading this article, I tried to understand how zookeeper works. 阅读本文后,我试图了解Zookeeper的工作原理。 With this one, and using a standard library( https://github.com/yfinkelstein/node-zookeeper ), I m facing a problem : 有了这个,并使用标准库( https://github.com/yfinkelstein/node-zookeeper ),我遇到了一个问题:

  • what is the value I have to set ? 我必须设置什么值? In fact with zookeeper, it seems that we have to set a pattern url and a value. 实际上,对于Zookeeper,似乎我们必须设置一个模式url和一个值。 What is this value ? 这个值是多少?
  • what are the service children with zookeeper ? 带动物园管理员的儿童有哪些服务? What is the aim of this concept ? 这个概念的目的是什么?

Thanks for advance everybody 谢谢大家的进步

Thanks for advance 谢谢前进

Here is a good article about service discovery patterns. 是一篇关于服务发现模式的好文章。 Here are some standard patterns based answers: 以下是一些基于标准模式的答案:

how can I access this service from another nodejs app ? 如何从另一个nodejs应用程序访问此服务?

The service discovery tool like etcd will return you the list of endpoints for the service you need. 诸如etcd之类的服务发现工具将为您返回所需服务的端点列表 See example here : 在这里查看示例:

{
    "action": "get",
    "node": {
        "key": "/",
        "dir": true,
        "nodes": [
            {
                "key": "/foo_dir",
                "dir": true,
                "modifiedIndex": 2,
                "createdIndex": 2
            },
            {
                "key": "/foo",
                "value": "two",
                "modifiedIndex": 1,
                "createdIndex": 1
            }
        ]
    }
}

how can I do if I want to access /my/service/something, knowing that it s not defined in the service registry and that we admit I dont know at all the API ? 知道服务注册表中未定义/ my / service / something,并且我承认我根本不知道该API怎么办?

I think you mean "what do I do if /my/service/something is undefined"? 我认为您的意思是“如果/ my / service / something未定义该怎么办”? In this case it is all up to the logic of your application. 在这种情况下,这完全取决于应用程序的逻辑。 I would think that reasonable way would be retry if you expect that the value will appear at some point. 我认为,如果您期望该值会在某个时候出现,那么将重试合理的方法。

what is the value I have to set ? 我必须设置什么值? In fact with zookeeper, it seems that we have to set a pattern url and a value. 实际上,对于Zookeeper,似乎我们必须设置一个模式url和一个值。 What is this value ? 这个值是多少?

The value is whatever you want it to be there. 该值是您想要的任何值。 With ZooKeeper you might want to use ephemeral nodes for each server node. 使用ZooKeeper,您可能希望对每个服务器节点使用临时节点。 You can keep data you need to connect to that node inside or just nothing. 您可以将需要连接到该节点的数据保留在内部,也可以什么也不保留。

what are the service children with zookeeper ? 带动物园管理员的儿童有哪些服务? What is the aim of this concept ? 这个概念的目的是什么?

I think you are referencing to hierarchical structure of ZooKeeper ZNodes. 我认为您指的是ZooKeeper ZNodes的层次结构。 I think "children" in this case will be all nodes which belong to some parent. 我认为在这种情况下,“子代”将是属于某个父代的所有节点。 For example, for nodes /a/b/c and /a/b/d their parent would be /a/b and therefore children of /a/b are /a/b/c and /a/b/d. 例如,对于节点/ a / b / c和/ a / b / d,其父节点为/ a / b,因此/ a / b的子节点为/ a / b / c和/ a / b / d。

Hope this helps. 希望这可以帮助。

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

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