moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

server.publish, callback doesn't fire (though message gets sent) #672

Closed mckennatim closed 6 years ago

mckennatim commented 6 years ago

Sorry can't figure how to delete this. I started a new 2.5.2 server and publish callback works. I must have broken it, maybe my authentication code did.

I'm running mosca: 2.3.0, node v6.92, ubuntu 16.04 and wanted to do some work in the service publish callback but it never seems to fire even though the message gets delivered. Here I just published a simple message after mosca is ready but console.log('done! SUPER SIMPLE') never runs. Any ideas?

moserver.on('ready', setup);

function setup() {
  console.log('Mosca server is up and running')
  console.log('device mqtt running on port '+cfg.port.mqtt)
  console.log('browser mqtt over ws port '+cfg.port.ws)
  var message = {
    topic: '/hello/world',
    payload: 'abcde', // or a Buffer
    qos: 0, // 0, 1, or 2
    retain: false // or true
  };
  moserver.publish(message, function() {
    console.log('done! SUPER SIMPLE');
  });  
}
mcollina commented 6 years ago

No worries, no need to delete, we can just close this.