mqtt

package
v1.18.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TopicGroup = "default"
)

Variables

View Source
var (
	ErrPublishTimeout = errors.New("mqtt publish wait timeout")
)
View Source
var WithAuth = func(username, password string) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.SetUsername(username)
		if len(password) > 0 {
			options = options.SetPassword(password)
		}
		return options
	}
}
View Source
var WithBroker = func(broker string, others ...string) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.AddBroker(broker)
		for _, b := range others {
			options = options.AddBroker(b)
		}
		return options
	}
}
View Source
var WithClientId = func(clientId string) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.SetClientID(clientId)
		return options
	}
}
View Source
var WithOnConnectHandler = func(h proxy.OnConnectHandler) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.SetOnConnectHandler(h)
		return options
	}
}
View Source
var WithOnLostHandler = func(h proxy.ConnectionLostHandler) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.SetConnectionLostHandler(h)
		return options
	}
}
View Source
var WithRandomClientId = func() ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.SetClientID(util.UUIDString())
		log.Debug("ClientId:%s", options.ClientID)
		return options
	}
}
View Source
var WithSessionControl = func(keepAlive, pingTimeout, writeTimeout time.Duration) ClientOption {
	return func(options *proxy.ClientOptions) *proxy.ClientOptions {
		options = options.
			SetKeepAlive(keepAlive).
			SetPingTimeout(pingTimeout).
			SetWriteTimeout(writeTimeout)
		return options
	}
}

Functions

func TopicBuilder added in v1.12.2

func TopicBuilder(opt BuilderOption, format string, key ...any) (t string)

func TopicResolver added in v1.12.2

func TopicResolver(tpl string, topic string) (res map[string]string, err error)

Types

type BuilderOption added in v1.12.2

type BuilderOption struct {
	Share bool   // 是否共享topic
	Tpl   bool   // true: /a/b/{c}/d  false:/a/b/c/d
	Group string // group名称, 默认default
}

type ClientOption

type ClientOption func(*proxy.ClientOptions) *proxy.ClientOptions

type Session

type Session interface {
	Connect() error
	Publish(topic string, qos byte, retained bool, data []byte) error
	Subscribe(handler func(topic string, payload []byte), qos byte, topic string) error
	Unsubscribe(topics ...string)
}

func New

func New(ctx context.Context, options ...ClientOption) Session

Jump to

Keyboard shortcuts

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