microsoft / etcd3

:bookmark: Node.js client for etcd3

Home Page:https://microsoft.github.io/etcd3/classes/etcd3.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example for simple service discovery ?

iangregsondev opened this issue · comments

commented

Hi,

Does anybody know if there is an example for service discovery using etcd and this library ?

I did look at consul but I prefer to use etcd for its simplicity but finding it hard to find concrete examples of how to "register" and "find" a service.

Any ideas ?

Thanks in advance

The example code for leases actually shows service discovery 🙂

The idea is that you set a key with a lease (so that etcd cleans up the lease if the server goes down) and then, to get services, retrieve all keys with the prefix.

Edit: I noticed that getAvailableHosts should actually be

const keys = await client.getAll().prefix(hostPrefix).keys();