mqtt

package
v0.0.0-...-d840a7c Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version311 byte = 4
	Version31  byte = 3
)

The supported MQTT versions.

Variables

View Source
var (
	// client's erros
	ErrClientAlreadyConnecting  = gomqtt.ErrClientAlreadyConnecting
	ErrClientNotConnected       = gomqtt.ErrClientNotConnected
	ErrClientMissingID          = gomqtt.ErrClientMissingID
	ErrClientConnectionDenied   = gomqtt.ErrClientConnectionDenied
	ErrClientMissingPong        = gomqtt.ErrClientMissingPong
	ErrClientExpectedConnack    = gomqtt.ErrClientExpectedConnack
	ErrClientSubscriptionFailed = gomqtt.ErrFailedSubscription
	ErrClientAlreadyClosed      = errors.New("client is closed")

	// future's errors
	ErrFutureTimeout  = future.ErrTimeout
	ErrFutureCanceled = future.ErrCanceled
)

all gomqtt client errors

Functions

func CheckTopic

func CheckTopic(topic string, wildcard bool) bool

CheckTopic check topic

func GetTLSCommonName

func GetTLSCommonName(conn Connection) (string, bool)

GetTLSCommonName check bidirectional authentication and return commonName

func MatchTopicQOS

func MatchTopicQOS(t *Trie, topic string) (bool, uint32)

MatchTopicQOS if topic matched, return the lowest qos

Types

type Client

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

Client auto reconnection client

func NewClient

func NewClient(ops ClientOptions) *Client

NewClient creates a new client

func (*Client) Close

func (c *Client) Close() error

Close closes client

func (*Client) Publish

func (c *Client) Publish(qos QOS, topic string, payload []byte, pid ID, retain bool, dup bool) error

Publish sends a publish packet

func (*Client) Send

func (c *Client) Send(pkt Packet) error

Send sends a generic packet

func (*Client) Subscribe

func (c *Client) Subscribe(s []Subscription) error

Subscribe sends a subscribe packet

type ClientConfig

type ClientConfig struct {
	Address              string        `yaml:"address" json:"address"`
	Username             string        `yaml:"username" json:"username"`
	Password             string        `yaml:"password" json:"password"`
	ClientID             string        `yaml:"clientid" json:"clientid"`
	CleanSession         bool          `yaml:"cleansession" json:"cleansession"`
	Timeout              time.Duration `yaml:"timeout" json:"timeout" default:"30s"`
	KeepAlive            time.Duration `yaml:"keepalive" json:"keepalive" default:"30s"`
	MaxReconnectInterval time.Duration `yaml:"maxReconnectInterval" json:"maxReconnectInterval" default:"3m"`
	MaxCacheMessages     int           `yaml:"maxCacheMessages" json:"maxCacheMessages" default:"10"`
	DisableAutoAck       bool          `yaml:"disableAutoAck" json:"disableAutoAck"`
	Subscriptions        Subscriptions `yaml:"subscriptions" json:"subscriptions" default:"[]"`
	utils.Certificate    `yaml:",inline" json:",inline"`
}

ClientConfig client config

func (ClientConfig) ToClientOptions

func (cc ClientConfig) ToClientOptions(obs Observer) (*ClientOptions, error)

ToClientOptions converts client config to client options

type ClientOptions

type ClientOptions struct {
	Address              string
	Username             string
	Password             string
	TLSConfig            *tls.Config
	ClientID             string
	CleanSession         bool
	Timeout              time.Duration
	KeepAlive            time.Duration
	MaxReconnectInterval time.Duration
	MaxMessageSize       utils.Size
	MaxCacheMessages     int
	DisableAutoAck       bool
	Observer             Observer
	Subscriptions        []Subscription
}

ClientOptions client options

func NewClientOptions

func NewClientOptions() ClientOptions

NewClientOptions creates client options with default values

type Connack

type Connack = packet.Connack

Connack the connack packet

func NewConnack

func NewConnack() *Connack

NewConnack creates a new Connack packet

type ConnackCode

type ConnackCode = packet.ConnackCode

The ConnackCode represents the return code in a Connack packet.

const (
	ConnectionAccepted ConnackCode = iota
	InvalidProtocolVersion
	IdentifierRejected
	ServerUnavailable
	BadUsernameOrPassword
	NotAuthorized
)

All available ConnackCodes.

type Connect

type Connect = packet.Connect

Connect the connect packet

func NewConnect

func NewConnect() *Connect

NewConnect creates a new Connect packet

type Connection

type Connection transport.Conn

Connection the connection between a client and a server

type Counter

type Counter = session.IDCounter

Counter the packet id counter

func NewCounter

func NewCounter() *Counter

NewCounter creates a new counter

type Dialer

type Dialer = transport.Dialer

The Dialer handles connecting to a server and creating a connection

func NewDialer

func NewDialer(tc *tls.Config, td time.Duration) *Dialer

NewDialer returns a new Dialer

type Disconnect

type Disconnect = packet.Disconnect

