mqtt

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AddToSchema = configBuilder.AddToSchema
)
View Source
var ConnectionConfigSpec = conf.SectionSpec{
	{
		Name:        "Name",
		Type:        conf.StringType,
		Description: "The name of the connection mainly used in references.",
		Required:    true,
	},
	{
		Name:        "Server",
		Type:        conf.StringSliceType,
		Description: "Mqtt server address",
		Required:    true,
	},
	{
		Name:        "ClientID",
		Type:        conf.StringType,
		Description: "Client ID for MQTT. A random ID will be created for each connection if left empty.",
	},
	{
		Name:        "KeepAliveSeconds",
		Type:        conf.IntType,
		Description: "Number of seconds for MQTT keep-alive",
		Default:     "60",
	},
	{
		Name:        "User",
		Type:        conf.StringType,
		Description: "Username for MQTT server",
	},
	{
		Name:        "Password",
		Type:        conf.StringType,
		Description: "Password for MQTT server",
		Annotations: new(conf.Annotation).With(
			conf.SecretValue(),
		),
	},
}

ConnectionConfigSpec defines all allowed MQTT configuration stanzas.

View Source
var DefaultConnectionManager = NewConnectionManager(runtime.GlobalSchema)

DefaultConnectionManager is the default connection manager that keeps track of configured and established MQTT connections. Note that the DefaultConnectionManager is bound to runtime.GlobalSchema!

View Source
var TriggerSpec = conf.SectionSpec{
	{
		Name:        "ConnectionName",
		Description: "The name of the MQTT connection configuration. Defaults to the first configuration.",
		Type:        conf.StringType,
		Annotations: new(conf.Annotation).With(
			runtime.OneOfRef("MQTT", "Name", "Name"),
		),
	},
	{
		Name:        "TopicPrefix",
		Description: "Prefix for the event topic",
		Type:        conf.StringType,
		Aliases:     []string{"Topic"},
	},
	{
		Name:        "EventAsTopic",
		Description: "Whether or not the event ID is used as a topic. If false, TopicPrefix or Topic must be set.",
		Type:        conf.BoolType,
		Default:     "yes",
	},
	{
		Name:        "QualityOfService",
		Description: "The QoS to use when publishing messages",
		Type:        conf.IntType,
		Default:     "0",
	},
}

Functions

func AddTriggerType

func AddTriggerType(reg *trigger.Registry, connectionManager *ConnectionManager) error

AddTriggerType registers the MQTT trigger on the registry reg.

Types

type Client

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

func (*Client) Release

func (cli *Client) Release()

type ConnectionConfig

type ConnectionConfig struct {
	Name             string
	Server           []string
	ClientID         string
	KeepAliveSeconds int
	User             string
	Password         string
}

ConnectionConfig groups all MQTT related configuration settings.

func (ConnectionConfig) GetClient

func (cfg ConnectionConfig) GetClient(ctx context.Context) (mqtt.Client, error)

GetClient returns a new MQTT client based on the configuration settings in cfg.

type ConnectionManager

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

func NewConnectionManager

func NewConnectionManager(cs *runtime.ConfigSchema) *ConnectionManager

NewConnectionManager returns a new MQTT connection manager.

func (*ConnectionManager) Client

func (cm *ConnectionManager) Client(ctx context.Context, name string) (*Client, error)

func (*ConnectionManager) ClientWithRandomID

func (cm *ConnectionManager) ClientWithRandomID(ctx context.Context, name string) (*Client, error)

ClientWithRandomID returns a new, connected MQTT client created from the configration identified by name. The ID of the client is a random string to not interfer with other instances of the above configuration.

type EventPublisher

type EventPublisher struct {
	ConnectionName   string
	TopicPrefix      string
	EventAsTopic     bool
	QualityOfService int
	// contains filtered or unexported fields
}

func (*EventPublisher) HandleEvents

func (pub *EventPublisher) HandleEvents(ctx context.Context, evts ...*event.Event) error

HandleEvent implements (event.Handler).

Jump to

Keyboard shortcuts

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