def ensured(self, connection, obj, to_ensure_func, **kwargs):
        """
        Ensure that recoverable errors are retried a set number of times before giving up.

        :param connection: Connection to messaging service
        :type connection: kombu.connection.Connection

        :param obj: Object whose method is to be ensured. Typically, channel, producer etc. from
                    the kombu library.
        :type obj: Must support mixin kombu.abstract.MaybeChannelBound
        """
        ensuring_func = connection.ensure(
            obj, to_ensure_func, errback=self.errback, max_retries=3
        )
        ensuring_func(**kwargs)

        Ensure that recoverable errors are retried a set number of times before giving up.

        :param connection: Connection to messaging service
        :type connection: kombu.connection.Connection

        :param obj: Object whose method is to be ensured. Typically, channel, producer etc. from
                    the kombu library.
        :type obj: Must support mixin kombu.abstract.MaybeChannelBound
        
st2common/st2common/transport/connection_retry_wrapper.py