service

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package service provides the MQTT Server and Client services in a library form. See Server and Client examples below for more detailed usage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConnectionType  error = errors.New("service: Invalid connection type")
	ErrInvalidSubscriber      error = errors.New("service: Invalid subscriber")
	ErrBufferNotReady         error = errors.New("service: buffer is not ready")
	ErrBufferInsufficientData error = errors.New("service: buffer has insufficient data.") //缓冲区数据不足。
)
View Source
var SVC *service

Functions

func QUICBuffConfigInit

func QUICBuffConfigInit(bufferSize, readBlockSize, writeBlockSize uint64)

buff 配置设置

Types

type OnCompleteFunc

type OnCompleteFunc func(msg, ack message.Message, err error) error

完成的回调方法

type OnPublishFunc

type OnPublishFunc func(msg *message.PublishMessage) error

type SafeMap

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

func NewSafeMap

func NewSafeMap() *SafeMap

func (*SafeMap) Get

func (sm *SafeMap) Get(k uint16) (v interface{}, exist bool)

func (*SafeMap) Set

func (sm *SafeMap) Set(k uint16, v interface{}) (interface{}, bool)

之前存在返回false,不会替换 存在返回旧数据,不存在存入,并返回新数据

type Server

type Server struct {
	Version string // 服务版本
	// The number of seconds to keep the connection live if there's no data.
	// If not set then default to 5 mins.
	//如果没有数据,保持连接的秒数。
	//如果没有设置,则默认为5分钟。
	KeepAlive int

	// The number of seconds to wait for the CONNECT message before disconnecting.
	// If not set then default to 2 seconds.
	//在断开连接之前等待连接消息的秒数。
	//如果没有设置,则默认为2秒。
	ConnectTimeout int

	// The number of seconds to wait for any ACK messages before failing.
	// If not set then default to 20 seconds.
	//失败前等待ACK消息的秒数。
	//如果没有设置,则默认为20秒。
	AckTimeout int

	// The number of times to retry sending a packet if ACK is not received.
	// If no set then default to 3 retries.
	//如果没有收到ACK,重试发送数据包的次数。
	//如果没有设置,则默认为3次重试。
	TimeoutRetries int

	// Authenticator is the authenticator used to check username and password sent
	// in the CONNECT message. If not set then default to "mockSuccess".
	// Authenticator是验证器,用于检查发送的用户名和密码
	//在连接消息中。如果不设置,则默认为"mockSuccess"
	Authenticator string

	// SessionsProvider is the session store that keeps all the Session objects.
	// This is the store to check if CleanSession is set to 0 in the CONNECT message.
	// If not set then default to "mem".
	// SessionsProvider是保存所有会话对象的会话存储。
	//这是用于检查在连接消息中是否将清洗设置为0的存储。
	//如果没有设置,则默认为"mem"。
	SessionsProvider string

	// TopicsProvider is the topic store that keeps all the subscription topics.
	// If not set then default to "mem".
	// TopicsProvider是保存所有订阅主题的主题存储。
	//如果没有设置,则默认为"mem"。
	TopicsProvider string
	// contains filtered or unexported fields
}

Server is a library implementation of the MQTT server that, as best it can, complies with the MQTT 3.1 and 3.1.1 specs. Server是MQTT服务器的一个库实现,它尽其所能遵守 使用MQTT 3.1和3.1.1规范。

func (*Server) Close

func (this *Server) Close() error

Close terminates the server by shutting down all the client connections and closing the listener. It will, as best it can, clean up after itself.

func (*Server) ListenAndServe

func (this *Server) ListenAndServe(uri string) error

ListenAndServe listents to connections on the URI requested, and handles any incoming MQTT client sessions. It should not return until Close() is called or if there's some critical error that stops the server from running. The URI supplied should be of the form "protocol://host:port" that can be parsed by url.Parse(). For example, an URI could be "tcp://0.0.0.0:1883". ListenAndServe监听请求的URI上的连接,并处理任何连接 传入的MQTT客户机会话。 在调用Close()之前,它不应该返回 或者有一些关键的错误导致服务器停止运行。 URI 提供的格式应该是“protocol://host:port”,可以通过它进行解析 url.Parse ()。 例如,URI可以是“tcp://0.0.0.0:1883”。

Jump to

Keyboard shortcuts

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