mqttclient

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 14 Imported by: 1

README

MQTT Client Package

The mqttclient package provides MQTT (Message Queuing Telemetry Transport) client functionality for IoT and messaging applications.

Features

  • MQTT Protocol Support: Connect to MQTT brokers
  • Message Handling: Subscribe and publish to MQTT topics
  • Utility Functions: Helper functions for MQTT operations

Main Components

MQTT Client

Wraps the Paho MQTT client for:

  • Connecting to MQTT brokers
  • Subscribing to topics
  • Publishing messages
  • Handling disconnections
Utilities

Helper functions for:

  • Message parsing
  • Topic management
  • Connection handling

Usage

// Connect to MQTT broker
client := mqttclient.New(config)

// Subscribe to topic
client.Subscribe("sensors/temperature", func(msg mqtt.Message) {
    // Handle message
})

// Publish message
client.Publish("sensors/humidity", payload)

Configuration

  • Broker URL
  • Client ID
  • Authentication credentials
  • QoS levels
  • Connection options

Dependencies

  • Eclipse Paho MQTT Go client
  • Zap for logging

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSharedTopic added in v0.12.0

func GetSharedTopic(topic string) string

Types

type MqttService

type MqttService struct {
	Endpoint      string
	User          string
	Password      string
	ClientID      string
	MaxPubWindow  int
	Cleansession  bool
	AutoReconnect bool
	Qos           byte
	TlsConfig     *TlsConfig

	Logger *zap.Logger
	Client mqtt.Client
	// contains filtered or unexported fields
}

func InitMqttService added in v0.12.0

func InitMqttService(clientID string, qos byte, cleansession bool, yamlKey string) (*MqttService, error)

func (*MqttService) LogMessage

func (m *MqttService) LogMessage(c mqtt.Client, msg mqtt.Message)

func (*MqttService) OnConnect

func (m *MqttService) OnConnect(c mqtt.Client)

func (*MqttService) Pub added in v0.10.18

func (m *MqttService) Pub(topic string, qos byte, retained bool, payload any) error

func (*MqttService) StartHeartbeat added in v0.10.18

func (m *MqttService) StartHeartbeat(serviceNmae, hbSchedule string)

func (*MqttService) Sub

func (m *MqttService) Sub(topic string, handle mqtt.MessageHandler) error

type TlsConfig added in v0.10.14

type TlsConfig struct {
	Ca   string
	Key  string
	Cert string
}

Jump to

Keyboard shortcuts

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