mqtt

package
v0.8.12 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultMQTTBufferSize is the default capacity of the
	// internal Go channel.
	DefaultMQTTBufferSize = dsl.DefaultChanBufferSize
)

Functions

func NewMQTTChan

func NewMQTTChan(ctx *dsl.Ctx, opts interface{}) (dsl.Chan, error)

Types

type MQTT

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

MQTT is an MQTT client Chan.

This channel impl talks MQTT to a broker. The configuration provides the data required to set up the connections. Messages published to this channel are forwarded to the MQTT broker, and messages received from the MQTT broker are available for a test to receive.

The topic of a message published to the channel becomes the MQTT topic for the message. Similarly, the topic of the message received from the broker becomes the topic of the message the test sees.

func (*MQTT) Close

func (c *MQTT) Close(ctx *dsl.Ctx) error

func (*MQTT) DocSpec

func (c *MQTT) DocSpec() *dsl.DocSpec

func (*MQTT) Kill

func (c *MQTT) Kill(ctx *dsl.Ctx) error

Kill is not currently supported. (It should be but the paho client does not support ungraceful termination of the connection.)

ToDo: Terminate the subprocess ungracefully.

func (*MQTT) Kind

func (c *MQTT) Kind() dsl.ChanKind

func (*MQTT) Open

func (c *MQTT) Open(ctx *dsl.Ctx) error

func (*MQTT) Pub

func (c *MQTT) Pub(ctx *dsl.Ctx, m dsl.Msg) error

func (*MQTT) Recv

func (c *MQTT) Recv(ctx *dsl.Ctx) chan dsl.Msg

func (*MQTT) Sub

func (c *MQTT) Sub(ctx *dsl.Ctx, topic string) error

func (*MQTT) To

func (c *MQTT) To(ctx *dsl.Ctx, m dsl.Msg) error

type MQTTOpts

