mqtt

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mqtt implements the "mqtt" protocol.Protocol driver, for load testing an MQTT 3.1.1 broker. It uses the Eclipse Paho client.

Each call to Do opens its own connection, does one job, and closes. That measures connect, publish and delivery time under load. It is not a long-lived session. The job is chosen with -opt mode=...:

publish    connect, publish the body, wait for the broker's ack. This
           is the default.
subscribe  connect, subscribe, wait for count messages.
roundtrip  connect, subscribe, publish the body, wait until this
           iteration's own message comes back. This measures delivery
           through the broker. The body must contain {id}, so the driver
           can tell its own message from another user's.

Options (set with -opt key=value):

mode           publish (default), subscribe, or roundtrip.
topic          The topic. Required. {id} is replaced by this
               iteration's unique client id, so each iteration can
               have its own topic. Publish and roundtrip topics must
               not have wildcards.
qos            0 (default), 1, or 2.
retain         true to publish the message as retained.
username       The user name.
password_env   The name of an environment variable that holds the
               password. It needs username. The password is never put
               on the command line.
client_id      A prefix for the client ids (default "vegaload"). Each
               iteration adds a unique suffix, because a broker closes
               an older connection that has the same id.
count          subscribe and roundtrip: messages to wait for (default 1).
expect         subscribe: every message must contain this text.
keepalive      Keep-alive time, such as 30s (default 30s).

Every iteration asks for a clean session, so the broker keeps nothing between iterations. The body is the message payload. {id} in it is replaced too. Use an mqtts:// target for TLS.

Index

Constants

This section is empty.

Variables

View Source
var Options = append([]string{
	"mode", "topic", "qos", "retain", "username", "password_env",
	"client_id", "count", "expect", "keepalive",
}, tlsconf.Keys...)

Options are the -opt keys this driver accepts. The command's protocol table uses the same list, so the two cannot differ.

Functions

This section is empty.

Types

type Driver

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

Driver is an MQTT protocol.Protocol.

func New

func New(target protocol.Target, timeout time.Duration) (*Driver, error)

New returns a ready-to-use Driver for target. target.URL is mqtt://host or mqtts://host, with an optional :port (1883, or 8883 for mqtts).

New returns an error only for a configuration problem, never for the broker being unreachable, which Do reports per call.

func NewWithPassword

func NewWithPassword(target protocol.Target, timeout time.Duration, password string) (*Driver, error)

NewWithPassword is New for a caller that already holds the password, such as a scenario script that read it from an environment variable it was given. The command line never uses it: there the password is read from the environment variable that password_env names. password_env and a password given here are not allowed together.

func (*Driver) Close

func (d *Driver) Close() error

Close implements protocol.Protocol. Do opens and closes its own connection every call, so Driver holds nothing to release.

func (*Driver) Do

func (d *Driver) Do(parent context.Context) (protocol.Result, error)

Do implements protocol.Protocol.

func (*Driver) Name

func (d *Driver) Name() string

Name implements protocol.Protocol.

func (*Driver) Run

func (d *Driver) Run(parent context.Context) (protocol.Result, []Message)

Run is Do, and it also returns the messages that were received: the messages that satisfied a subscribe, or the message that came back in a roundtrip. A load test does not need them. A scenario script does.

type Message

type Message struct {
	Topic   string
	Payload []byte
}

Message is one message that came from the broker.

Directories

Path Synopsis
Package mqtttest is a very small MQTT 3.1.1 broker for tests in other packages, so scripts can be tested without a real broker.
Package mqtttest is a very small MQTT 3.1.1 broker for tests in other packages, so scripts can be tested without a real broker.

Jump to

Keyboard shortcuts

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