Late to the party, but I'm writing my Bachelor Thesis on this subject and developed a Python module that acts as a subscriber-publisher (using Paho-MQTT library to do so) with a multithreaded interface to do exactly this. I'm also writing a Mosquitto native plugin in C++ to do the same thing within the broker, without the need of sending your data to an external client. It's all very rough because I'm no such expert programmer, with many issues, but it works and the basic idea is there if anyone wants to take a look. Also, check HiveMQ, I think they implemented something similar in their broker software.