mqtt

package
v2.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: Apache-2.0 Imports: 22 Imported by: 25

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      = fmt.Errorf("client is closed")

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

all gomqtt client errors

View Source
var (
	ErrInvalidLengthMqtt        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowMqtt          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupMqtt = fmt.Errorf("proto: unexpected end of group")
)

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) SendOrDrop added in v2.0.8

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

Send sends a generic packet, drop the packet if the channel is full

func (*Client) Start

func (c *Client) Start(obs Observer) error

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        []QOSTopic    `yaml:"subscriptions" json:"subscriptions" default:"[]"`
	utils.Certificate    `yaml:",inline" json:",inline"`
}

ClientConfig client config

func (ClientConfig) ToClientOptions

func (cc ClientConfig) ToClientOptions() (*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
	Subscriptions        []Subscription
	DisableAutoAck       bool
}

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 Context

type Context struct {
	ID    uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
	TS    uint64 `protobuf:"varint,2,opt,name=TS,proto3" json:"TS,omitempty"`
	QOS   uint32 `protobuf:"varint,3,opt,name=QOS,proto3" json:"QOS,omitempty"`
	Flags uint32 `protobuf:"varint,4,opt,name=Flags,proto3" json:"Flags,omitempty"`
	Topic string `protobuf:"bytes,5,opt,name=Topic,proto3" json:"Topic,omitempty"`
}

func NewPopulatedContext

func NewPopulatedContext(r randyMqtt, easy bool) *Context

func (*Context) Descriptor

func (*Context) Descriptor() ([]byte, []int)

func (*Context) Equal

func (this *Context) Equal(that interface{}) bool

func (*Context) GoString

func (this *Context) GoString() string

func (*Context) Marshal

func (m *Context) Marshal() (dAtA []byte, err error)

func (*Context) MarshalTo

func (m *Context) MarshalTo(dAtA []byte) (int, error)

func (*Context) MarshalToSizedBuffer

func (m *Context) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Context) ProtoMessage

func (*Context) ProtoMessage()

func (*Context) Reset

func (m *Context) Reset()

func (*Context) Size

func (m *Context) Size() (n int)

func (*Context) String

func (m *Context) String() string

func (*Context) Unmarshal

func (m *Context) Unmarshal(dAtA []byte) error

func (*Context) XXX_DiscardUnknown

func (m *Context) XXX_DiscardUnknown()

func (*Context) XXX_Marshal

func (m *Context) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Context) XXX_Merge

func (m *Context) XXX_Merge(src proto.Message)

func (*Context) XXX_Size

func (m *Context) XXX_Size() int

func (*Context) XXX_Unmarshal

func (m *Context) XXX_Unmarshal(b []byte) error

type Counter

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

func NewCounter

func NewCounter() *Counter

NewCounter creates a new counter

func NewCounterWithNext added in v2.0.12

func NewCounterWithNext(next ID) *Counter

NewIDCounterWithNext returns a new counter that will emit the specified if id as the next id.

func (*Counter) GetNextID added in v2.0.12

func (c *Counter) GetNextID() ID

GetNextID will return the next id without increment

func (*Counter) NextID added in v2.0.12

func (c *Counter) NextID() ID

NextID will return the next id and increase id

func (*Counter) Reset added in v2.0.12

func (c *Counter) Reset()

Reset will reset the 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

func NextCounterID added in v2.0.12

func NextCounterID(id ID) 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 struct {
	Context Context `protobuf:"bytes,1,opt,name=Context,proto3" json:"Context"`
	Content []byte  `protobuf:"bytes,2,opt,name=Content,proto3" json:"Content,omitempty"`
}

func NewPopulatedMessage

func NewPopulatedMessage(r randyMqtt, easy bool) *Message

func (*Message) Descriptor

func (*Message) Descriptor() ([]byte, []int)

func (*Message) Equal

func (this *Message) Equal(that interface{}) bool

func (*Message) GoString

func (this *Message) GoString() string

func (*Message) Marshal

func (m *Message) Marshal() (dAtA []byte, err error)

func (*Message) MarshalTo

func (m *Message) MarshalTo(dAtA []byte) (int, error)

func (*Message) MarshalToSizedBuffer

func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) Size

func (m *Message) Size() (n int)

func (*Message) String

func (m *Message) String() string

func (*Message) Unmarshal

func (m *Message) Unmarshal(dAtA []byte) error

func (*Message) XXX_DiscardUnknown

func (m *Message) XXX_DiscardUnknown()

func (*Message) XXX_Marshal

func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Message) XXX_Merge

func (m *Message) XXX_Merge(src proto.Message)

func (*Message) XXX_Size

func (m *Message) XXX_Size() int

func (*Message) XXX_Unmarshal

func (m *Message) XXX_Unmarshal(b []byte) error

type Observer

type Observer interface {
	OnPublish(*packet.Publish) error
	OnPuback(*packet.Puback) error
	// Do not invoke client.Close() in OnError, otherwise a deadlock will occur.
	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 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