Documentation ¶
Index ¶
- Constants
- Variables
- func CheckTopic(topic string, wildcard bool) bool
- func GetTLSCommonName(conn Connection) (string, bool)
- func MatchTopicQOS(t *Trie, topic string) (bool, uint32)
- type Client
- type ClientConfig
- type ClientOptions
- type Connack
- type ConnackCode
- type Connect
- type Connection
- type Context
- func (*Context) Descriptor() ([]byte, []int)
- func (this *Context) Equal(that interface{}) bool
- func (this *Context) GoString() string
- func (m *Context) Marshal() (dAtA []byte, err error)
- func (m *Context) MarshalTo(dAtA []byte) (int, error)
- func (m *Context) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Context) ProtoMessage()
- func (m *Context) Reset()
- func (m *Context) Size() (n int)
- func (m *Context) String() string
- func (m *Context) Unmarshal(dAtA []byte) error
- func (m *Context) XXX_DiscardUnknown()
- func (m *Context) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Context) XXX_Merge(src proto.Message)
- func (m *Context) XXX_Size() int
- func (m *Context) XXX_Unmarshal(b []byte) error
- type Counter
- type Dialer
- type Disconnect
- type Future
- type ID
- type Launcher
- type Message
- func (*Message) Descriptor() ([]byte, []int)
- func (this *Message) Equal(that interface{}) bool
- func (this *Message) GoString() string
- func (m *Message) Marshal() (dAtA []byte, err error)
- func (m *Message) MarshalTo(dAtA []byte) (int, error)
- func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Message) ProtoMessage()
- func (m *Message) Reset()
- func (m *Message) Size() (n int)
- func (m *Message) String() string
- func (m *Message) Unmarshal(dAtA []byte) error
- func (m *Message) XXX_DiscardUnknown()
- func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Message) XXX_Merge(src proto.Message)
- func (m *Message) XXX_Size() int
- func (m *Message) XXX_Unmarshal(b []byte) error
- type Observer
- type ObserverWrapper
- type OnError
- type OnPuback
- type OnPublish
- type Packet
- type Pingreq
- type Pingresp
- type Puback
- type Publish
- type QOS
- type QOSTopic
- type Server
- type Suback
- type Subscribe
- type Subscription
- type TopicChecker
- type Tracker
- type Trie
- type Type
- type Unsuback
- type Unsubscribe
Constants ¶
const ( Version311 byte = 4 Version31 byte = 3 )
The supported MQTT versions.
Variables ¶
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
Functions ¶
func GetTLSCommonName ¶
func GetTLSCommonName(conn Connection) (string, bool)
GetTLSCommonName check bidirectional authentication and return commonName
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client auto reconnection 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) SendOrDrop ¶ added in v2.0.8
Send sends a generic packet, drop the packet if the channel is full
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 ConnackCode ¶
type ConnackCode = packet.ConnackCode
The ConnackCode represents the return code in a Connack packet.
const ( ConnectionAccepted ConnackCode = iota InvalidProtocolVersion IdentifierRejected BadUsernameOrPassword NotAuthorized )
All available ConnackCodes.
type Connection ¶
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 (*Context) Descriptor ¶
func (*Context) MarshalToSizedBuffer ¶
func (*Context) ProtoMessage ¶
func (*Context) ProtoMessage()
func (*Context) XXX_DiscardUnknown ¶
func (m *Context) XXX_DiscardUnknown()
func (*Context) XXX_Marshal ¶
func (*Context) XXX_Unmarshal ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
func NewCounterWithNext ¶ added in v2.0.12
NewIDCounterWithNext returns a new counter that will emit the specified if id as the next id.
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 (*Message) Descriptor ¶
func (*Message) MarshalToSizedBuffer ¶
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) XXX_DiscardUnknown ¶
func (m *Message) XXX_DiscardUnknown()
func (*Message) XXX_Marshal ¶
func (*Message) XXX_Unmarshal ¶
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
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 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 Unsubscribe ¶
type Unsubscribe = packet.Unsubscribe
Unsubscribe the unsubscribe packet
func NewUnsubscribe ¶
func NewUnsubscribe() *Unsubscribe
NewUnsubscribe creates a new Unsubscribe packet