mqtt

package
v0.0.0-...-4086bda Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package mqtt provides support for handling messages from the gateway and emitting messages to the gateway using MQTT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBroker

func NewBroker(t *testing.T) (*mqtt.Server, *url.URL)

NewBroker creates a local MQTT broker that can be used for testing.

func NewEmitter

func NewEmitter(opts ...Opt[Emitter]) transport.Emitter

Types

type Emitter

type Emitter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Emitter is an implementation of transport.Emitter that uses MQTT as the transport.

Messages are published on a topic that is composed of a number of elements: <prefix>/out/<ocpp-version>/<cs-id>. The prefix is configured, the ocpp-version and cs-id are provided to the Emit function. If not configured the default prefix is `cs`.

The Emitter defaults to connecting to a broker on 127.0.0.1:1883.

func (*Emitter) Emit

func (e *Emitter) Emit(ctx context.Context, ocppVersion transport.OcppVersion, chargeStationId string, message *transport.Message) error

type Listener

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

func NewListener

func NewListener(opts ...Opt[Listener]) *Listener

func (*Listener) Connect

func (l *Listener) Connect(ctx context.Context, ocppVersion transport.OcppVersion, chargeStationId *string, handler transport.MessageHandler) (transport.Connection, error)

type Opt

type Opt[T any] func(h *T)

func WithMqttBrokerUrl

func WithMqttBrokerUrl[T Emitter | Listener](brokerUrl *url.URL) Opt[T]

func WithMqttBrokerUrls

func WithMqttBrokerUrls[T Emitter | Listener](brokerUrls []*url.URL) Opt[T]

func WithMqttConnectSettings

func WithMqttConnectSettings[T Emitter | Listener](mqttConnectTimeout, mqttConnectRetryDelay, mqttKeepAliveInterval time.Duration) Opt[T]

func WithMqttGroup

func WithMqttGroup[T Listener](mqttGroup string) Opt[T]

func WithMqttPrefix

func WithMqttPrefix[T Emitter | Listener](mqttPrefix string) Opt[T]

func WithOtelTracer

func WithOtelTracer[T Emitter | Listener](tracer trace.Tracer) Opt[T]

Jump to

Keyboard shortcuts

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