subscribe

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: MIT Imports: 16 Imported by: 0

README

订阅协议实现

Documentation

Index

Constants

View Source
const (
	CMD_SET_PRO = iota // 注册客户端操作,加入到指定分组
	CMD_AUTH           // 认证(暂未使用)
	CMD_ERROR          // 错误响应
	CMD_TICK           // 心跳包
	CMD_EVENT          // 事件
	CMD_AGENT
	CMD_STOP
	CMD_RELOAD
	CMD_SHOW_MEMBERS
	CMD_POS
)
View Source
const (
	FlagSetPro = iota
	FlagPing
)
View Source
const (
	Registered = 1 << iota
)

服务注册

View Source
const ServiceName = "wing-binlog-go-subscribe"

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseFunc

type CloseFunc func()

type KeepaliveFunc

type KeepaliveFunc func(data []byte)

type NodeFunc

type NodeFunc func(n *tcpClientNode)

type NodeOption

type NodeOption func(n *tcpClientNode)

func NodeClose

func NodeClose(f NodeFunc) NodeOption

type OnConnectFunc

type OnConnectFunc func(conn *net.Conn)

type OnLeaderFunc

type OnLeaderFunc func(bool)

type OnRemoveFunc

type OnRemoveFunc func(conn *net.Conn)

type ReloadFunc

type ReloadFunc func()

type SendAllFunc

type SendAllFunc func(table string, data []byte) bool

type SendRawFunc

type SendRawFunc func(msg []byte)

type Service

type Service struct {
	ServiceName string //service name, like: service.add
	ServiceHost string //service host, like: 0.0.0.0, 127.0.0.1
	ServiceIp   string // if ServiceHost is 0.0.0.0, ServiceIp must set,
	// like 127.0.0.1 or 192.168.9.12 or 114.55.56.168
	ServicePort int           // service port, like: 9998
	Interval    time.Duration // interval for update ttl
	Ttl         int           //check ttl
	ServiceID   string        //serviceID = fmt.Sprintf("%s-%s-%d", name, ip, port)

	Kv *consul.KV
	// contains filtered or unexported fields
}

func NewService

func NewService(
	host string,
	port int,
	consulAddress string,
	opts ...ServiceOption) *Service

new a service name: service name host: service host like 0.0.0.0 or 127.0.0.1 port: service port, like 9998 consulAddress: consul service address, like 127.0.0.1:8500 opts: ServiceOption, like ServiceIp("127.0.0.1") return new service pointer

func (*Service) Close

func (sev *Service) Close()

func (*Service) Deregister

func (sev *Service) Deregister() error

func (*Service) Register

func (sev *Service) Register() error

type ServiceOption

type ServiceOption func(s *Service)

func Interval

func Interval(interval time.Duration) ServiceOption

set interval

func ServiceIp

func ServiceIp(serviceIp string) ServiceOption

set service ip

func Ttl

func Ttl(ttl int) ServiceOption

set ttl

type SetProFunc

type SetProFunc func(n *tcpClientNode, groupName string) bool

type TcpConfig

type TcpConfig struct {
	Listen        string `toml:"listen"` //like 0.0.0.0:9996
	Enable        bool   `toml:"enable"` //service enable
	ConsulAddress string `toml:"consul_address"`
	ConsulEnable  bool   `toml:"consul_enable"`
}

type TcpGroupsOptions

type TcpGroupsOptions func(groups *tcpGroups)

func SetOnRemove

func SetOnRemove(f OnRemoveFunc) TcpGroupsOptions

type TcpService

type TcpService struct {
	service.Service
	Listen string // 监听ip

	Enable bool
	// contains filtered or unexported fields
}

func NewSubscribeService

func NewSubscribeService(ctx *app.Context) *TcpService

func (*TcpService) Close

func (tcp *TcpService) Close()

func (*TcpService) Name

func (tcp *TcpService) Name() string

func (*TcpService) Reload

func (tcp *TcpService) Reload()

func (*TcpService) SendAll

func (tcp *TcpService) SendAll(table string, data []byte) bool

send event data to all connects client

func (*TcpService) SendRaw

func (tcp *TcpService) SendRaw(msg []byte) bool

send raw bytes data to all connects client msg is the pack frame form func: pack

func (*TcpService) Start

func (tcp *TcpService) Start()

type TcpServiceOption

type TcpServiceOption func(service *TcpService)

func SetKeepalive

func SetKeepalive(f KeepaliveFunc) TcpServiceOption

func SetOnClose

func SetOnClose(f CloseFunc) TcpServiceOption

func SetOnConnect

func SetOnConnect(f OnConnectFunc) TcpServiceOption

func SetReload

func SetReload(f ReloadFunc) TcpServiceOption

func SetSendAll

func SetSendAll(f SendAllFunc) TcpServiceOption

func SetSendRaw

func SetSendRaw(f SendRawFunc) TcpServiceOption

Jump to

Keyboard shortcuts

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