libmqtt

package module
v0.0.0-...-0dbc52a Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

README

libmqtt

Build Status GoDoc GoReportCard

Feature rich modern MQTT 3.1.1 client lib in pure Go, for Go, C/C++, Java and Python

Contents

Features

  1. Feature rich MQTT 3.1.1 client
  2. HTTP server like API
  3. High performance and less memory footprint (see Benchmark)
  4. Customizable TopicRouter (see Topic Routing)
  5. Builtin multiple session persist methods (see Session Persist)
  6. C/C++ lib, Java lib, Python lib - TODO, Command line client support
  7. Idiomatic Go, reactive stream

Extensions

Helpful extensions for libmqtt (see extension)

Usage

This project can be used as

As a Go lib
Prerequisite
  • Go 1.9+ (with GOPATH configured)
Steps
  1. Go get this project
go get github.com/goiiot/libmqtt
  1. Import this package in your project file
import "github.com/goiiot/libmqtt"
  1. Create a custom client
client, err := libmqtt.NewClient(
    // server address(es)
    libmqtt.WithServer("localhost:1883"),
)
if err != nil {
    // handle client creation error
}

Notice: If you would like to explore all the options available, please refer to GoDoc#Option

  1. Register the handlers and Connect, then you are ready to pub/sub with server

We recommend you to register handlers for pub, sub, unsub, net error and persist error, for they can provide you more controllability of the lifecycle of a MQTT client

// register handler for pub success/fail (optional, but recommended)
client.HandlePub(PubHandler)

// register handler for sub success/fail (optional, but recommended)
client.HandleSub(SubHandler)

// register handler for unsub success/fail (optional, but recommended)
client.HandleUnSub(UnSubHandler)

// register handler for net error (optional, but recommended)
client.HandleNet(NetHandler)

// register handler for persist error (optional, but recommended)
client.HandlePersist(PersistHandler)

// define your topic handlers like a golang http server
client.Handle("foo", func(topic string, qos libmqtt.QosLevel, msg []byte) {
    // handle the topic message
})

client.Handle("bar", func(topic string, qos libmqtt.QosLevel, msg []byte) {
    // handle the topic message
})

// connect to server
client.Connect(func(server string, code libmqtt.ConnAckCode, err error) {
    if err != nil {
        // failed
        panic(err)
    }

    if code != libmqtt.ConnAccepted {
        // server rejected or in error
        panic(code)
    }

    // success
    // you are now connected to the `server`
    // (the `server` is one of you have provided `servers` when create the client)
    // start your business logic here or send a signal to your logic to start

    // subscribe some topic(s)
    client.Subscribe(
        &libmqtt.Topic{Name: "foo"},
        &libmqtt.Topic{Name: "bar", Qos: libmqtt.Qos1},
        // ...
    )

    // publish some topic message(s)
    client.Publish(
        &libmqtt.PublishPacket{
            TopicName: "foo",
            Qos:       libmqtt.Qos0,
            Payload:   []byte("foo data"),
        }, &libmqtt.PublishPacket{
            TopicName: "bar",
            Qos:       libmqtt.Qos1,
            Payload:   []byte("bar data"),
        },
        // ...
    )
})
  1. Unsubscribe topic(s)
client.UnSubscribe("foo", "bar")
  1. Destroy the client when you would like to
// passing true to Destroy means a immediate disconnect to server
// while passing false will try to send a DisConn packet to server
client.Destroy(true)
As a C/C++ lib

Please refer to c - README.md

As a Java lib

Please refer to java - README.md

As a Python lib

TODO

As a command line client

Please refer to cmd - README.md

Topic Routing

Routing topics is one of the most important thing when it comes to business logics, we currently have built two TopicRouters which is ready to use, they are TextRouter and RegexRouter

  • TextRouter will match the exact same topic which was registered to client by Handle method. (this is the default router in a client)
  • RegexRouter will go through all the registered topic handlers, and use regular expression to test whether that is matched and should dispatch to the handler

If you would like to apply other routing strategy to the client, you can provide this option when creating the client

client, err := libmqtt.NewClient(
    // ...
    // for example, use `RegexRouter`
    libmqtt.WithRouter(libmqtt.NewRegexRouter()),
    // ...
)

Session Persist

Per MQTT Specification, session state should be persisted and be recovered when next time connected to server without clean session flag set, currently we provide persist method as following:

  1. NonePersist - no session persist
  2. MemPersist - in memory session persist
  3. FilePersist - files session persist (with write barrier)
  4. RedisPersist - redis session persist (available inside github.com/goiiot/libmqtt/extension package)

Note: Use RedisPersist if possible.

Benchmark

The procedure of the benchmark is as following:

  1. Create the client
  2. Connect to server
  3. Subscribe to topic foo
  4. Publish to topic foo
  5. Unsubsecibe when received all published message (with foo topic)
  6. Destroy client (a sudden disconnect without disconnect packet)

The benchmark result listed below was taken on a Macbook Pro 13' (Early 2015, macOS 10.13.2), statistics inside which is the value of ten times average

Bench Name Pub Count ns/op B/op allocs/op Transfer Time Total Time
BenchmarkPahoClient-4 10000 199632 1399 31 0.230s 2.021s
BenchmarkLibmqttClient-4 10000 144407 331 9 0.124s 1.467s
BenchmarkPahoClient-4 50000 205884 1395 31 1.170s 10.316s
BenchmarkLibmqttClient-4 50000 161640 328 9 0.717s 8.105s

You can make the benchmark using source code from benchmark

Notice: benchmark on libmqtt sometimes can be a infinite loop, we are now trying to solve that

RoadMap

  1. File persist storage of session status (High priority)
  2. Full tested multiple connections in one client (High priority)
  3. Add compatibility with mqtt 5.0 (Medium priority)
  4. Export to Python (CPython)... (Low priority)

LICENSE

Copyright GoIIoT (https://github.com/goiiot)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PingReqPacket is the final instance of pingReqPacket
	PingReqPacket = &pingReqPacket{}
	// PingRespPacket is the final instance of pingRespPacket
	PingRespPacket = &pingRespPacket{}
)
View Source
var (
	// DisConnPacket is the final instance of disConnPacket
	DisConnPacket = &disConnPacket{}
)
View Source
var (
	// ErrBadPacket is the error happened when trying to decode a none MQTT packet
	ErrBadPacket = errors.New("decoded none MQTT packet ")
)
View Source
var (
	// ErrTimeOut connection timeout error
	ErrTimeOut = errors.New("connection timeout ")
)
View Source
var NonePersist = &nonePersist{}

NonePersist defines no persist storage

View Source
var (
	// PacketDroppedByStrategy used when persist store packet while strategy
	// don't allow that persist
	PacketDroppedByStrategy = errors.New("packet persist dropped by strategy ")
)

Functions

This section is empty.

Types

type BufferWriter

type BufferWriter interface {
	io.Writer
	io.ByteWriter
}

type Client

type Client interface {
	// Handle register topic handlers, mostly used for RegexHandler, RestHandler
	// the default handler inside the client is TextHandler, which match the exactly same topic
	Handle(topic string, h TopicHandler)

	// Connect to all specified server with client options
	Connect(ConnHandler)

	// Publish a message for the topic
	Publish(packets ...*PublishPacket)

	// Subscribe topic(s)
	Subscribe(topics ...*Topic)

	// UnSubscribe topic(s)
	UnSubscribe(topics ...string)

	// Wait will wait until all connection finished
	Wait()

	// Destroy all client connection
	Destroy(force bool)

	// handlers
	HandlePub(PubHandler)
	HandleSub(SubHandler)
	HandleUnSub(UnSubHandler)
	HandleNet(NetHandler)
	HandlePersist(PersistHandler)
}

Client act as a mqtt client

func NewClient

func NewClient(options ...Option) (Client, error)

NewClient will create a new mqtt client

type ConnAckCode

type ConnAckCode = byte

ConnAckCode is connection response code from server

const (
	// ConnAccepted client accepted by server
	ConnAccepted ConnAckCode = iota
	// ConnBadProtocol Protocol not supported
	ConnBadProtocol
	// ConnIDRejected Connection Id not valid
	ConnIDRejected
	// ConnServerUnavailable Server error
	ConnServerUnavailable
	// ConnBadIdentity Identity failed
	ConnBadIdentity
	// ConnAuthFail Auth failed
	ConnAuthFail
)

type ConnAckPacket

type ConnAckPacket struct {
	Present bool
	Code    ConnAckCode
}

ConnAckPacket is the packet sent by the Server in response to a ConnPacket received from a Client.

The first packet sent from the Server to the Client MUST be a ConnAckPacket

