def _callback_handler(self, message, callback): """Call callback with deserialized message. Messages that are processed without exception are ack'ed. If the message processing generates an exception, it will be ack'ed if ack_on_error=True. Otherwise it will be .reject()'ed. Rejection is better than waiting for the message to timeout. Rejected messages are immediately requeued. """ ack_msg = False try: msg = rpc_common.deserialize_msg(message.payload) callback(msg) ack_msg = True except Exception: if self.ack_on_error: ack_msg = True LOG.exception(_("Failed to process message" " ... skipping it.")) else: LOG.exception(_("Failed to process message" " ... will requeue.")) finally: if ack_msg: message.ack() else: message.reject()