consul

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

docker run -d -p 8500:8500 --restart=always --name=consul consul:latest agent -server -bootstrap -ui -node=1 -client='0.0.0.0'

agent: 表示启动 Agent 进程。

server:表示启动 Consul Server 模式

client:表示启动 Consul Cilent 模式。

bootstrap:表示这个节点是 Server-Leader ,每个数据中心只能运行一台服务器。技术角度上讲 Leader 是通过 Raft 算法选举的,但是集群第一次启动时需要一个引导 Leader,在引导群集后,建议不要使用此标志。

ui:表示启动 Web UI 管理器,默认开放端口 8500,所以上面使用 Docker 命令把 8500 端口对外开放。

node:节点的名称,集群中必须是唯一的,默认是该节点的主机名。

client:consul服务侦听地址,这个地址提供HTTP、DNS、RPC等服务,默认是127.0.0.1所以不对外提供服务,如果你要对外提供服务改成0.0.0.0

join:表示加入到某一个集群中去。 如:-json=192.168.0.11。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIntranetIP

func GetIntranetIP() string

func NewConsulClient

func NewConsulClient(address string) (*api.Client, error)

NewConsulClient ...

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is consul client config

func NewClientX

func NewClientX(cli *api.Client) *Client

NewClientX creates consul client

func (*Client) Deregister

func (d *Client) Deregister(ctx context.Context, serviceID string) error

Deregister deregister service by service ID

func (*Client) LoadJSONFromConsulKV

func (c *Client) LoadJSONFromConsulKV(configKey string, cfg interface{})

LoadJSONFromConsulKV ...

func (*Client) PutKeyValueToConsul

func (c *Client) PutKeyValueToConsul(key string, value []byte)

PutKeyValueToConsul ...

func (*Client) Register

func (d *Client) Register(ctx context.Context, svc *registry.ServiceInstance, enableHealthCheck bool) error

Register register service instacen to consul

func (*Client) Service

func (d *Client) Service(ctx context.Context, service string, index uint64, passingOnly bool) ([]*registry.ServiceInstance, uint64, error)

Service get services from consul

type Config

type Config struct {
	*api.Config
}

Config is consul registry config

type Option

type Option func(*Registry)

Option is consul registry option.

func WithHealthCheck

func WithHealthCheck(enable bool) Option

WithHealthCheck with registry health check option.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is consul registry

func New

func New(xClient *Client, opts ...Option) *Registry

New creates consul registry

func (*Registry) Deregister

func (r *Registry) Deregister(ctx context.Context, svc *registry.ServiceInstance) error

Deregister deregister service

func (*Registry) GetService

func (r *Registry) GetService(ctx context.Context, name string) (services []*registry.ServiceInstance, err error)

GetService return service by name

func (*Registry) ListServices

func (r *Registry) ListServices() (allServices map[string][]*registry.ServiceInstance, err error)

ListServices return service list.

func (*Registry) Register

func (r *Registry) Register(ctx context.Context, svc *registry.ServiceInstance) error

Register register service

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, name string) (registry.Watcher, error)

Watch resolve service by name

Jump to

Keyboard shortcuts

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