servicev5

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: 31 Imported by: 0

Documentation

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 GetServerName

func GetServerName() string

func InitServiceTaskPool

func InitServiceTaskPool(poolSize int) (close io.Closer)

Types

type Client

type Client struct {
	// The number of seconds to keep the connection live if there's no data.
	// If not set then default to 5 mins.
	KeepAlive int

	// The number of seconds to wait for the CONNACK messagev5 before disconnecting.
	// If not set then default to 2 seconds.
	ConnectTimeout int

	AuthPlus authplus.AuthPlus

	// The number of seconds to wait for any ACK messages before failing.
	// If not set then default to 20 seconds.
	AckTimeout int

	// The number of times to retry sending a packet if ACK is not received.
	// If no set then default to 3 retries.
	TimeoutRetries int
	// contains filtered or unexported fields
}

Client is a library implementation of the MQTT client that, as best it can, complies with the MQTT 3.1 and 3.1.1 specs. Client是MQTT客户机的一个库实现,它尽可能地进行了编译 带有MQTT 3.1和3.1.1规范。

func (*Client) Connect

func (this *Client) Connect(uri string, msg *messagev5.ConnectMessage) (err error)

Connect is for MQTT clients to open a connection to a remote server. It needs to know the URI, e.g., "tcp://127.0.0.1:1883", so it knows where to connect to. It also needs to be supplied with the MQTT CONNECT messagev5. Connect用于MQTT客户端打开到远程服务器的连接。它需要 知道URI,例如,“tcp://127.0.0.1:1883”,因此它知道连接到哪里。它还 需要与MQTT连接消息一起提供。

func (*Client) Disconnect

func (this *Client) Disconnect()

Disconnect sends a single DISCONNECT messagev5 to the server. The client immediately terminates after the sending of the DISCONNECT messagev5. 向服务器发送一条断开连接的消息。客户端立即 发送断开连接的消息后终止。 如果是并发测试时,需要对Disconnect加锁,因为内部取消Topic等管理器会出现并发操作map 因为不想因为Client而对内部加锁,影响性能,所以使用者自行加锁

func (*Client) Ping

func (this *Client) Ping(onComplete OnCompleteFunc) error

Ping sends a single PINGREQ messagev5 to the server. PINGREQ/PINGRESP messages are mainly used by the client to keep a heartbeat to the server so the connection won't be dropped. Ping向服务器发送一条单独的PINGREQ消息。PINGREQ / PINGRESP消息 客户端主要用来保持心跳到服务器,这样连接就不会dropped

func (*Client) Publish

func (this *Client) Publish(msg *messagev5.PublishMessage, onComplete OnCompleteFunc) error

Publish sends a single MQTT PUBLISH messagev5 to the server. On completion, the supplied OnCompleteFunc is called. For QOS 0 messages, onComplete is called immediately after the messagev5 is sent to the outgoing buffer. For QOS 1 messages, onComplete is called when PUBACK is received. For QOS 2 messages, onComplete is called after the PUBCOMP messagev5 is received. Publish向服务器发送单个MQTT发布消息。在完成, 调用 provided OnCompleteFunc。对于QOS 0消息,将调用onComplete 在消息发送到传出缓冲区之后立即执行。对于QOS 1消息, 当收到PUBACK时调用onComplete。对于QOS 2消息,onComplete是 在收到PUBCOMP消息后调用。

func (*Client) Subscribe

func (this *Client) Subscribe(msg *messagev5.SubscribeMessage, onComplete OnCompleteFunc, onPublish OnPublishFunc) error

Subscribe sends a single SUBSCRIBE messagev5 to the server. The SUBSCRIBE messagev5 can contain multiple topicsv5 that the client wants to subscribe to. On completion, which is when the client receives a SUBACK messsage back from the server, the supplied onComplete funciton is called.

When messages are sent to the client from the server that matches the topicsv5 the client subscribed to, the onPublish function is called to handle those messages. So in effect, the client can supply different onPublish functions for different topicsv5. Subscribe向服务器发送一条订阅消息。 订阅消息 可以包含客户端希望订阅的多个主题。 收购完成后, 当客户端收到来自服务器的一个SUBACK消息时 提供一个完整的功能被调用。

当消息从与主题匹配的服务器发送到客户端时 客户端订阅后,调用onPublish函数来处理这些消息。 因此,实际上,客户端可以为不同的onPublish函数提供不同的onPublish函数 主题。

func (*Client) Unsubscribe

func (this *Client) Unsubscribe(msg *messagev5.UnsubscribeMessage, onComplete OnCompleteFunc) error

Unsubscribe sends a single UNSUBSCRIBE messagev5 to the server. The UNSUBSCRIBE messagev5 can contain multiple topicsv5 that the client wants to unsubscribe. On completion, which is when the client receives a UNSUBACK messagev5 from the server, the supplied onComplete function is called. The client will no longer handle messages from the server for those unsubscribed topicsv5. 取消订阅向服务器发送一条取消订阅消息。的退订 消息可以包含多个客户端想要取消订阅的主题。在 完成,当客户端收到来自服务器的UNSUBACK消息时, 调用所提供的onComplete函数。客户端将不再处理 来自服务器的未订阅主题的消息。

type OnCompleteFunc

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

完成的回调方法

type OnPublishFunc

type OnPublishFunc func(msg *messagev5.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 // 服务版本

	ConFig *config.SIConfig // 偷懒了

	// The number of seconds to keep the connection live if there's no data.
	// If not set then default to 5 mins.
	//如果没有数据,保持连接的秒数。
	//如果没有设置,则默认为5分钟。connect中的该值的1.5倍作为读超时
	KeepAlive int // uint16

	// 写超时,默认5分钟 1.5
	WriteTimeout int

	// The number of seconds to wait for the CONNECT messagev5 before disconnecting.
	// If not set then default to 5 seconds.
	//在断开连接之前等待连接消息的秒数。
	//如果没有设置,则默认为5秒。
	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 messagev5. 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 messagev5.
	// If not set then default to "mem".
	// SessionsProvider是保存所有会话对象的会话存储。
	//这是用于检查在连接消息中是否将清洗设置为0的存储。
	//如果没有设置,则默认为"mem"。
	SessionsProvider string

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

	// 增强认证管理器
	AuthPlusProvider []string

	ClusterDiscover   cluster.NodeDiscover
	ClusterServer     *server.Server
	ClusterClient     *sync.Map // name --> *client.Client
	ShareTopicMapNode cluster.ShareTopicMapNode

	SessionStore store.SessionStore
	MessageStore store.MessageStore
	EventStore   store.EventStore
	// 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) AddCloser

func (this *Server) AddCloser(close io.Closer)

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) InitStore

func (this *Server) InitStore()

func (*Server) ListenAndServe

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

ListenAndServe listents to connections on the URI requested, and handles any incoming MQTT client sessionsv5. 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”。

func (*Server) NewService

func (this *Server) NewService() *service

func (*Server) RunClusterComp

func (this *Server) RunClusterComp()

func (*Server) TopicProvider

func (s *Server) TopicProvider() *topicsv5.Manager

Jump to

Keyboard shortcuts

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