moscajs / mosca

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

Change packet payload in 'published' event #696

Closed robertsLando closed 6 years ago

robertsLando commented 6 years ago

Hi everyone, I would like to know if there is a way to change published packets payload received by mosca MQTT broker. I'm using published event to get all published packets and by using inspect I have noticed that the packet is published at the end of this method so maybe there could be a way to do this.

In my case this would be useful because I have to save an incoming object in MongoDB and add the id of the created object to the packet.payload. ATM I'm using two differents topics like /objectName and /objectName/store and once I receive a packet in /store I create the new object and publish the created object data with id in /objectName.

mcollina commented 6 years ago

'published'  is emitted after the packet as been published. You can do that in Aedes with https://github.com/mcollina/aedes#authorizePublish.