Bitcoin's ZMQ notifications can currently be enabled (or not) through -zmqpub... startup arguments, but there is no way to enable more (or perhaps disable existing) notifications dynamically at runtime. This would be useful, so that software that wants to subscribe can configure the daemon accordingly (in conjunction with getzmqnotifications).
The most straight-forward way to implement dynamic addition of notifications is to add a new RPC addzmqnotification like this:
$ bitcoin-cli addzmqnotification pubhashtx tcp://127.0.0.1:5678
(returns the address, "tcp://127.0.0.1:5678")
This call would add a new pubhashtx notifier on the given address, either reusing an existing socket or creating a new one. This is very similar to how it could be created with -zmqpubhashtx=tcp://127.0.0.1:5678.
A potential difference to the existing CLI argument is that the RPC could, if desired, allow multiple pubhashtx notifiers on different addresses. Alternatively it could refuse to create a second one if one is already active and instead return the address of the existing one in that case.
There are two minor issues I have with this proposal:
It allows an RPC client to induce the daemon to start listening on an arbitrary address/port, which might be a security risk.
A ZMQ subscriber that wants to enable a certain notification probably doesn't care too much about the exact address/port, and might not want to be responsible for actually choosing one.
Issue 1) is IMHO not a big concern, as access to the RPC interface already allows a lot of things to be done and should be restricted anyway.
For 2), we could make the second argument of addzmqnotification optional or remove it completely. The address would then be chosen from an existing notification, or could perhaps be set using a generic -zmqaddress option; the RPC would return the chosen address. This would shift more sensitive configuration back to the startup options, while still allowing subscribers to dynamically enable the notifications they need.
What do you think about this proposal, does it make sense? Is there a better way to implement dynamic addition of ZMQ notifiers? (I know @promag is also interested in that - any input?)