moscajs / mosca

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

Receiving "clientID" on "published" #735

Closed alexgtn closed 6 years ago

alexgtn commented 6 years ago
mqttServer.on('published', function(packet, client) {
   console.log packet.payload ....
});

The server receives the clientID as a packet.payload on "published" and on "client disconnect".

Example sequence of messages the broker is receiving on "published":

clientId123 << when a client connected
{"foo":"bar"}
{"foo":"bar"}
{"foo":"bar"}
{"foo":"bar"}
clientId123 << when the client disconnected

Is that normal behaviour? Should I manually filter out the clientId in case I don't want it?

Thank you!

mcollina commented 6 years ago

If you check the topic under which that is happening, you will see that's an internal topic used by Mosca.

I would recommend to use Aedes which has a instance.subscribe https://github.com/mcollina/aedes#subscribe feature that enables you to listen to specific patterns (similar to a MQTT client) but from within a broker instance.

alexgtn commented 6 years ago

@mcollina interesting! I'll check that out. Thanks for the reply.