mqtt

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mqtt provides a client for interacting with MQTT message brokers.This package facilitates interaction with MQTT brokers, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.

Package mqtt is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Protocol         string
	Hostname         string
	Port             int
	Username         string
	Password         string
	ClientID         string
	QoS              byte
	Order            bool
	RetrieveRetained bool
}

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

type MQTT

type MQTT struct {
	// contains filtered or unexported fields
	mqtt.Client
	// contains filtered or unexported fields
}

MQTT is the struct that implements PublisherSubscriber interface to provide functionality for the MQTT as a pubsub.

func New

func New(config *Config, logger Logger, metrics Metrics) *MQTT

New establishes a connection to MQTT Broker using the configs and return pubsub.MqttPublisherSubscriber with more MQTT focused functionalities related to subscribing(push), unsubscribing and disconnecting from broker.

func (*MQTT) CreateTopic

func (m *MQTT) CreateTopic(_ context.Context, topic string) error

func (*MQTT) DeleteTopic

func (m *MQTT) DeleteTopic(_ context.Context, _ string) error

DeleteTopic is implemented to adhere to the PubSub Client interface Note: there is no concept of deletion.

func (*MQTT) Disconnect

func (m *MQTT) Disconnect(waitTime uint)

func (*MQTT) Health

func (m *MQTT) Health() datasource.Health

func (*MQTT) Ping

func (m *MQTT) Ping() error

func (*MQTT) Publish

func (m *MQTT) Publish(ctx context.Context, topic string, message []byte) error

func (*MQTT) Subscribe

func (m *MQTT) Subscribe(ctx context.Context, topic string) (*pubsub.Message, error)

func (*MQTT) SubscribeWithFunction

func (m *MQTT) SubscribeWithFunction(topic string, subscribeFunc SubscribeFunc) error

SubscribeWithFunction subscribe with a subscribing function, called whenever broker publishes a message.

func (*MQTT) Unsubscribe

func (m *MQTT) Unsubscribe(topic string) error

type Metrics

type Metrics interface {
	IncrementCounter(ctx context.Context, name string, labels ...string)
}

type MockMetrics

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

MockMetrics is a mock of Metrics interface.

func NewMockMetrics

func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics

NewMockMetrics creates a new mock instance.

func (*MockMetrics) EXPECT

func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMetrics) IncrementCounter

func (m *MockMetrics) IncrementCounter(ctx context.Context, name string, labels ...string)

IncrementCounter mocks base method.

type MockMetricsMockRecorder

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

MockMetricsMockRecorder is the mock recorder for MockMetrics.

func (*MockMetricsMockRecorder) IncrementCounter

func (mr *MockMetricsMockRecorder) IncrementCounter(ctx, name interface{}, labels ...interface{}) *gomock.Call

IncrementCounter indicates an expected call of IncrementCounter.

type PubSub

type PubSub interface {
	SubscribeWithFunction(topic string, subscribeFunc SubscribeFunc) error
	Publish(ctx context.Context, topic string, message []byte) error
	Unsubscribe(topic string) error
	Disconnect(waitTime uint)
	Ping() error
	Health() datasource.Health
}

type SubscribeFunc

type SubscribeFunc func(*pubsub.Message) error

Jump to

Keyboard shortcuts

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