func (*ConnAckPacket) Type

func (c *ConnAckPacket) Type() CtrlType

Type ConnAckPacket'strategy type is CtrlConnAck

func (*ConnAckPacket) WriteTo

func (c *ConnAckPacket) WriteTo(w BufferWriter) error

WriteTo encode ConnAckPacket to bytes

type ConnHandler

type ConnHandler func(server string, code ConnAckCode, err error)

ConnHandler is the handler which tend to the Connect result server is the server address provided by user in client creation call code is the ConnResult code err is the error happened when connect to server, if a error happened, the code value will max byte value (255)

type ConnPacket

type ConnPacket struct {
	Username     string
	Password     string
	ClientID     string
	CleanSession bool
	IsWill       bool
	WillQos      QosLevel
	WillRetain   bool
	Keepalive    uint16
	WillTopic    string
	WillMessage  []byte
	// contains filtered or unexported fields
}

ConnPacket is the first packet sent by Client to Server

func (*ConnPacket) Type

func (c *ConnPacket) Type() CtrlType

Type ConnPacket'strategy type is CtrlConn

func (*ConnPacket) WriteTo

func (c *ConnPacket) WriteTo(w BufferWriter) error

WriteTo encode ConnPacket to bytes

type CtrlType

type CtrlType = byte

CtrlType is MQTT Control packet type

const (
	// CtrlConn Connect
	CtrlConn CtrlType = iota + 1
	// CtrlConnAck Connect Ack
	CtrlConnAck
	// CtrlPublish Publish
	CtrlPublish
	// CtrlPubAck Publish Ack
	CtrlPubAck
	// CtrlPubRecv Publish Received
	CtrlPubRecv
	// CtrlPubRel Publish Release
	CtrlPubRel
	// CtrlPubComp Publish Complete
	CtrlPubComp
	// CtrlSubscribe Subscribe
	CtrlSubscribe
	// CtrlSubAck Subscribe Ack
	CtrlSubAck
	// CtrlUnSub UnSubscribe
	CtrlUnSub
	// CtrlUnSubAck UnSubscribe Ack
	CtrlUnSubAck
	// CtrlPingReq Ping Request
	CtrlPingReq
	// CtrlPingResp Ping Response
	CtrlPingResp
	// CtrlDisConn Disconnect
	CtrlDisConn
)

type FilePersist

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

FilePersist is the file persist method

func NewFilePersist

func NewFilePersist(dirPath string, strategy *PersistStrategy) *FilePersist

NewFilePersist will create a file persist method with provided dirPath and strategy, if no strategy provided (nil), then the default strategy will be used

func (*FilePersist) Delete

func (m *FilePersist) Delete(key string) error

Delete a persisted packet with key

func (*FilePersist) Destroy

func (m *FilePersist) Destroy() error

Destroy persist storage

func (*FilePersist) Load

func (m *FilePersist) Load(key string) (Packet, bool)

Load a packet with key, return nil, false when no packet found

func (*FilePersist) Name

func (m *FilePersist) Name() string

Name of this persist method

func (*FilePersist) Range

func (m *FilePersist) Range(ranger func(key string, p Packet) bool)

Range over all packet persisted

func (*FilePersist) Store

func (m *FilePersist) Store(key string, p Packet) error

Store a key packet pair, error happens when file access failed

type LogLevel

type LogLevel int

LogLevel is used to set log level in client creation

const (
	// Silent No log
	Silent LogLevel = iota
	// Verbose log all
	Verbose
	// Debug log with debug and above
	Debug
	// Info log with info and above
	Info
	// Warning log with warning and above
	Warning
	// Error log error only
	Error
)

type MemPersist

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

MemPersist is the in memory persist method

func NewMemPersist

func NewMemPersist(strategy *PersistStrategy) *MemPersist

NewMemPersist create a in memory persist method with provided strategy if no strategy provided (nil), then the default strategy will be used

func (*MemPersist) Delete

func (m *MemPersist) Delete(key string) error

Delete a persisted packet with key

func (*MemPersist) Destroy

func (m *MemPersist) Destroy() error

Destroy persist storage

func (*MemPersist) Load

func (m *MemPersist) Load(key string) (Packet, bool)

Load a packet with key, return nil, false when no packet found

func (*MemPersist) Name

func (m *MemPersist) Name() string

Name of this persist method

