select untried messages first

When a lot of messages are waiting in the queue (more then 50)
the seem messages are selected time and time again. So some
messages are not tried until those first messages failed.

This is aspecially problematic when those message at the end
of the queue are acknowledgement message. Causing the remote
site to keep retrying messages that don't get acked.
Merge the changes proposed by Mathijs Möhlmann into the clustering branch