https://issues.apache.org/jira/browse/AMQCPP-543

Implemented this based on the provided patch with some tweaks.