Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Documentationbreadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/x/mqttbreadcrumb arrow Clientbreadcrumb arrow Client.publishAsync( topic, payload, [options] )
Open source

Client.publishAsync()

Publish a message asynchronously. Returns a promise that resolves when the message is published.

Signature

JavaScript
await client.publishAsync(topic, payload, options)

Parameters

ParameterTypeDescription
topicstringTopic to publish to
payloadstring | ArrayBufferMessage payload (string or binary data)
optionsobjectOptional publish configuration
options.qosnumberQuality of Service level (0, 1, or 2). Default: 0
options.retainbooleanWhether the message should be retained by the broker. Default: false
options.tagsobjectCustom tags for metrics (key-value pairs)

Returns

A promise that resolves when the message is successfully published.