Yes... hmm.
We do that with custom code now - and I am experimenting with ways to replace our custom code with more standard approaches, while also scaling from our current 1M clients to 20M.
The most promising strategy thus far has been to start with an open source MQTT broker and "decompose" it into a microservice implementation. Essentially this creates "hooks" and "injection points" in the broker for CONNECT, PUBLISH, SUBSCRIBE, etc. Importantly, a microservice can subscribe a client to a topic without the client requesting it.
A mechanism for accomplishing "special" client requests, without breaking the protocol, is to use the "$" hierarchy (other than $SYS) - brokers are supposed to "dampen" the propagation of such messages, but we can grab them via a hook.
We have clients send specials as (sort of) restful URLs, in your case a client might subscribe using a topic like:
'$QUERY/my-app/my-db?query=select * from foo where bar = baz'
This would be intercepted in the broker and forwarded to the QUERY microservice which would: 1) set up a trigger to publish new results if this query does not yet have such a trigger; 3) subscribe the user to the unique id for this query (together with other users if any); 3) execute the query and return current results to the user if the RETAIN flag was set.
There are lots of other little details involved of course, but this is the sort of thing we are experimenting with.
Currently we are using mosquitto for MQTT. We have 0MQ/RabbitMQ forming the microservice and enterprise bus. We use Postgres, Neo4j, and/or Cassandra for data stores. We will be adding golang and nsq to the experimental mix over the next few months. Postgres triggers might be useful in your case.
It's quite a bit of work, but all the pieces are reasonably small once it is factored. Certainly not a ready made solution for your requirement, and, as I said, experimental for us at this point.
ml