GithubHelp home page GithubHelp logo

gutorc92 / etcd-registry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flaviostutz/etcd-registry

0.0 0.0 0.0 16 KB

ETCD Service Registry lib in Go. When endpoints go live, they register themselves with a TTL so that another service can know all live endpoints for a specific server.

License: MIT License

Dockerfile 15.53% Go 83.38% Shell 1.09%

etcd-registry's Introduction

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

If you need a standalone application for registration, see https://github.com/flaviostutz/etcd-registrar

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.