mqtt

package
v0.174.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

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

Variables

This section is empty.

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 added in v0.137.0

type DefaultDialer struct{}

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

func (DefaultDialer) Dial added in v0.137.0

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 added in v0.140.0

type ErrorDialer struct{}

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

func (ErrorDialer) Dial added in v0.140.0

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.

Jump to

Keyboard shortcuts

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