User Properties — MQTT 5.0 new features

What are User Properties?

Why do we need User Properties?

User Properties of the connected client

User Properties during message publishing

Use of User Properties

File transfer

{
"filename": "test.txt",
"content": "xxxx"
}

Resource analysis

{
"region": "A",
"type": "JSON"
}

Message routing

{
"type": "real-time",
"timestamp": 1636620444
}

How to configure in MQTT client

Connect

// connect options
const OPTIONS = {
clientId: 'mqtt_test',
clean: true,
connectTimeout: 4000,
username: 'emqx',
password: 'public',
reconnectPeriod: 1000,
protocolVersion: 5,
properties: {
userProperties: {
region: 'A',
type: 'JSON',
},
},
}
const client = mqtt.connect('mqtt://broker.emqx.io', OPTIONS)

Publish messages

client.publish(topic, 'nodejs mqtt test', {
qos: 0,
retain: false,
properties: {
userProperties: {
region: 'A',
type: 'JSON',
},
},
}, (error) => {
if (error) {
console.error(error)
}
})
client.on('message', (topic, payload, packet) => {
console.log('packet:', packet)
console.log('Received Message:', topic, payload.toString())
})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store