package mqtt

import "github.com/influxdata/flux/dependencies/mqtt"

Index

Constants

const (
	DefaultTimeout  = 1 * time.Second
	DefaultClientID = "flux-mqtt"
)

Functions

func Inject

func Inject(ctx context.Context, dialer Dialer) context.Context

Inject will inject this Dialer into the dependency chain.

Types

type Client

type Client interface {
	// Publish will publish the payload to a particular topic.
	Publish(ctx context.Context, topic string, qos byte, retain bool, payload interface{}) error

	io.Closer
}

Client is an mqtt client that can publish to an mqtt broker.

type DefaultDialer

type DefaultDialer struct{}

DefaultDialer is the default dialer that uses the default mqtt client.

func (DefaultDialer) Dial

func (d DefaultDialer) Dial(ctx context.Context, brokers []string, options Options) (Client, error)

type Dependency

type Dependency struct {
	Dialer Dialer
}

Dependency will inject the Dialer into the dependency chain.

func (Dependency) Inject

func (d Dependency) Inject(ctx context.Context) context.Context

Inject will inject the Dialer into the dependency chain.

type Dialer

type Dialer interface {
	// Dial will connect to the given brokers and return a Client.
	Dial(ctx context.Context, brokers []string, options Options) (Client, error)
}

Dialer provides a method to connect a client to one or more mqtt brokers.

func GetDialer

func GetDialer(ctx context.Context) Dialer

GetDialer will return the Dialer for the current context. If no Dialer has been injected into the dependencies, this will return a default provider.

type ErrorDialer

type ErrorDialer struct{}

ErrorDialer is the default dialer that uses the default mqtt client.

func (ErrorDialer) Dial

func (d ErrorDialer) Dial(ctx context.Context, brokers []string, options Options) (Client, error)

type Options

type Options struct {
	ClientID string
	Username string
	Password string
	Timeout  time.Duration
}

Options contains additional options for configuring the mqtt client.

Source Files

mqtt.go

Version
v0.196.1 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
10 packages
Last checked
1 day ago

Tools for package owners.