简体   繁体   中英

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.

Then I have some questions :

  • how can I access this service from another nodejs app ?
  • 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 ?

After reading this article, I tried to understand how zookeeper works. With this one, and using a standard library( https://github.com/yfinkelstein/node-zookeeper ), I m facing a problem :

  • 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. 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 ?

The service discovery tool like etcd will return you the list of endpoints for the service you need. 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 ?

I think you mean "what do I do if /my/service/something is undefined"? 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. 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. 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. 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.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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