PubSub improvements.

- Moving the logic into it's own partial class.
- Adding support for re-subscribing when a connection is lost.