Process each message in a DB transaction (controlled by global setting)

Change-Id: Id1b280cf11c1a10d301bd9a5e1392f0a8ec302f5
Move common dequeue error handling into Queue::dequeue_loop

Change-Id: I991373f805d0a768d60cd4addfcddd68a144d886