Unconsumed messages at a consumer need to be rolledback on recovery as they can get redispatched in arbitrary order. see - https://issues.apache.org/activemq/browse/AMQ-2573
As operations are in progress, like a send transaction, the rollback cannot happen till the send transaction commit completes so it must be async with the failover interruption. Dispatch needs to be gated on completion of the outstanding operations as it currently is with the resolution to
However there is the possibility that the broker starts to dispatch to that consumer/connection before recovery is complete and can block the receipt of messages, the response to the send commit for example as the dispatch is waiting for the send to complete so that any unconsumed messages are rolledback in advance of dispatch. With asyncDispatch=false and optimizedDispatch it is possible to simulate this.
The solution requires two wireformat changes, An indication on a connection that it is recovering (this can be propagated to a consumer) and an indication that recovery is complete such that dispatch on a recovered consumer can complete. An additional AckMode AckRecoveryComplete could do it.
Thus dispatch would be gated such that it cannot interfere with outstanding work that needs to be restored and completed inorder to correctly clear unconsumed and delivered messages.