Implement keepAlive correctly, handle retained messages better and support 3.1.1 behaviours sufficiently to pass interops tests.