type MQTTOpts struct {

	// BrokerURL is the URL for the MQTT broker.
	//
	// This required value has the form "PROTOCOL://HOST:PORT".
	BrokerURL string `json:",omitempty" yaml:",omitempty"`

	// CertFile is the optional filename for the client's certificate.
	CertFile string `json:",omitempty" yaml:",omitempty"`

	// CACertFile is the optional filename for the certificate
	// authority.
	CACertFile string `json:",omitempty" yaml:",omitempty"`

	// KeyFile is the optional filename for the client's private key.
	KeyFile string `json:",omitempty" yaml:",omitempty"`

	// Insecure will given the value for the tls.Config InsecureSkipVerify.
	//
	// This flag specifies whether a client verifies the server's
	// certificate chain and host name. If InsecureSkipVerify is
	// true, crypto/tls accepts any certificate presented by the
	// server and any host name in that certificate. In this mode,
	// TLS is susceptible to machine-in-the-middle attacks unless
	// custom verification is used. This should be used only for
	// testing.
	Insecure bool `json:",omitempty" yaml:",omitempty"`

	// ALPN gives the
	// https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation
	// for the connection.
	//
	// For example, see
	// https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html.
	ALPN string `json:",omitempty" yaml:",omitempty"`

	// Token is the optional value for the header given by
	// TokenHeader.
	//
	// See
	// https://docs.aws.amazon.com/iot/latest/developerguide/custom-authorizer.html.
	//
	// When Token is not empty, then you should probably also
	// provide AuthorizerName and TokenSig.
	Token string `json:",omitempty" yaml:",omitempty"`

	// TokenHeader is the name of the header which will have the
	// value given by Token.
	TokenHeader string `json:",omitempty" yaml:",omitempty"`

	// AuthorizerName is the optional value for the header
	// "x-amz-customauthorizer-name", which is used when making a
	// AWS IoT Core WebSocket connection that will call an AWS IoT
	// custom authorizer.
	//
	// See
	// https://docs.aws.amazon.com/iot/latest/developerguide/custom-authorizer.html.
	AuthorizerName string `json:",omitempty" yaml:",omitempty"`

	// TokenSig is the signature for the token for a WebSocket
	// connection to AWS IoT Core.
	//
	// See
	// https://docs.aws.amazon.com/iot/latest/developerguide/custom-authorizer.html.
	TokenSig string `json:",omitempty" yaml:",omitempty"`

	// BufferSize specifies the capacity of the internal Go
	// channel.
	//
	// The default is DefaultMQTTBufferSize.
	BufferSize int `json:",omitempty yaml:",omitempty"`

	// PubTimeout is the timeout in milliseconds for MQTT PUBACK.
	PubTimeout int64 `json:",omitempty" yaml:",omitempty"`

	// SubTimeout is the timeout in milliseconds for MQTT SUBACK.
	SubTimeout int64 `json:",omitempty" yaml:",omitempty"`

	// ClientID is MQTT client id.
	ClientID string `json:",omitempty" yaml:",omitempty"`

	// Username is the optional MQTT client username.
	Username string `json:",omitempty" yaml:",omitempty"`

	// Password is the optional MQTT client password.
	Password string `json:",omitempty" yaml:",omitempty"`

	// CleanSession, when true, will not resume a previous MQTT
	// session for this client id.
	CleanSession bool `json:",omitempty" yaml:",omitempty"`

	// WillEnabled, if true, will establish an MQTT Last Will and Testament.
	//
	// See WillTopic, WillPayload, WillQoS, and WillRetained.
	WillEnabled bool `json:",omitempty" yaml:",omitempty"`

	// WillTopic gives the MQTT LW&T topic.
	//
	// See WillEnabled.
	WillTopic string `json:",omitempty" yaml:",omitempty"`

	// WillPayload gives the MQTT LW&T payload.
	//
	// See WillEnabled.
	WillPayload string `json:",omitempty" yaml:",omitempty"`

	// WillQoS specifies the MQTT LW&T QoS.
	//
	// See WillEnabled.
	WillQoS byte `json:",omitempty" yaml:",omitempty"`

	// WillRetained specifies the MQTT LW&T retained flag.
	//
	// See WillEnabled.
	WillRetained bool `json:",omitempty" yaml:",omitempty"`

	// KeepAlive is the duration in seconds that the MQTT client
	// should wait before sending a PING request to the broker.
	KeepAlive int64 `json:",omitempty" yaml:",omitempty"`

	// PingTimeout is the duration in seconds that the client will
	// wait after sending a PING request to the broker before
	// deciding that the connection has been lost.  The default is
	// 10 seconds.
	PingTimeout int64 `json:",omitempty" yaml:",omitempty"`

	// ConnectTimeout is the duration in seconds that the MQTT
	// client will wait after attempting to open a connection to
	// the broker.  A duration of 0 never times out.  The default
	// 30 seconds.
	//
	// This property does not apply to WebSocket connections.
	ConnectTimeout int64 `json:",omitempty" yaml:",omitempty"`

	// MaxReconnectInterval specifies maximum duration in
	// seconds between reconnection attempts.
	MaxReconnectInterval int64 `json:",omitempty" yaml:",omitempty"`

	// AutoReconnect turns on automation reconnection attempts
	// when a connection is lost.
	AutoReconnect bool `json:",omitempty" yaml:",omitempty"`

	// WriteTimeout is the duration to wait for a PUBACK.
	WriteTimeout int64 `json:",omitempty" yaml:",omitempty"`

	// ResumeSubs enables resuming of stored (un)subscribe
	// messages when connecting but not reconnecting if
	// CleanSession is false.
	ResumeSubs bool `json:",omitempty" yaml:",omitempty"`
}

MQTTOpts is partly subset of mq.ClientOptions that can be deserialized.

This data specifies everything required to attempt the connection to the MQTT broker.

func (*MQTTOpts) Opts

func (o *MQTTOpts) Opts(ctx *dsl.Ctx) (*mq.ClientOptions, error)

Opts constructions an mq.ClientOptions.

Jump to

Keyboard shortcuts

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