Class MdcAwareSubscriber<T>

  • Type Parameters:
    T - the type of element signaled.
    All Implemented Interfaces:
    org.reactivestreams.Subscriber<T>

    public final class MdcAwareSubscriber<T>
    extends Object
    implements org.reactivestreams.Subscriber<T>
    An implementation of Subscriber that will preserve the SLF4J MDC.
    • Method Detail

      • onSubscribe

        public void onSubscribe​(org.reactivestreams.Subscription s)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onNext

        public void onNext​(@NonNull
                           T t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

        public void onError​(@NonNull
                            @NonNull Throwable e)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<T>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • mdcAwareSubscriber

        public static <T> org.reactivestreams.Subscriber<T> mdcAwareSubscriber​(org.reactivestreams.Subscriber<T> delegate)
        Wraps the delegate Subscriber with another Subscriber instance that will capture the current MDC context, and will use it when delegating the calls to the delegated Subscriber.
        Type Parameters:
        T - the type of element signaled.
        Parameters:
        delegate - the Subscriber to delegate the calls to
        Returns:
        A Subscriber that will position the captured MDC context before each call.
        See Also:
        mdcAwareSubscriber(Map, Subscriber)
      • mdcAwareSubscriber

        public static <T> org.reactivestreams.Subscriber<T> mdcAwareSubscriber​(Map<String,​String> mdc,
                                                                               org.reactivestreams.Subscriber<T> delegate)
        Wraps the delegate Subscriber with another Subscriber instance that will use the provided MDC context when delegating the calls to the delegated Subscriber.
        Type Parameters:
        T - the type of element signaled.
        Parameters:
        mdc - The MDC to use when delegating the calls
        delegate - the Subscriber to delegate the calls to
        Returns:
        A Subscriber that will position the captured MDC context before each call.