Service registration and discovery, support etcd, zookeeper, consul, etc.

discox

支持类型

  • zookeeper
  • etcd
  • consul

示例

zookeeper

server

package main

import (
	"fmt"
	"github.com/goeasya/discox"
	"os"
)

func main() {
	cfg := discox.RegisterConfig{
		BackendType:      discox.ZookeeperBackend,
		BackendEndPoints: []string{"10.1.1.1:2181"},
		DiscoverPrefix:   "/soaservices",
		ServiceName:      "demo",
		HeartBeatPeriod:  5,
		ServiceEndPoint:  "127.0.0.1:8111",
	}
	service, err := discox.NewRegister(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = service.Start(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	defer service.Stop()
	select {}
}

client

package main

import (
	"fmt"
	"github.com/goeasya/discox"
	"os"
	"time"
)

func main() {
	timer := time.NewTimer(time.Second * 5)
	cfg := discox.DiscoverConfig{
		BackendEndPoints: []string{"10.1.1.1:2181"},
		BackendType:      discox.ZookeeperBackend,
		DiscoverPrefix:   "/soaservices",
		ServiceName:      "demo",
	}
	server, err := discox.NewDiscover(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	endpointCacher := discox.NewLiteEndpoint()
	go server.Start(endpointCacher)
	defer server.Stop()

	for {
		select {
		case <-timer.C:
			fmt.Println("time 5 seconds")
			endpoints := endpointCacher.List()
			fmt.Println(endpoints, len(endpoints))
			timer.Reset(time.Second * 5)
		}
	}
}

etcd

server

package main

import (
	"fmt"
	"os"
	
	"github.com/goeasya/discox"
)

func main() {
	cfg := discox.RegisterConfig{
		BackendType:      discox.EtcdBackend,
		BackendEndPoints: []string{"http://10.1.1.1:23790"},
		DiscoverPrefix:   "/discox/etcddemo",
		ServiceName:      "demo",
		HeartBeatPeriod:  5,
		ServiceEndPoint:  "127.0.0.1:8111",
	}
	service, err := discox.NewRegister(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = service.Start(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	defer service.Stop()
	select {}
}

client

package main

import (
	"fmt"
	"os"
	"time"
	
	"github.com/goeasya/discox"
)

func main() {
	timer := time.NewTimer(time.Second * 5)
	cfg := discox.DiscoverConfig{
		BackendEndPoints: []string{"http://10.1.1.1:23790"},
		BackendType:      discox.EtcdBackend,
		DiscoverPrefix:   "/discox/etcddemo",
		ServiceName:      "demo",
	}
	server, err := discox.NewDiscover(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	endpointCacher := discox.NewLiteEndpoint()
	go server.Start(endpointCacher)
	defer server.Stop()

	for {
		select {
		case <-timer.C:
			fmt.Println("time 5 seconds")
			endpoints := endpointCacher.List()
			fmt.Println(endpoints, len(endpoints))
			timer.Reset(time.Second * 5)
		}
	}
}

consul

server

package main

import (
	"fmt"
	"net/http"
	"os"
	
	"github.com/goeasya/discox"
)

func main() {
	cfg := discox.RegisterConfig{
		BackendType:         discox.ConsulBackend,
		BackendEndPoints:    []string{"consul.test.com"},
		DiscoverPrefix:      "/soaservices",
		ServiceName:         "demo",
		HeartBeatPeriod:     5,
		ServiceEndPoint:     "172.18.1.1:8080",
		HealthCheckEndPoint: "172.18.1.1:8080/check",
	}
	service, err := discox.NewRegister(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = service.Start(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	http.HandleFunc("/check", consulCheck)
	go http.ListenAndServe(":8080", nil)
	defer service.Stop()
	select {}

}

var count int64

func consulCheck(w http.ResponseWriter, r *http.Request) {

	s := "consulCheck" + fmt.Sprint(count) + "remote:" + r.RemoteAddr + " " + r.URL.String()
	fmt.Println(s)
	fmt.Fprintln(w, s)
	count++
}

client

package main

import (
	"fmt"
	"os"
	"time"
	
	"github.com/goeasya/discox"
)

func main() {
	timer := time.NewTimer(time.Second * 5)
	cfg := discox.DiscoverConfig{
		BackendEndPoints: []string{"consul.test.com"},
		BackendType:      discox.ConsulBackend,
		DiscoverPrefix:   "/soaservices",
		ServiceName:      "demo",
	}
	server, err := discox.NewDiscover(&cfg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	endpointCacher := discox.NewLiteEndpoint()
	go server.Start(endpointCacher)
	defer server.Stop()

	for {
		select {
		case <-timer.C:
			fmt.Println("time 5 seconds")
			endpoints := endpointCacher.List()
			fmt.Println(endpoints, len(endpoints))
			timer.Reset(time.Second * 5)
		}
	}
}
Similar Resources

golang consul tools

中文文档 consult A consul key/value tool for golang Usage install go get -u github.com/xxjwxc/consult@master New Config conf := consulkv.NewConfig() With

Mar 6, 2022

Consul K/V Store Implementation For Go

Consul K/V Store Implementation For Go

Consul K/V Store Implementation For Go Enables Consul to be used as a configuration source in go applications Dynamic Configuration with Consul's Key/

Jun 7, 2022

Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service.

Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service. Program can take large input files.

Feb 6, 2022

A rate limiter for Golang, with ETCD data bindings

Go Rate limiter This package allows us to have a distributed rate limiter, using Redis as a central counter. The limits that are set are only "soft" l

Dec 9, 2021

Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Fast passive subdomain enumeration tool. Features • Install • Usage • API Setup • License • Join Discord Subfinder is a subdomain discovery tool that

Jan 4, 2023

Libp2p chat with discovery and pubsub

Dicovery - pubsub chat with libp2p How to test Run boostrap node $ go run main/main.go --port 35005 --nick boot --pk XDLjuaVJ2yKQ2zHMmsee5PGHtDHmkkvFA

Jul 3, 2022

CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed.

CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed.

CoreRAD CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed. To get started with

Nov 14, 2022

Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman:

Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman:

peerdiscovery Pure-go library for cross-platform thread-safe local peer discovery using UDP multicast. I needed to use peer discovery for croc and eve

Jan 8, 2023

Data Availability Sampling (DAS) on a Discovery-v5 DHT overlay

Implementing Data Availability Sampling (DAS) There's a lot of history to unpack here. Vitalik posted about the "Endgame": where ethereum could be hea

Nov 12, 2022
Related tags
A service registry and service discovery implemention for kitex based on etcd

kitex etcd Introduction kitexetcd is an implemention of service registry and service discovery for kitex based on etcd. Installation go get -u github.

Feb 18, 2022
zk2etcd 是一款同步 zookeeper 数据到 etcd 的工具
zk2etcd 是一款同步 zookeeper 数据到 etcd 的工具

zk2etcd zk2etcd 是一款同步 zookeeper 数据到 etcd 的工具 项目背景 在云原生大浪潮下,业务都逐渐上 k8s,许多业务以前使用 zookeeper 作为注册中心,现都逐渐倾向更加贴近云原生的 etcd。 在业务向云原生迁移改造的过程中,可能需要将 zookeeper 中

Sep 1, 2022
Use Consul to do service discovery, use gRPC +kafka to do message produce and consume. Use redis to store result.
Use  Consul to do service discovery, use gRPC +kafka to do message produce and consume. Use redis to store result.

目录 gRPC/consul/kafka简介 gRPC+kafka的Demo gRPC+kafka整体示意图 限流器 基于redis计数器生成唯一ID kafka生产消费 kafka生产消费示意图 本文kafka生产消费过程 基于pprof的性能分析Demo 使用pprof统计CPU/HEAP数据的

Jul 9, 2022
Jun 20, 2022
Check DNS and optionally Consul and serve the status from a Web page

dns-checker Table of contents Preamble Compiling the program Keepalived and LVS Available options Setting up systemd Preamble This application checks

Nov 7, 2021
Envoy-eds-server - Envoy EDS server is a working Envoy Discovery Service implementation

envoy-eds-server Intro Envoy EDS server is a working Envoy Discovery Service imp

Apr 2, 2022
DNS service discovery library for Go

Discovery DNS service discovery library for Go Documentation see pkg.go.dev Installation

Mar 10, 2022
Kong and Consul Lab For Golang

Kong and Consul Lab Prerequisites docker Deploy Consul Server docker run -d -p 8500:8500 -p 8600:8600/udp --name=consul-server consul agent -server -u

Nov 25, 2021
Consul Load-Balancing made simple
Consul Load-Balancing made simple

Notes From release 1.5.15 onward, fabio changes the default GOGC from 800 back to the golang default of 100.

Dec 27, 2022
Consul Load-Balancing made simple
Consul Load-Balancing made simple

Notes From release 1.5.15 onward, fabio changes the default GOGC from 800 back to the golang default of 100. Apparently this made some sense back in t

Dec 31, 2022