Modified for HA, reconnecting, republishing failed publishes, etc.  Completely untested.