Mosca MQTT - 客户立即退订
Mosca MQTT - Client instantly unsuscribed
在服务器上我正在收听订阅并记录它们
mqttServ.on('subscribed', (topic, client) => {
mqttServ.publish({
topic: topic,
payload: `client ${client.id} subscribed`,
qos: 1
}, client)
})
mqttServ.on('unsubscribed', (topic, client) => {
console.log(
`client ${client.id} unsuscribed from topic ${topic}`
)
})
在客户端我正确地收到了第一条消息
client.on('connect', () => {
client.subscribe('goodmorning')
})
client.on('message', (topic, payload) => {
console.log([topic, payload].join(": "))
client.end()
})
但我无法发送给其他人...可能是因为我注意到客户正在取消订阅该主题。
为什么会发生退订?
删除(或注释掉)client.end() 调用 - 这将关闭客户端与代理的连接,这将在服务器上导致订阅被删除,因为客户端不再连接:- o
在服务器上我正在收听订阅并记录它们
mqttServ.on('subscribed', (topic, client) => {
mqttServ.publish({
topic: topic,
payload: `client ${client.id} subscribed`,
qos: 1
}, client)
})
mqttServ.on('unsubscribed', (topic, client) => {
console.log(
`client ${client.id} unsuscribed from topic ${topic}`
)
})
在客户端我正确地收到了第一条消息
client.on('connect', () => {
client.subscribe('goodmorning')
})
client.on('message', (topic, payload) => {
console.log([topic, payload].join(": "))
client.end()
})
但我无法发送给其他人...可能是因为我注意到客户正在取消订阅该主题。 为什么会发生退订?
删除(或注释掉)client.end() 调用 - 这将关闭客户端与代理的连接,这将在服务器上导致订阅被删除,因为客户端不再连接:- o