mqtt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 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.

Package mqtt is a generated GoMock package.

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
	KeepAlive        time.Duration
	CloseTimeout     time.Duration
}

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) Close

func (m *MQTT) Close() error

func (*MQTT) CreateTopic

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

func (*MQTT) DeleteTopic

func (*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) error

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 MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) AddRoute

func (m *MockClient) AddRoute(arg0 string, arg1 mqtt.MessageHandler)

AddRoute mocks base method.

func (*MockClient) Connect

func (m *MockClient) Connect() mqtt.Token

Connect mocks base method.

func (*MockClient) Disconnect

func (m *MockClient) Disconnect(arg0 uint)

Disconnect mocks base method.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

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

func (*MockClient) IsConnected

func (m *MockClient) IsConnected() bool

IsConnected mocks base method.

func (*MockClient) IsConnectionOpen

func (m *MockClient) IsConnectionOpen() bool

IsConnectionOpen mocks base method.

func (*MockClient) OptionsReader

func (m *MockClient) OptionsReader() mqtt.ClientOptionsReader

OptionsReader mocks base method.

func (*MockClient) Publish

func (m *MockClient) Publish(arg0 string, arg1 byte, arg2 bool, arg3 any) mqtt.Token

Publish mocks base method.

func (*MockClient) Subscribe

func (m *MockClient) Subscribe(arg0 string, arg1 byte, arg2 mqtt.MessageHandler) mqtt.Token

Subscribe mocks base method.

func (*MockClient) SubscribeMultiple

func (m *MockClient) SubscribeMultiple(arg0 map[string]byte, arg1 mqtt.MessageHandler) mqtt.Token

SubscribeMultiple mocks base method.

func (*MockClient) Unsubscribe

func (m *MockClient) Unsubscribe(arg0 ...string) mqtt.Token

Unsubscribe mocks base method.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) AddRoute

func (mr *MockClientMockRecorder) AddRoute(arg0, arg1 any) *gomock.Call

AddRoute indicates an expected call of AddRoute.

func (*MockClientMockRecorder) Connect

func (mr *MockClientMockRecorder) Connect() *gomock.Call

Connect indicates an expected call of Connect.

func (*MockClientMockRecorder) Disconnect

func (mr *MockClientMockRecorder) Disconnect(arg0 any) *gomock.Call

Disconnect indicates an expected call of Disconnect.

func (*MockClientMockRecorder) IsConnected

func (mr *MockClientMockRecorder) IsConnected() *gomock.Call

IsConnected indicates an expected call of IsConnected.

func (*MockClientMockRecorder) IsConnectionOpen

func (mr *MockClientMockRecorder) IsConnectionOpen() *gomock.Call

IsConnectionOpen indicates an expected call of IsConnectionOpen.

func (*MockClientMockRecorder) OptionsReader

func (mr *MockClientMockRecorder) OptionsReader() *gomock.Call

OptionsReader indicates an expected call of OptionsReader.

func (*MockClientMockRecorder) Publish

func (mr *MockClientMockRecorder) Publish(arg0, arg1, arg2, arg3 any) *gomock.Call

Publish indicates an expected call of Publish.

func (*MockClientMockRecorder) Subscribe

func (mr *MockClientMockRecorder) Subscribe(arg0, arg1, arg2 any) *gomock.Call

Subscribe indicates an expected call of Subscribe.

func (*MockClientMockRecorder) SubscribeMultiple

func (mr *MockClientMockRecorder) SubscribeMultiple(arg0, arg1 any) *gomock.Call

SubscribeMultiple indicates an expected call of SubscribeMultiple.

func (*MockClientMockRecorder) Unsubscribe

func (mr *MockClientMockRecorder) Unsubscribe(arg0 ...any) *gomock.Call

Unsubscribe indicates an expected call of Unsubscribe.

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...any)

Debug mocks base method.

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(format string, args ...any)

Debugf mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

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

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(format string, args ...any)

Errorf mocks base method.

func (*MockLogger) Infof

func (m *MockLogger) Infof(format string, args ...any)

Infof mocks base method.

func (*MockLogger) Warnf

func (m *MockLogger) Warnf(format string, args ...any)

Warnf mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(args ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Debugf

func (mr *MockLoggerMockRecorder) Debugf(format any, args ...any) *gomock.Call

Debugf indicates an expected call of Debugf.

func (*MockLoggerMockRecorder) Errorf

func (mr *MockLoggerMockRecorder) Errorf(format any, args ...any) *gomock.Call

Errorf indicates an expected call of Errorf.

func (*MockLoggerMockRecorder) Infof

func (mr *MockLoggerMockRecorder) Infof(format any, args ...any) *gomock.Call

Infof indicates an expected call of Infof.

func (*MockLoggerMockRecorder) Warnf

func (mr *MockLoggerMockRecorder) Warnf(format any, args ...any) *gomock.Call

Warnf indicates an expected call of Warnf.

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 any, labels ...any) *gomock.Call

IncrementCounter indicates an expected call of IncrementCounter.

type MockPubSub

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

MockPubSub is a mock of PubSub interface.

func NewMockPubSub

func NewMockPubSub(ctrl *gomock.Controller) *MockPubSub

NewMockPubSub creates a new mock instance.

func (*MockPubSub) Disconnect

func (m *MockPubSub) Disconnect(waitTime uint) error

Disconnect mocks base method.

func (*MockPubSub) EXPECT

func (m *MockPubSub) EXPECT() *MockPubSubMockRecorder

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

func (*MockPubSub) Health

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

Health mocks base method.

func (*MockPubSub) Ping

func (m *MockPubSub) Ping() error

Ping mocks base method.

func (*MockPubSub) Publish

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

Publish mocks base method.

func (*MockPubSub) SubscribeWithFunction

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

SubscribeWithFunction mocks base method.

func (*MockPubSub) Unsubscribe

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

Unsubscribe mocks base method.

type MockPubSubMockRecorder

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

MockPubSubMockRecorder is the mock recorder for MockPubSub.

func (*MockPubSubMockRecorder) Disconnect

func (mr *MockPubSubMockRecorder) Disconnect(waitTime any) *gomock.Call

Disconnect indicates an expected call of Disconnect.

func (*MockPubSubMockRecorder) Health

func (mr *MockPubSubMockRecorder) Health() *gomock.Call

Health indicates an expected call of Health.

func (*MockPubSubMockRecorder) Ping

func (mr *MockPubSubMockRecorder) Ping() *gomock.Call

Ping indicates an expected call of Ping.

func (*MockPubSubMockRecorder) Publish

func (mr *MockPubSubMockRecorder) Publish(ctx, topic, message any) *gomock.Call

Publish indicates an expected call of Publish.

func (*MockPubSubMockRecorder) SubscribeWithFunction

func (mr *MockPubSubMockRecorder) SubscribeWithFunction(topic, subscribeFunc any) *gomock.Call

SubscribeWithFunction indicates an expected call of SubscribeWithFunction.

func (*MockPubSubMockRecorder) Unsubscribe

func (mr *MockPubSubMockRecorder) Unsubscribe(topic any) *gomock.Call

Unsubscribe indicates an expected call of Unsubscribe.

type MockToken

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

MockToken is a mock of Token interface.

func NewMockToken

func NewMockToken(ctrl *gomock.Controller) *MockToken

NewMockToken creates a new mock instance.

func (*MockToken) Done

func (m *MockToken) Done() <-chan struct{}

Done mocks base method.

func (*MockToken) EXPECT

func (m *MockToken) EXPECT() *MockTokenMockRecorder

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

func (*MockToken) Error

func (m *MockToken) Error() error

Error mocks base method.

func (*MockToken) Wait

func (m *MockToken) Wait() bool

Wait mocks base method.

func (*MockToken) WaitTimeout

func (m *MockToken) WaitTimeout(arg0 time.Duration) bool

WaitTimeout mocks base method.

type MockTokenMockRecorder

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

MockTokenMockRecorder is the mock recorder for MockToken.

func (*MockTokenMockRecorder) Done

func (mr *MockTokenMockRecorder) Done() *gomock.Call

Done indicates an expected call of Done.

func (*MockTokenMockRecorder) Error

func (mr *MockTokenMockRecorder) Error() *gomock.Call

Error indicates an expected call of Error.

func (*MockTokenMockRecorder) Wait

func (mr *MockTokenMockRecorder) Wait() *gomock.Call

Wait indicates an expected call of Wait.

func (*MockTokenMockRecorder) WaitTimeout

func (mr *MockTokenMockRecorder) WaitTimeout(arg0 any) *gomock.Call

WaitTimeout indicates an expected call of WaitTimeout.

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) error
	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