mqtt

package
v0.1.92 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 23 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      = 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 added in v0.1.1

func CheckTopic(topic string, wildcard bool) bool

CheckTopic check topic

func GetTLSCommonName added in v0.1.1

func GetTLSCommonName(conn Connection) (string, bool)

GetTLSCommonName check bidirectional authentication and return commonName

func MatchTopicQOS added in v0.0.6

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) Start added in v0.1.91

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 added in v0.1.13

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

ToClientOptions converts client config to client options

type ClientOptions added in v0.1.9

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 added in v0.1.9

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 added in v0.1.57

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 added in v0.1.57

func NewPopulatedContext(r randyMqtt, easy bool) *Context

func (*Context) Descriptor added in v0.1.57

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

func (*Context) Equal added in v0.1.57

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

func (*Context) GoString added in v0.1.57

func (this *Context) GoString() string

func (*Context) Marshal added in v0.1.57

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

func (*Context) MarshalTo added in v0.1.57

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

func (*Context) MarshalToSizedBuffer added in v0.1.57

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

func (*Context) ProtoMessage added in v0.1.57

func (*Context) ProtoMessage()

func (*Context) Reset added in v0.1.57

func (m *Context) Reset()

func (*Context) Size added in v0.1.57

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

func (*Context) String added in v0.1.57

func (m *Context) String() string

func (*Context) Unmarshal added in v0.1.57

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

func (*Context) XXX_DiscardUnknown added in v0.1.57

func (m *Context) XXX_DiscardUnknown()

func (*Context) XXX_Marshal added in v0.1.57

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

func (*Context) XXX_Merge added in v0.1.57

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

func (*Context) XXX_Size added in v0.1.57

func (m *Context) XXX_Size() int

func (*Context) XXX_Unmarshal added in v0.1.57

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

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 added in v0.0.8

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 added in v0.1.57

func NewPopulatedMessage(r randyMqtt, easy bool) *Message

func (*Message) Descriptor added in v0.1.57

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

func (*Message) Equal added in v0.1.57

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

func (*Message) GoString added in v0.1.57

func (this *Message) GoString() string

func (*Message) Marshal added in v0.1.57

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

func (*Message) MarshalTo added in v0.1.57

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

func (*Message) MarshalToSizedBuffer added in v0.1.57

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

func (*Message) ProtoMessage added in v0.1.57

func (*Message) ProtoMessage()

func (*Message) Reset added in v0.1.57

func (m *Message) Reset()

func (*Message) Size added in v0.1.57

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

func (*Message) String added in v0.1.57

func (m *Message) String() string

func (*Message) Unmarshal added in v0.1.57

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

func (*Message) XXX_DiscardUnknown added in v0.1.57

func (m *Message) XXX_DiscardUnknown()

func (*Message) XXX_Marshal added in v0.1.57

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

func (*Message) XXX_Merge added in v0.1.57

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

func (*Message) XXX_Size added in v0.1.57

func (m *Message) XXX_Size() int

func (*Message) XXX_Unmarshal added in v0.1.57

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 added in v0.0.6

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

TopicChecker checks topic

func NewTopicChecker added in v0.0.6

func NewTopicChecker(sysTopics []string) *TopicChecker

NewTopicChecker create topicChecker

func (*TopicChecker) CheckTopic added in v0.0.6

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