func (*MemPersist) Range

func (m *MemPersist) Range(f func(key string, p Packet) bool)

Range over all packet persisted

func (*MemPersist) Store

func (m *MemPersist) Store(key string, p Packet) error

Store a key packet pair, in memory persist always return nil (no error)

type NetHandler

type NetHandler func(server string, err error)

NetHandler handles the error occurred when net broken

type Option

type Option func(*client) error

Option is client option for connection options

func WithBackoffStrategy

func WithBackoffStrategy(firstDelay, maxDelay time.Duration, factor float64) Option

WithBackoffStrategy will set reconnect backoff strategy firstDelay is the time to wait before retrying after the first failure maxDelay defines the upper bound of backoff delay factor is applied to the backoff after each retry. e.g. FirstDelay = 1s and Factor = 2, then the SecondDelay is 2s, the ThirdDelay is 4s

func WithCleanSession

func WithCleanSession(f bool) Option

WithCleanSession will set clean flag in connect packet

func WithClientID

func WithClientID(clientID string) Option

WithClientID set the client id for connection

func WithDialTimeout

func WithDialTimeout(timeout uint16) Option

WithDialTimeout for connection time out (time in second)

func WithIdentity

func WithIdentity(username, password string) Option

WithIdentity for username and password

func WithKeepalive

func WithKeepalive(keepalive uint16, factor float64) Option

WithKeepalive set the keepalive interval (time in second)

func WithLog

func WithLog(l LogLevel) Option

WithLog will create basic logger for log

func WithPersist

func WithPersist(method PersistMethod) Option

WithPersist defines the persist method to be used

func WithRecvBuf

func WithRecvBuf(size int) Option

WithRecvBuf designate the channel size of receive

func WithRouter

func WithRouter(r TopicRouter) Option

WithRouter set the router for topic dispatch

func WithSendBuf

func WithSendBuf(size int) Option

WithSendBuf designate the channel size of send

func WithServer

func WithServer(servers ...string) Option

WithServer adds servers as client server Just use "ip:port" or "domain.name:port" However, only TCP connection supported for now

func WithTLS

func WithTLS(certFile, keyFile string, caCert string, serverNameOverride string, skipVerify bool) Option

WithTLS for client tls certification

func WithWill

func WithWill(topic string, qos QosLevel, retain bool, payload []byte) Option

WithWill mark this connection as a will teller

type Packet

type Packet interface {
	// Type return the packet type
	Type() CtrlType

	// WriteTo
	WriteTo(BufferWriter) error
}

Packet is MQTT control packet

func DecodeOnePacket

func DecodeOnePacket(reader io.Reader) (pkt Packet, err error)

DecodeOnePacket will decode one mqtt packet

type PersistHandler

type PersistHandler func(err error)

PersistHandler handles err happened when persist process has trouble

type PersistMethod

type PersistMethod interface {
	// Name of what persist strategy used
	Name() string

	// Store a packet with key
	Store(key string, p Packet) error

	// Load a packet from stored data according to the key
	Load(key string) (Packet, bool)

	// Range over data stored, return false to break the range
	Range(func(key string, p Packet) bool)

	// Delete
	Delete(key string) error

	// Destroy stored data
	Destroy() error
}

PersistMethod defines the behavior of persist methods

type PersistStrategy

type PersistStrategy struct {
	// Interval applied to file/database persist
	// if this field is set to 0, means do persist per action
	// default value is 1s
	Interval time.Duration

	// MaxCount applied to all persist method
	// if this field set to 0, means no persist limit
	// for memory persist, means max in memory count
	// for file/database persist, means max entry in file/memory
	// default value is 0
	MaxCount uint32

	// DropOnExceed defines how to tackle with packets incoming
	// when max count is reached, default value is false
	DropOnExceed bool

	// DuplicateReplace defines whether duplicated key should
	// override previous one, default value is true
	DuplicateReplace bool
}

PersistStrategy defines the details to be complied in persist methods

func DefaultPersistStrategy

func DefaultPersistStrategy() *PersistStrategy

DefaultPersistStrategy will create a default PersistStrategy Interval = 1s, MaxCount = 0, DropOnExceed = false, DuplicateReplace = true

type ProtocolLevel

type ProtocolLevel = byte

ProtocolLevel MQTT Protocol

