datacenterbridge

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 15 Imported by: 0

README

datacenter-bridge (dcb)

multiple datacenters bridge direct connection go library.

多区域数据中心建立直通桥, 进行跨区域收发数据.

功能设计

  • [ + ] 服务发现(ServiceDiscovery)
    • [ x ] consul
    • [ x ] etcd
    • redis
  • [ + ] 桥通信(BridgeChannel)
    • [ x ] websocket(s)
    • [ x ] quic
    • http(s)
    • tcp(tls)
    • p2p
    • mqtt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChannelNotFound = errors.New("channel not found")
View Source
var ErrNoDiscovery = errors.New("no discovery")
View Source
var ErrNoServer = errors.New("no server")
View Source
var SWG = sync.WaitGroup{}

SWG -

Functions

func NewSelf

func NewSelf(zone, service, id string) *discovery.Service

NewSelf -

Types

type AppConfigure

type AppConfigure struct {
	AppInfo `yaml:",inline"`
	Mode    string `yaml:"mode" json:"mode" comment:"运行模式"`

	Log       logger.LogConfigure `yaml:"log" json:"log" comment:"日志配置"`
	Servers   ServerConfigure     `yaml:"servers" json:"servers" comment:"服务列表"`
	Discovery DiscoveryConfigure  `yaml:"discovery" json:"discovery" comment:"服务发现"`
}

type AppInfo

type AppInfo struct {
	Zone    string `yaml:"zone" json:"zone" comment:"区域:cn-001"`
	Service string `yaml:"service" json:"service" comment:"服务类别:gw-dcb-service"`
	Id      string `yaml:"id" json:"id" comment:"服务Id:gw-node1"`
}

AppInfo - local app info.

type ChannelList

type ChannelList struct {
	Info map[string][]channel.ChannelInfo `json:"info" comment:"桥通道服务列表"`
}

func (ChannelList) String

func (l ChannelList) String() string

type ClosedChannel added in v0.0.2

type ClosedChannel func(ch channel.Channel)

type Configure

type Configure struct {
	AppConfigure `yaml:"app" json:"app" comment:"应用配置"`
}

Configure -

func LoadConfigure

func LoadConfigure(configFile string) (*Configure, error)

LoadConfigure - load configure from file.

func NewConfigure

func NewConfigure() *Configure

NewConfigure -

func (Configure) Check

func (c Configure) Check(server bool) error

Check - check configure.

func (Configure) Register

func (c Configure) Register() *discovery.Service

Register - etcd use.

func (Configure) Self

func (c Configure) Self() *discovery.Service

func (Configure) String

func (c Configure) String() string

type ConsulConfigure

type ConsulConfigure struct {
	Up    bool   `yaml:"up" json:"up" comment:"是否启用"`
	Host  string `yaml:"host" json:"host" comment:"http://Ip:Port"`
	Token string `yaml:"token" json:"token" comment:"acl认证"`
}

ConsulConfigure-

type DCenterBridge

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

DCenterBridge - 区域桥通道.

func NewDCenterBridge

func NewDCenterBridge(ctx context.Context, done chan bool, config *Configure) *DCenterBridge

NewDCenterBridge -

func (*DCenterBridge) ChannelsLoop

func (dc *DCenterBridge) ChannelsLoop(channelMsg GetChannelMsg, channelClosed ClosedChannel) error

ChannelsLoop -

func (*DCenterBridge) CreateChannel

func (dc *DCenterBridge) CreateChannel(zone, serviceName, id string) (channel.Channel, error)

CreateChannel - 创建桥通道.

func (*DCenterBridge) CreateChannelForTest

func (dc *DCenterBridge) CreateChannelForTest(zone, serviceName, id, host string) (channel.Channel, error)

func (*DCenterBridge) DeleteChannel

func (dc *DCenterBridge) DeleteChannel(zone, serviceName, id string) error

func (*DCenterBridge) DiscoveryServers added in v0.0.5

func (dc *DCenterBridge) DiscoveryServers(zone, service string) ([]discovery.Service, error)

func (*DCenterBridge) GetChannelList

func (dc *DCenterBridge) GetChannelList() ChannelList

GetChannelList -

func (*DCenterBridge) GetListenerList

func (dc *DCenterBridge) GetListenerList() ListenerList

func (*DCenterBridge) ListenAndServe

func (dc *DCenterBridge) ListenAndServe() error

ListenAndServe -

func (*DCenterBridge) SendData

func (dc *DCenterBridge) SendData(zone, serviceName string, data []byte) error

SendData -

func (*DCenterBridge) WaitQuit

func (dc *DCenterBridge) WaitQuit()

WaitQuit -

type Datacenter

type Datacenter interface {
	ListenAndServe() error // 启动服务监听.
	WaitQuit()             // 等待退出.

	ChannelsLoop(GetChannelMsg, ClosedChannel) error // client loop.

	DiscoveryServers(zone, service string) ([]discovery.Service, error) // 发现桥通道:区域|服务名称.

	CreateChannel(zone, service, id string) (channel.Channel, error) // 创建桥通道:区域|服务名称.
	DeleteChannel(zone, service, id string) error                    // 删除桥通道:区域|服务名称.
	SendData(zone, service string, data []byte) error                // 发送数据:区域|服务名称|数据.

	CreateChannelForTest(zone, service, id, host string) (channel.Channel, error) // for test, no use production.

	GetChannelList() ChannelList   // 获取桥通道列表.
	GetListenerList() ListenerList // 获取监听服务列表.

}

Datacenter - datacenter bridge interface.

func NewDCenterBridgeWithClient

func NewDCenterBridgeWithClient(ctx context.Context, done chan bool, self AppInfo, options ...interface{}) Datacenter

NewDCenterBridgeWithClient - client use.

func NewDCenterBridgeWithServer

func NewDCenterBridgeWithServer(ctx context.Context, done chan bool, self AppInfo, options ...interface{}) Datacenter

NewDCenterBridge - server use.

type DiscoveryConfigure

type DiscoveryConfigure struct {
	Consul ConsulConfigure `yaml:"consul" json:"consul" comment:"Consul服务发现"`
	Etcd   EtcdConfigure   `yaml:"etcd" json:"etcd" comment:"Etcd服务发现"`
}

DiscoveryConfigure -

type EtcdConfigure

type EtcdConfigure struct {
	Up         bool     `yaml:"up" json:"up" comment:"是否启用"`
	Endpoints  []string `yaml:"endpoints" json:"endpoints" comment:"[]Ip:Port"`
	Prefix     string   `yaml:"prefix" json:"prefix" comment:"service prefix /dcbridge."`
	GrantedTTL int64    `yaml:"ttl" json:"ttl" comment:"service granted ttl in seconds"`
}

type GetChannelMsg

type GetChannelMsg func(ch channel.Channel, data []byte)

GetChannelMsg - get bridge channel message.

type ListenerList

type ListenerList struct {
	Self    AppInfo  `json:"app" comment:"本地服务信息"`
	Listens []string `json:"listens" comment:"监听地址列表"`
}

ListenerList -

func (ListenerList) String

func (l ListenerList) String() string

type QuicConfigure

type QuicConfigure struct {
	Up         bool   `yaml:"up" json:"up" comment:"是否启用"`
	Host       string `yaml:"host" json:"host" comment:"quic://Ip:Port"`
	CertFile   string `yaml:"certfile" json:"certfile" comment:"certfile"`
	KeyFile    string `yaml:"keyfile" json:"keyfile" comment:"keyfile"`
	QueueSize  int    `yaml:"queueSize" json:"queueSize" comment:"队列大小"`
	BufferSize int    `yaml:"bufferSize" json:"bufferSize" comment:"缓存大小"`
}

func (QuicConfigure) To

func (s QuicConfigure) To() *quic.QuicConfig

To -

type ServerConfigure

type ServerConfigure struct {
	Ws   WebsocketConfigure  `yaml:"ws" json:"ws" comment:"Ws服务配置"`
	Wss  WebsocketsConfigure `yaml:"wss" json:"wss" comment:"Wss服务配置"`
	Quic QuicConfigure       `yaml:"quic" json:"quic" comment:"Quic服务配置"`
}

ServerConfigure -

type WebsocketConfigure

type WebsocketConfigure struct {
	Up   bool   `yaml:"up" json:"up" comment:"是否启用"`
	Host string `yaml:"host" json:"host" comment:"ws://Ip:Port/bridge"`
	// Prefix string `yaml:"prefix" json:"prefix" comment:"uri prefix"`
	QueueSize  int `yaml:"queueSize" json:"queueSize" comment:"队列大小"`
	BufferSize int `yaml:"bufferSize" json:"bufferSize" comment:"缓存大小"`
}

WebsocketConfigure -

func (WebsocketConfigure) To

To -

type WebsocketsConfigure

type WebsocketsConfigure struct {
	Up         bool   `yaml:"up" json:"up" comment:"是否启用"`
	Host       string `yaml:"host" json:"host" comment:"ws://Ip:Port/bridge"`
	CertFile   string `yaml:"certfile" json:"certfile" comment:"certfile"`
	KeyFile    string `yaml:"keyfile" json:"keyfile" comment:"keyfile"`
	QueueSize  int    `yaml:"queueSize" json:"queueSize" comment:"队列大小"`
	BufferSize int    `yaml:"bufferSize" json:"bufferSize" comment:"缓存大小"`
}

WebsocketsConfigure -

func (WebsocketsConfigure) To

To -

Directories

Path Synopsis
examples
app command
client command
server command

Jump to

Keyboard shortcuts

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