-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[help wanted] nothing receive after publishing message with MQTT5 properties #1357
Comments
I'm sorry to bother you, Did I miss any details? Or is it just a bug? Waiting for your reply. THANKS!! :) @YoDaMa |
I also test on MQTT.js version: 4.0.0 and Also can't send an message with properties: const mqtt = require('mqtt')
const host = 'broker.mqttdashboard.com' // or broker.mqttdashboard.com
const port = '8000' // 8000 for broker.mqttdashboard.com
const protocol = 'ws' // ws for broker.mqttdashboard.com
const connectUrl = `${protocol}://${host}:${port}`
const clientId = `mqtt_${Math.random().toString(16).slice(3)}`
const client = mqtt.connect(connectUrl, {
clientId,
clean: true,
connectTimeout: 4000,
reconnectPeriod: 1000,
protocolVersion: 5,
path: '/mqtt', // for broker.mqttdashboard.com
})
const topic = '/nodejs/mqtt'
client.on('message', (topic, payload, packet) => {
console.log(`=====Received Message=====
from topic: ${topic}
payload: ${payload.toString()}
packet: ${JSON.stringify(packet)}
properties: ${packet.properties}
`)
})
client.on('connect', () => {
console.log('Connected')
client.subscribe([topic], () => {
console.log(`Subscribe to topic '${topic}'`)
client.publish(topic, 'nodejs mqtt test', {
qos: 2,
properties: {
topicAlias: 'test',
userProperties: {
myprop: "myprop value"
}
},
retain: false
}, (error) => {
if (error) {
console.error(error)
}
})
})
}) result after delete properties: client.on('connect', () => {
console.log('Connected')
client.subscribe([topic], () => {
console.log(`Subscribe to topic '${topic}'`)
client.publish(topic, 'nodejs mqtt test', {
qos: 2,
- properties: {
- topicAlias: 'test',
- userProperties: {
- myprop: "myprop value"
- }
- },
retain: false
}, (error) => {
if (error) {
console.error(error)
}
})
})
}) Message send normally. |
@oceanlvr thanks for your patience. looking at this issue now. There is a bug in the typings of topicAlias, it should be a number. This is fixed in this PR: https://github.com/mqttjs/MQTT.js/pull/1359/files So make sure to use a number for your topicAlias. |
@oceanlvr did you find this solved? |
Yes, problem solved! :) |
Environment:
EMQX
andHiveMQ
brokerDear dev, I write some demo to test
publish
API (with MQTT5 properties), and nothing was received when I set theIClientPublishOptions['properties']
. Here is the codepublish
properties affect message events and we can't send messages with properties successfully.Nothing receives, and we expect at least a message like
nodejs mqtt test
, then I pub some other message on this topic, nothing receive either.Did I miss any details? Or is it just a bug? Waiting for your reply. THANKS!! :)
Here is my test repo, please try this to get more detail:
https://github.com/oceanlvr/mqtt5-publish-props
Maybe relative:
The text was updated successfully, but these errors were encountered: