mqtt

package
v0.0.0-...-648f786 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerTopicPrefix = "/sys"
	DeviceTopicPrefix = "/device"
)
View Source
const SupportPackageIsVersion1 = true

SupportPackageIsVersion1 These constants should not be referenced from any other code.

Variables

This section is empty.

Functions

func DefaultErrorEncoder

func DefaultErrorEncoder(c pmqtt.Client, topic string, err error)

DefaultErrorEncoder encodes the error to the mqtt response.

func DefaultRequestDecoder

func DefaultRequestDecoder(data []byte, v interface{}) error

DefaultRequestDecoder decodes the request body to object.

func DefaultResponseEncoder

func DefaultResponseEncoder(c pmqtt.Client, topic string, v interface{}) error

DefaultResponseEncoder encodes the object to the mqtt reply.

Types

type Context

type Context interface {
	context.Context
	Client() pmqtt.Client
	Message() pmqtt.Message
	Reset(context.Context, pmqtt.Client, pmqtt.Message, *mux.Params)
	Middleware(middleware.Handler) middleware.Handler
	Bind(v interface{}) error
	BindVars(v interface{}) error
	Reply(v interface{}) error
	ReplyErr(err error)
}

Context is an MQTT Context.

type DecodeRequestFunc

type DecodeRequestFunc func([]byte, interface{}) error

DecodeRequestFunc is decode request func.

type EncodeErrorFunc

type EncodeErrorFunc func(c pmqtt.Client, topic string, err error)

EncodeErrorFunc is encode error func.

type EncodeResponseFunc

type EncodeResponseFunc func(c pmqtt.Client, topic string, v interface{}) error

EncodeResponseFunc is encode response func.

type HandlerFunc

type HandlerFunc func(Context)

HandlerFunc defines a function to serve MQTT requests.

type MQTTSubscribe

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

func (*MQTTSubscribe) SetServer

func (m *MQTTSubscribe) SetServer(srv *Server)

func (*MQTTSubscribe) Subscribe

func (m *MQTTSubscribe) Subscribe(c mqtt.Client, topic string, qos byte)

type Router

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

Router is an MQTT router.

func (*Router) Handle

func (r *Router) Handle(topic string, h HandlerFunc)

Handle registers a new route with a matcher for the Topic.

type Server

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

func NewServer

func NewServer(opts ...ServerOption) *Server

NewServer creates an MQTT server by options.

func (*Server) Route

func (s *Server) Route() *Router

Route registers an MQTT router.

func (*Server) Start

func (o *Server) Start(ctx context.Context) error

func (*Server) Stop

func (o *Server) Stop(ctx context.Context) error

func (*Server) Subscribe

func (s *Server) Subscribe(c mqtt.Client, topic string, qos byte)

Subscribe to topic

type ServerOption

type ServerOption func(*Server)

ServerOption is an MQTT server option.

func AutoReconnect

func AutoReconnect(autoReconnect bool) ServerOption

AutoReconnect with mqtt client autoReconnect.

func Broker

func Broker(broker string) ServerOption

Broker with mqtt client broker.

func CleanSession

func CleanSession(cleanSession bool) ServerOption

CleanSession with mqtt client cleanSession.

func ClientId

func ClientId(clientId string) ServerOption

ClientId with mqtt client clientId.

func ConnectTimeout

func ConnectTimeout(timeout time.Duration) ServerOption

ConnecTimeout with mqtt client connecTimeout.

func ConnectionLostHandler

func ConnectionLostHandler(connectLostHandler pmqtt.ConnectionLostHandler) ServerOption

ConnectionLostHandler with mqtt client connectLostHandler.

func DisconnectQuiesce

func DisconnectQuiesce(quiesce uint) ServerOption

DisconnectQuiesce with mqtt client disconnectQuiesce.

func ErrorEncoder

func ErrorEncoder(en EncodeErrorFunc) ServerOption

ErrorEncoder with error encoder.

func Logger

func Logger(logger log.Logger) ServerOption

Logger with server logger.

func Middleware

func Middleware(m ...middleware.Middleware) ServerOption

Middleware with service middleware option.

func OnConnectHandler

func OnConnectHandler(onConnectHandler pmqtt.OnConnectHandler) ServerOption

OnConnectHandler with mqtt client onConnectHandler.

func OrderMatters

func OrderMatters(orderMatters bool) ServerOption

orderMatters with mqtt client orderMatters.

func Password

func Password(password string) ServerOption

Password with mqtt client password.

func PingTimeout

func PingTimeout(timeout time.Duration) ServerOption

PingTimeout with mqtt client pingTimeout.

func RequestDecoder

func RequestDecoder(dec DecodeRequestFunc) ServerOption

RequestDecoder with request decoder.

func ResponseEncoder

func ResponseEncoder(en EncodeResponseFunc) ServerOption

ResponseEncoder with response encoder.

func ResumeSubs

func ResumeSubs(resumeSubs bool) ServerOption

ResumeSubs with mqtt client resumeSubs.

func Username

func Username(username string) ServerOption

Username with mqtt client username.

Directories

Path Synopsis
The registered topic, against which the router matches incoming requests, can contain two types of parameters:
The registered topic, against which the router matches incoming requests, can contain two types of parameters:

Jump to

Keyboard shortcuts

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