etcd-registry

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2019 License: MIT

README

etcd-registry

ETCD Service Registry in Go. On each service node that is launched, register itself using this library so that the registration will be kept in an ETCD server. After registration, another client can discover which nodes are available and connect to them if desired. You must define a TTL for the registration so that if the node goes down after a while, the registration key in ETCD gets vanished and all watchers can know it is no longer available. The TTL keep alive is performed automatically by the library

Usage

  1. To register a running Node:
    registry, _ := etcdregistry.NewEtcdRegistry([]string{"http://etcd0:2379"}, "/services", 5*time.Second)
    node := etcdregistry.Node{}
	node.Name = "test"
	err := registry.RegisterNode(context.TODO(), "myservice", node, 5*time.Second)
  1. To query available service nodes
    registry, _ := etcdregistry.NewEtcdRegistry([]string{"http://etcd0:2379"}, "/services", 5*time.Second)
    nodes, _ := registry.GetServiceNodes("myservice")

See sample/main.go for a simple example

Run an Example

  1. Create a docker-compose.yml
version: '3.5'

services:

  sample:
    build: .

  etcd0:
    image: quay.io/coreos/etcd:v3.2.25
    environment:
      - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
      - ETCD_ADVERTISE_CLIENT_URLS=http://etcd0:2379

  etcd3-lucas:
    image: registry.cn-hangzhou.aliyuncs.com/ringtail/lucas:0.0.1
    ports:
      - 8888:8080
    environment:
      - ENDPOINTS=http://etcd0:2379
  1. Run docker-compose up

  2. See logs

  3. Run docker-compose scale sample=10

  4. Open browser at http://localhost:8888, click on "/" and find all registered nodes on ETCD tree

  5. Run docker-compose scale sample=3

  6. Check on browser for nodes being reajusted

More

  • Check github.com/flaviostutz/etcd-registrar for an utility that can be used with your existing application to register and keep alive the service node in parallel to the application execution

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL