subpub

package
v1.2.24041 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// action, &isOk, confMap
	ACTION_BEFORE_CONNECT = 1

	// actioin[,fromaddr[,data]]
	ACTION_CONNECTED = 2

	// action, buf
	ACTION_RECVBUF = 3
	// action, buf
	ACTION_SEND_BUF = 4

	// action, reason
	ACTION_DISCONNECTED = 5

	// ACTION, msg
	ACTION_START = 8

	// action, msg
	ACTION_CLOSE = 9

	// action, err
	ACTION_CONNECTFAIL = 10

	// action, topic, data
	ACTION_RECV_TOPIC_DATA = 11

	// action, err
	ACTION_ERROR   = 21
	ACTION_MESSAGE = 20

	ACTION_CUSTOM = 200

	ACTION_SERVER_BASE = 30

	// action, sessionid, fromaddr[,data]
	ACTION_SERVER_CONN_CONNECTED = ACTION_SERVER_BASE + 1

	// action, sessionid, buf
	ACTION_SERVER_CONN_SEND_BUF = ACTION_SERVER_BASE + 2

	// action, sessionid, buf
	ACTION_SERVER_CONN_RECV_BUF = ACTION_SERVER_BASE + 3

	// action, sessionid, reason
	ACTION_SERVER_CONN_DISCONNECTED = ACTION_SERVER_BASE + 4
)

Variables

View Source
var (
	DefaultPub = NewPubHub()
)
View Source
var (
	DefaultSub = NewSubHub()
)
View Source
var (
	DefaultSubchannel = NewSubchannel()
)
View Source
var (
	DefaultSubscribe = NewSubscribe()
)

Functions

This section is empty.

Types

type IPub added in v1.2.24013

type IPub interface {
	Pub(topic string, max int, args ...interface{}) int
}

type IStatus added in v1.2.24013

type IStatus interface {
	Status() string
}

type ISub added in v1.2.24013

type ISub interface {
	Sub(id, topic string, cb func(id, topic string, args ...interface{}) (ok bool))
}

type ISubPub added in v1.2.24013

type ISubPub interface {
	ISub
	IUnsub
	IPub
}

type IUnsub added in v1.2.24013

type IUnsub interface {
	Unsub(id, topic string) bool
}

type PubHub

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

发布中心 负责创建管理会话对象 注册的方法必须是pub.开头

func NewPubHub

func NewPubHub() *PubHub

func (*PubHub) AddSession

func (this *PubHub) AddSession(sessionid string, conf gobase.StrMap, notifyFn SubFunc) (pub PubSessionIntf, err error)

使用conntype参数, 调用pub.[xxx]注册的方法, 创建一个Pub会话对象

false: 如果sessionid已经存在; conntype参数未注册

func (*PubHub) DelSession

func (this *PubHub) DelSession(sessionid string) bool

关闭移除一个会话

func (*PubHub) Pub

func (this *PubHub) Pub(sessionid string, topic string, max int, args ...interface{}) int

发布数据

type PubSessionIntf

type PubSessionIntf interface {
	Start()
	Close() error

	// 发布数据
	Pub(topic string, max int, args ...interface{}) int
}

创建的Session对象必须要实现的接口方法

type SubFunc added in v1.2.24013

type SubFunc = func(id, topic string, args ...interface{}) (ok bool)

type SubHub

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

订阅中心 负责创建管理会话对象 注册的方法必须是sub.开头

func NewSubHub

func NewSubHub() *SubHub

func (*SubHub) AddSession

func (this *SubHub) AddSession(sessionid string, conf gobase.StrMap, fn SubFunc) error

func (*SubHub) ConfigDefaultConnType added in v1.2.24013

func (this *SubHub) ConfigDefaultConnType(s string)

func (*SubHub) DelSession

func (this *SubHub) DelSession(sessionid string) bool

func (*SubHub) PostData

func (this *SubHub) PostData(sessionid string, args ...interface{}) error

func (*SubHub) Status added in v1.2.24013

func (this *SubHub) Status() string

type SubSessionIntf

type SubSessionIntf interface {
	Start()
	Close() error
	PostData(args ...interface{}) error
}

type Subchannel added in v1.2.24013

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

订阅中心, 订阅和取消订阅的效率比subscribe快很多 订阅主题 Sub消息通道不支持通配符

func NewSubchannel added in v1.2.24013

func NewSubchannel() *Subchannel

func (*Subchannel) CleanChannels added in v1.2.24013

func (this *Subchannel) CleanChannels() (cnt int)

清理一些超时10分钟没有发布消息的通道

func (*Subchannel) Close added in v1.2.24013

func (this *Subchannel) Close() error

func (*Subchannel) ClosePubChannel added in v1.2.24013

func (this *Subchannel) ClosePubChannel(channel string) (closed bool)

释放通道

func (*Subchannel) GetChannelCount added in v1.2.24013

func (this *Subchannel) GetChannelCount() int

func (*Subchannel) GetChannelSessionCount added in v1.2.24013

func (this *Subchannel) GetChannelSessionCount(channel string) int

func (*Subchannel) Pub added in v1.2.24013

func (this *Subchannel) Pub(channel string, max int, args ...interface{}) int

0:发布数据失败

func (*Subchannel) Status added in v1.2.24013

func (this *Subchannel) Status() string

func (*Subchannel) Sub added in v1.2.24013

func (this *Subchannel) Sub(id, channel string, cb SubFunc)

channel不能为空

func (*Subchannel) Unsub added in v1.2.24013

func (this *Subchannel) Unsub(id, channel string) bool

type Subscribe added in v1.2.24013

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

订阅中心, 订阅主题:支持通配符/news/+/qq, 将会收到匹配的的通道消息 PUB消息通道不支持通配符

func NewSubscribe added in v1.2.24013

func NewSubscribe() *Subscribe

func NewSubscribeEx added in v1.2.24013

func NewSubscribeEx(routeParseFunc func(topic string) interface{}, routeMatchFunc func(route interface{}, topic interface{}) bool) *Subscribe

func (*Subscribe) CleanChannels added in v1.2.24013

func (this *Subscribe) CleanChannels() (cnt int)

清理一些超时10分钟没有发布消息的通道

func (*Subscribe) Close added in v1.2.24013

func (this *Subscribe) Close() error

func (*Subscribe) ClosePubChannel added in v1.2.24013

func (this *Subscribe) ClosePubChannel(channel string) (closed bool)

释放通道

func (*Subscribe) Count added in v1.2.24013

func (this *Subscribe) Count() int

func (*Subscribe) GetTopicSubCount added in v1.2.24013

func (this *Subscribe) GetTopicSubCount(topic string) int

func (*Subscribe) Pub added in v1.2.24013

func (this *Subscribe) Pub(channel string, max int, args ...interface{}) int

>1 投递成功max次后停止 循环map

utils_subscribe_v2._test.go:168: 34228, 6844/s
utils_subscribe_v2._test.go:168: 68952, 6894/s

循环lst

utils_subscribe_v2._test.go:168: 35343, 6977/s
utils_subscribe_v2._test.go:168: 71194, 7072/s

向主题订阅者推送数据 topic推送的主题 max最大接收者,超过该值不再进行推送

func (*Subscribe) Status added in v1.2.24013

func (this *Subscribe) Status() string

func (*Subscribe) StatusDetail added in v1.2.24013

func (this *Subscribe) StatusDetail() string

func (*Subscribe) Sub added in v1.2.24013

func (this *Subscribe) Sub(id, topic string, cb SubFunc)

订阅一个主题

topic订阅主题,为空不进行订阅 id订阅者id,topic 下id重复将会被覆盖(之前订阅失效)

func (*Subscribe) TopicCount added in v1.2.24013

func (this *Subscribe) TopicCount() int

func (*Subscribe) Unsub added in v1.2.24013

func (this *Subscribe) Unsub(id, topic string) bool

取消订阅 id 订阅时传入的id topic订阅的主题

Jump to

Keyboard shortcuts

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