mqtt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout           = 5  // seconds
	DefaultConnectionTimeout = 30 // seconds

	ErrMissingBroker   = utils.Error("at least one broker must be specified")
	ErrInvalidProtocol = utils.Error("invalid protocol")
	ErrInvalidTimeout  = utils.Error("invalid timeout")
	ErrInvalidQoSLevel = utils.Error("invalid QoS level")
	ErrPublishTimeout  = utils.Error("timeout when publishing")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ClientOptions *paho.ClientOptions
	Client        paho.Client
	QoS           byte
	Timeout       time.Duration
	Retain        bool
}

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) AddRoute

func (c *Client) AddRoute(topic string, handler paho.MessageHandler)

func (*Client) ChannelSubscribe

func (c *Client) ChannelSubscribe(topic string, qos byte, ch chan paho.Message) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect() (bool, error)

func (*Client) CustomSettings

func (c *Client) CustomSettings() error

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, qos byte, handler paho.MessageHandler) error

func (*Client) SubscribeMultiple

func (c *Client) SubscribeMultiple(filters map[string]byte, handler paho.MessageHandler) error

func (*Client) Write

func (c *Client) Write(topic string, value []byte) error

func (*Client) WriteJson

func (c *Client) WriteJson(topic string, value interface{}) error

type Config

type Config struct {
	Brokers           []string `json:"brokers"`
	Protocol          string   `json:"protocol"`
	Username          string   `json:"username"`
	Password          string   `json:"password"`
	Timeout           int      `json:"timeout"`
	ConnectionTimeout int      `json:"connectionTimeout"`
	QoS               int      `json:"qos"`
	ClientID          string   `json:"clientId"`
	Retain            bool     `json:"retain"`
	KeepAlive         int64    `json:"keepAlive"`
	AutoReconnect     bool     `json:"autoReconnect"`
	PersistentSession bool     `json:"persistentSession"`
	tlsProvider.ClientConfig
	MqttHandlers `json:"-"`
}

func NewConfig

func NewConfig() *Config

func (*Config) Validate

func (c *Config) Validate() error

type MqttHandlers

type MqttHandlers struct {
	DefaultPublishHandler  paho.MessageHandler
	OnConnect              paho.OnConnectHandler
	OnConnectionLost       paho.ConnectionLostHandler
	OnReconnecting         paho.ReconnectHandler
	OnConnectAttempt       paho.ConnectionAttemptHandler
	CustomOpenConnectionFn paho.OpenConnectionFunc
}

Jump to

Keyboard shortcuts

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