-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
While using protocol version 5, calling writeToStream with userProperties being empty object {} method fails with false as return value.
This is the packet being written:
{
cmd: "publish",
topic: "protocol-version-debug",
payload: "{\"pattern\":\"protocol-version-debug\",\"data\":\"{\\\"ok\\\":1724704578895}\"}",
qos: 0,
retain: true,
messageId: 0,
dup: false,
properties: {
userProperties: {
},
},
}
I traced the problem to getProperties method which returns false when userProperties is empty object {} because getLengthProperty for empty object returns 0 causing getProperties to return false:
Line 1004 in 1f2cf7f
| if (!propValueLength) { return false } |
Setting userProperties to something like {'f': 'u'} removes the issue.
We are using ClientMqtt from @nestjs/microservices to emit data to a topic.
const {
MqttRecordBuilder,
ClientProxyFactory,
Transport
} = require('@nestjs/microservices');
const client = ClientProxyFactory.create({
transport: Transport.MQTT,
options: {
url: 'mqtt://0.0.0.0:1883',
protocolVersion: 5,
}
})
const record = new MqttRecordBuilder()
.setData(JSON.stringify({ ok: new Date().getTime() }))
.setRetain(true)
.build();
client.emit('protocol-version-debug', record);
It seems the ClientMqtt sets userProperties to empty object when no userProperties is provided:
Metadata
Metadata
Assignees
Labels
No labels