Disconnect the disconnect packet

func NewDisconnect

func NewDisconnect() *Disconnect

NewDisconnect creates a new Disconnect packet

type Future

type Future = future.Future

Future future

func NewFuture

func NewFuture() *Future

NewFuture creates a new future.

type ID

type ID = packet.ID

ID the packet id

type Launcher

type Launcher = transport.Launcher

The Launcher helps with launching a server and accepting connections

func NewLauncher

func NewLauncher(tc *tls.Config) *Launcher

NewLauncher returns a new Launcher

type Message

type Message = packet.Message

Message the mqtt message

type Observer

type Observer interface {
	OnPublish(*packet.Publish) error
	OnPuback(*packet.Puback) error
	OnError(error)
}

Observer message observer interface

type ObserverWrapper

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

ObserverWrapper MQTT message handler wrapper

func NewObserverWrapper

func NewObserverWrapper(onPublish OnPublish, onPuback OnPuback, onError OnError) *ObserverWrapper

NewObserverWrapper creates a new handler wrapper

func (*ObserverWrapper) OnError

func (h *ObserverWrapper) OnError(err error)

OnError handles error

func (*ObserverWrapper) OnPuback

func (h *ObserverWrapper) OnPuback(pkt *packet.Puback) error

OnPuback handles puback packet

func (*ObserverWrapper) OnPublish

func (h *ObserverWrapper) OnPublish(pkt *packet.Publish) error

OnPublish handles publish packet

type OnError

type OnError func(error)

OnError handles error

type OnPuback

type OnPuback func(*packet.Puback) error

OnPuback handles puback packet

type OnPublish

type OnPublish func(*packet.Publish) error

OnPublish handles publish packet

type Packet

type Packet = packet.Generic

Packet the generic packet

type Pingreq

type Pingreq = packet.Pingreq

Pingreq the pingreq packet

func NewPingreq

func NewPingreq() *Pingreq

NewPingreq creates a new Pingreq packet.

type Pingresp

type Pingresp = packet.Pingresp

Pingresp the pingresp packet

func NewPingresp

func NewPingresp() *Pingresp

NewPingresp creates a new Pingresp packet

type Puback

type Puback = packet.Puback

Puback the puback packet

func NewPuback

func NewPuback() *Puback

NewPuback creates a new Puback packet

type Publish

type Publish = packet.Publish

Publish the publish packet

func NewPublish

func NewPublish() *Publish

NewPublish creates a new Publish packet

type QOS

type QOS = packet.QOS

QOS the quality of service levels

const (
	QOSAtMostOnce  QOS = iota
	QOSAtLeastOnce QOS = iota
	QOSExactlyOnce QOS = iota
	QOSFailure     QOS = 0x80
)

Al QoS levels

type QOSTopic

type QOSTopic struct {
	QOS   uint32 `yaml:"qos" json:"qos" validate:"min=0, max=1"`
	Topic string `yaml:"topic" json:"topic" validate:"nonzero"`
}

QOSTopic topic and qos

type Server

type Server = transport.Server

Server the server to accept connections

type Suback

type Suback = packet.Suback

Suback the suback packet

func NewSuback

func NewSuback() *Suback

NewSuback creates a new Suback packet

type Subscribe

type Subscribe = packet.Subscribe

Subscribe the subscribe packet

func NewSubscribe

func NewSubscribe() *Subscribe

NewSubscribe creates a new Subscribe packet

type Subscription

type Subscription = packet.Subscription

Subscription the topic and qos of subscription

type Subscriptions

type Subscriptions []QOSTopic

Subscriptions subscriptions

func (Subscriptions) ToMQTTSubscriptions

func (ss Subscriptions) ToMQTTSubscriptions() []Subscription

ToMQTTSubscriptions converts to mqtt subscriptions

type TopicChecker

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

TopicChecker checks topic

func NewTopicChecker

func NewTopicChecker(sysTopics []string) *TopicChecker

NewTopicChecker create topicChecker

func (*TopicChecker) CheckTopic

func (tc *TopicChecker) CheckTopic(topic string, wildcard bool) bool

CheckTopic checks the topic

type Tracker

type Tracker = gomqtt.Tracker

Tracker keeps track of keep alive intervals

func NewTracker

func NewTracker(timeout time.Duration) *Tracker

NewTracker creates a new tracker

type Trie

type Trie = topic.Tree

Trie the trie of topic subscription

func NewTrie

func NewTrie() *Trie

NewTrie creates a new trie

type Type

type Type = packet.Type

Type the packet type

type Unsuback

type Unsuback = packet.Unsuback

Unsuback the unsuback packet

func NewUnsuback

func NewUnsuback() *Unsuback

NewUnsuback creates a new Unsuback packet

type Unsubscribe

type Unsubscribe = packet.Unsubscribe

Unsubscribe the unsubscribe packet

func NewUnsubscribe

func NewUnsubscribe() *Unsubscribe

NewUnsubscribe creates a new Unsubscribe packet

Jump to

Keyboard shortcuts

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