service_manager

package module
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

service_manager

服务管理系统 基于zookeeper

开始使用

服务生产者

import "github.com/ZR233/service_manager"

//zookeeper集群地址
zkHosts = ["192.168.0.2:2181", "192.168.0.3:2181"]
//服务名称
serviceName = "test_project/auth"
//服务地址
serviceHost = "localhost:9999"
service = service_manager.NewService(serviceName,
                          		serviceHost,
                          		zkHosts)
//服务注册,此函数不会阻塞
service.Open()

if err != nil {
    panic(err)
}
//服务注销
defer service.Close()

服务消费者

import "github.com/ZR233/service_manager"

zkHosts = ["192.168.0.2:2181", "192.168.0.3:2181"]
serviceName = "test_project/auth"
consumer = service_manager.NewConsumer(serviceName, zkHosts)
//Run()函数不会阻塞
consumer.Run()

address, err := consumer.GetServiceHost()
if err != nil {
    return
}

Documentation

Overview

@Time : 2019-10-08 16:28 @Author : zr

@Time : 2019-10-08 11:06 @Author : zr

@Time : 2019-10-14 10:16 @Author : zr

@Time : 2019-10-08 16:18 @Author : zr

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoService                 = errors.New("no service")
	ErrNoServiceAlive            = errors.New("no service alive")
	ErrHost                      = errors.New("host error")
	ErrConnectToZooKeeper        = zk.ErrNoServer
	ErrInvalidPath               = zk.ErrInvalidPath
	ErrSingletonServiceIsRunning = errors.New("service type is singleton and there is one already running")
)

Functions

func GRpcConnTest added in v1.1.0

func GRpcConnTest() pool.ConnTestFunc

func GetCurrentPath added in v1.1.1

func GetCurrentPath() (string, error)

Types

type ConnFactory added in v1.1.0

type ConnFactory func(host string) (io.Closer, error)

func GRpcFactory added in v1.1.0

func GRpcFactory() ConnFactory

type Consumer added in v1.0.1

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

func (*Consumer) Close added in v1.0.2

func (c *Consumer) Close()

func (*Consumer) GetConn added in v1.1.0

func (c *Consumer) GetConn() (conn io.Closer, err error)

func (*Consumer) Open added in v1.0.1

func (c *Consumer) Open() (err error)

func (*Consumer) ReleaseConn added in v1.1.0

func (c *Consumer) ReleaseConn(conn io.Closer)

type ConsumerOption added in v1.1.0

type ConsumerOption interface {
	// contains filtered or unexported methods
}

type ConsumerOptionConnFactory added in v1.1.0

type ConsumerOptionConnFactory ConnFactory

type ConsumerOptionConnMax added in v1.1.0

type ConsumerOptionConnMax int

type ConsumerOptionConnMin added in v1.1.0

type ConsumerOptionConnMin int

type ConsumerOptionConnTestFunc added in v1.1.0

type ConsumerOptionConnTestFunc pool.ConnTestFunc

type Logger added in v1.0.3

type Logger interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Panic(args ...interface{})
}

type Manager added in v1.0.1

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

func NewManager added in v1.0.1

func NewManager(hosts []string) *Manager

func (*Manager) Close added in v1.1.0

func (m *Manager) Close() error

func (*Manager) NewConsumer added in v1.1.0

func (m *Manager) NewConsumer(service *Service, options ...ConsumerOption) (c *Consumer, err error)

func (*Manager) NewProducer added in v1.1.0

func (m *Manager) NewProducer(service *Service, port int, options ...ProducerOption) (producer *Producer, err error)

func (*Manager) NewService added in v1.1.0

func (m *Manager) NewService(sPath string, options ...ServiceOption) *Service

func (*Manager) RunSync added in v1.1.0

func (m *Manager) RunSync() (err error)

func (*Manager) SetLogger added in v1.1.0

func (m *Manager) SetLogger(logger Logger)

type NodeInfo added in v1.1.0

type NodeInfo struct {
	Pid      int
	Host     string
	HostName string
	Port     int
	ExecPath string
	// contains filtered or unexported fields
}

type NodeRunningError added in v1.1.0

type NodeRunningError struct {
	RunningHost string
	Err         error
}

func (*NodeRunningError) Error added in v1.1.0

func (e *NodeRunningError) Error() string

func (*NodeRunningError) Unwrap added in v1.1.0

func (e *NodeRunningError) Unwrap() error

type OptionHost added in v1.1.0

type OptionHost string

ipv6 地址 格式为 [::1234]

type Producer added in v1.1.0

type Producer struct {

	//public:
	NodeInfo
	// contains filtered or unexported fields
}

func (*Producer) Close added in v1.1.0

func (p *Producer) Close() error

func (*Producer) Open added in v1.1.0

func (p *Producer) Open() (err error)

func (*Producer) Status added in v1.1.0

func (p *Producer) Status() Status

type ProducerOption added in v1.1.0

type ProducerOption interface {
	// contains filtered or unexported methods
}

type Protocol added in v1.1.0

type Protocol int
const (
	ProtocolGRPC Protocol = iota
	ProtocolHttp
	ProtocolThrift
)

func (Protocol) String added in v1.1.0

func (p Protocol) String() string

type Service

type Service struct {
	Path     string `json:"-"`
	Protocol Protocol
	Type     ServiceType
}

type ServiceOption added in v1.1.0

type ServiceOption interface {
	// contains filtered or unexported methods
}

type ServiceOptionProtocol added in v1.1.0

type ServiceOptionProtocol Protocol

type ServiceOptionServiceType added in v1.1.0

type ServiceOptionServiceType ServiceType

type ServiceType added in v1.1.0

type ServiceType int
const (
	ServiceTypeNormal    ServiceType = iota
	ServiceTypeSingleton             //只允许运行一个实例
)

func (ServiceType) String added in v1.1.0

func (s ServiceType) String() string

type Status added in v1.1.0

type Status int
const (
	StatusInit Status = iota
	StatusOpen
	StatusOpenSuccess
	StatusReady
	StatusZkConnected
	StatusStopping
	StatusStopped
)

type ZKError added in v1.1.0

type ZKError struct {
	Msg string
	Err error
}

func (*ZKError) Error added in v1.1.0

func (z *ZKError) Error() string

func (*ZKError) Unwrap added in v1.1.0

func (z *ZKError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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