Class MdcAwareConsumer<T>

  • Type Parameters:
    T - the value type
    All Implemented Interfaces:
    io.reactivex.rxjava3.functions.Consumer<T>

    public final class MdcAwareConsumer<T>
    extends Object
    implements io.reactivex.rxjava3.functions.Consumer<T>
    An implementation of Consumer that will preserve the SLF4J MDC.
    • Method Detail

      • accept

        public void accept​(T t)
                    throws Throwable
        Specified by:
        accept in interface io.reactivex.rxjava3.functions.Consumer<T>
        Throws:
        Throwable
      • mdcAwareConsumer

        public static <T> io.reactivex.rxjava3.functions.Consumer<T> mdcAwareConsumer​(io.reactivex.rxjava3.functions.Consumer<T> delegate)
        Wraps the delegate Consumer with another Consumer instance that will capture the current MDC context, and will use it when delegating the calls to the delegated Consumer.
        Type Parameters:
        T - the value type.
        Parameters:
        delegate - the Subscriber to delegate the calls to
        Returns:
        A Consumer that will position the captured MDC context before each call.
        See Also:
        mdcAwareConsumer(Consumer)
      • mdcAwareConsumer

        public static <T> io.reactivex.rxjava3.functions.Consumer<T> mdcAwareConsumer​(Map<String,​String> mdc,
                                                                                      io.reactivex.rxjava3.functions.Consumer<T> delegate)
        Wraps the delegate Consumer with another Consumer instance that will use the provided MDC context when delegating the calls to the delegated Consumer.
        Type Parameters:
        T - the value type.
        Parameters:
        mdc - The MDC to use when delegating the calls
        delegate - the Consumer to delegate the calls to
        Returns:
        A Consumer that will position the captured MDC context before each call.