Interface BatchPublisherWithContext<K,​V>


  • @NullMarked
    @PublicSpi
    public interface BatchPublisherWithContext<K,​V>
    This form of BatchPublisher is given a BatchLoaderEnvironment object that encapsulates the calling context. A typical use case is passing in security credentials or database details for example.

    See BatchPublisher for more details on the design invariants that you must implement in order to use this interface.

    • Method Detail

      • load

        void load​(java.util.List<K> keys,
                  org.reactivestreams.Subscriber<V> subscriber,
                  BatchLoaderEnvironment environment)
        Called to batch the provided keys into a stream of values. You must provide the same number of values as there as keys, and they must be in the order of the keys.

        The idiomatic approach would be to create a reactive Publisher that provides the values given the keys and then subscribe to it with the provided Subscriber.

        NOTE: It is required that Subscriber.onNext(Object) is invoked on each value in the same order as the provided keys and that you provide a value for every key provided.

        This is given an environment object to that maybe be useful during the call. A typical use case is passing in security credentials or database details for example.

        Parameters:
        keys - the collection of keys to load
        subscriber - as values arrive you must call the subscriber for each value
        environment - an environment object that can help with the call