Limit the maximum number of messages that can be queued by the client

Fixes #166.