Example for simple service discovery ?
iangregsondev opened this issue · comments
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();