const (
	// V311 means MQTT 3.1.1
	V311 ProtocolLevel = 4
	// V5 means MQTT 5
	V5 ProtocolLevel = 5
)

type PubAckPacket

type PubAckPacket struct {
	PacketID uint16
}

PubAckPacket is the response to a PublishPacket with QoS level 1.

func (*PubAckPacket) Type

func (p *PubAckPacket) Type() CtrlType

Type PubAckPacket's type is CtrlPubAck

func (*PubAckPacket) WriteTo

func (p *PubAckPacket) WriteTo(w BufferWriter) error

WriteTo encode PubAckPacket into buffer

type PubCompPacket

type PubCompPacket struct {
	PacketID uint16
}

PubCompPacket is the response to a PubRelPacket. It is the fourth and final packet of the QoS 892 2 protocol exchange. 893

func (*PubCompPacket) Type

func (p *PubCompPacket) Type() CtrlType

Type PubCompPacket's type is CtrlPubComp

func (*PubCompPacket) WriteTo

func (p *PubCompPacket) WriteTo(w BufferWriter) error

WriteTo encode PubCompPacket into buffer

type PubHandler

type PubHandler func(topic string, err error)

PubHandler handles the error occurred when publish some message if err is not nil, that means a error occurred when sending pub msg

type PubRecvPacket

type PubRecvPacket struct {
	PacketID uint16
}

PubRecvPacket is the response to a PublishPacket with QoS 2. It is the second packet of the QoS 2 protocol exchange.

func (*PubRecvPacket) Type

func (p *PubRecvPacket) Type() CtrlType

Type PubRecvPacket's type is CtrlPubRecv

func (*PubRecvPacket) WriteTo

func (p *PubRecvPacket) WriteTo(w BufferWriter) error

WriteTo encode PubRecvPacket into buffer

type PubRelPacket

type PubRelPacket struct {
	PacketID uint16
}

PubRelPacket is the response to a PubRecvPacket. It is the third packet of the QoS 2 protocol exchange.

func (*PubRelPacket) Type

func (p *PubRelPacket) Type() CtrlType

Type PubRelPacket's type is CtrlPubRel

func (*PubRelPacket) WriteTo

func (p *PubRelPacket) WriteTo(w BufferWriter) error

WriteTo encode PubRelPacket into buffer

type PublishPacket

type PublishPacket struct {
	IsDup     bool
	Qos       QosLevel
	IsRetain  bool
	TopicName string
	Payload   []byte
	PacketID  uint16
}

PublishPacket is sent from a Client to a Server or from Server to a Client to transport an Application Message.

func (*PublishPacket) Type

func (p *PublishPacket) Type() CtrlType

Type PublishPacket's type is CtrlPublish

func (*PublishPacket) WriteTo

func (p *PublishPacket) WriteTo(w BufferWriter) error

WriteTo encode PublishPacket into buffer

type QosLevel

type QosLevel = byte

QosLevel is either 0, 1, 2

const (
	// Qos0 0
	Qos0 QosLevel = iota
	// Qos1 1
	Qos1
	// Qos2 2
	Qos2
)

type RegexRouter

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

RegexRouter use regex to match topic messages

func NewRegexRouter

func NewRegexRouter() *RegexRouter

NewRegexRouter will create a regex router

func (*RegexRouter) Dispatch

func (r *RegexRouter) Dispatch(p *PublishPacket)

Dispatch the received packet

func (*RegexRouter) Handle

func (r *RegexRouter) Handle(topicRegex string, h TopicHandler)

Handle will register the topic with handler

func (*RegexRouter) Name

func (r *RegexRouter) Name() string

Name is the name of router

type StandardRouter

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

StandardRouter implements standard MQTT routing behaviour

func NewStandardRouter

func NewStandardRouter() *StandardRouter

NewStandardRouter will create a standard mqtt router

func (*StandardRouter) Dispatch

func (s *StandardRouter) Dispatch(p *PublishPacket)

Dispatch defines the action to dispatch published packet

func (*StandardRouter) Handle

func (s *StandardRouter) Handle(topic string, h TopicHandler)

Handle defines how to register topic with handler

func (*StandardRouter) Name

func (s *StandardRouter) Name() string

Name is the name of router

type SubAckCode

type SubAckCode = byte

SubAckCode is returned by server in SubAckPacket

