1

I'm running Mosquitto (latest). Is it possible to hook/define a "middleware processor" which executes between Mosquitto receiving a Publish from a client and sending the payload to subscribers, giving me the ability to manipulate the payload before it's sent out?

Normal Publish happens like this:

[Client publishes] ---> [Mosquitto receives the published payload] ---> [Mosquitto sends the payload to all subscribers]

I want to do this:

[Client publishes] ---> [Mosquitto receives the published payload] ===> [My arbitrary code executes to manipulate the payload] ===> [Mosquitto sends the payload to all subscribers]

Any tips appreciated.

Ryan Griggs
  • 2,457
  • 2
  • 35
  • 58
  • 1
    Can you just add one node in the system which subscribe data and process it then publish again on final topic, I'm not sure if this is the correct way? – Milan Aug 29 '21 at 18:25
  • @Milan Yes I have tried that, but it is going to effectively double the bandwidth required, since all Pubs get pushed twice (and then all Subs would have to be programmed to ignore the "unmodified" version). It would be better to have access to the data **before** it is pushed to all subscribers. – Ryan Griggs Aug 29 '21 at 18:56
  • 1
    @Milan I suppose I could have one set of Topics coming from the publisher, and only listen to them by the "middleware" client. Then the "middleware" client could Publish a **new** set of Topics containing the modified data, and all Subs subscribe to this set of Topics instead. Is that the right way to do it? – Ryan Griggs Aug 29 '21 at 18:57
  • Yes as I haven't heard about middleware processing in mqtt. Assuming we are right about that. You should try using two or more topics for middleware processing, then subscribe last topic in all clients. – Milan Aug 30 '21 at 11:17

0 Answers0