const (
	// SubOkMaxQos0 QoS 0 is used by server
	SubOkMaxQos0 SubAckCode = iota
	// SubOkMaxQos1 QoS 1 is used by server
	SubOkMaxQos1
	// SubOkMaxQos2 QoS 2 is used by server
	SubOkMaxQos2
	// SubFail means that subscription is not successful
	SubFail SubAckCode = 0x80
)

type SubAckPacket

type SubAckPacket struct {
	PacketID uint16
	Codes    []SubAckCode
}

SubAckPacket is sent by the Server to the Client to confirm receipt and processing of a SubscribePacket.

SubAckPacket contains a list of return codes, that specify the maximum QoS level that was granted in each Subscription that was requested by the SubscribePacket.

func (*SubAckPacket) Type

func (s *SubAckPacket) Type() CtrlType

Type SubAckPacket'strategy type is CtrlSubAck

func (*SubAckPacket) WriteTo

func (s *SubAckPacket) WriteTo(w BufferWriter) error

WriteTo encode SubAckPacket into buffer

type SubHandler

type SubHandler func(topics []*Topic, err error)

SubHandler handles the error occurred when subscribe some topic if err is not nil, that means a error occurred when sending sub msg

type SubscribePacket

type SubscribePacket struct {
	PacketID uint16
	Topics   []*Topic
}

SubscribePacket is sent from the Client to the Server to create one or more Subscriptions.

Each Subscription registers a Client’strategy interest in one or more TopicNames. The Server sends PublishPackets to the Client in order to forward Application Messages that were published to TopicNames that match these Subscriptions. The SubscribePacket also specifies (for each Subscription) the maximum QoS with which the Server can send Application Messages to the Client

func (*SubscribePacket) Type

func (s *SubscribePacket) Type() CtrlType

Type SubscribePacket'strategy type is CtrlSubscribe

func (*SubscribePacket) WriteTo

func (s *SubscribePacket) WriteTo(w BufferWriter) error

WriteTo encode SubscribePacket into buffer

type TextRouter

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

TextRouter uses plain string comparison to dispatch topic message this is the default router in client

func NewTextRouter

func NewTextRouter() *TextRouter

NewTextRouter will create a text based router

func (*TextRouter) Dispatch

func (r *TextRouter) Dispatch(p *PublishPacket)

Dispatch the received packet

func (*TextRouter) Handle

func (r *TextRouter) Handle(topic string, h TopicHandler)

Handle will register the topic with handler

func (*TextRouter) Name

func (r *TextRouter) Name() string

Name of TextRouter is "TextRouter"

type Topic

type Topic struct {
	Name string
	Qos  QosLevel
}

Topic for both topic name and topic qos

type TopicHandler

type TopicHandler func(topic string, qos QosLevel, msg []byte)

TopicHandler handles topic sub message topic is the client user provided topic code can be SubOkMaxQos0, SubOkMaxQos1, SubOkMaxQos2, SubFail

type TopicRouter

type TopicRouter interface {
	// Name is the name of router
	Name() string
	// Handle defines how to register topic with handler
	Handle(topic string, h TopicHandler)
	// Dispatch defines the action to dispatch published packet
	Dispatch(p *PublishPacket)
}

TopicRouter defines how to route the topic message to handler

type UnSubAckPacket

type UnSubAckPacket struct {
	PacketID uint16
}

UnSubAckPacket is sent by the Server to the Client to confirm receipt of an UnSubPacket

func (*UnSubAckPacket) Type

func (s *UnSubAckPacket) Type() CtrlType

Type UnSubAckPacket'strategy type is CtrlUnSubAck

func (*UnSubAckPacket) WriteTo

func (s *UnSubAckPacket) WriteTo(w BufferWriter) error

WriteTo encode UnSubAckPacket into buffer

type UnSubHandler

type UnSubHandler func(topic []string, err error)

UnSubHandler handles the error occurred when publish some message

type UnSubPacket

type UnSubPacket struct {
	PacketID   uint16
	TopicNames []string
}

UnSubPacket is sent by the Client to the Server, to unsubscribe from topics.

func (*UnSubPacket) Type

func (s *UnSubPacket) Type() CtrlType

Type UnSubPacket'strategy type is CtrlUnSub

func (*UnSubPacket) WriteTo

func (s *UnSubPacket) WriteTo(w BufferWriter) error

WriteTo encode UnSubPacket into buffer

Directories

Path Synopsis
c

Jump to

Keyboard shortcuts

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