Class MultiMerge

java.lang.Object
io.smallrye.mutiny.groups.MultiMerge

public class MultiMerge extends Object
Creates new Multi by merging several Multi or Flow.Publisher.

This class allows configuring how the merge is executed. Unlike a concatenation, a merge emits the items as they come, so the items may be interleaved.

  • Method Details

    • streams

      @SafeVarargs @CheckReturnValue public final <T> Multi<T> streams(Flow.Publisher<T>... publishers)
      Creates a new Multi merging the items emitted by the given multis / publishers.

      If you pass no publishers, the resulting Multi emits the completion event immediately after subscription. If you pass a single publisher, the resulting Multi emits the events from that publisher. If you pass multiple publishers, the resulting Multi emits the events from the publishers, until all the publishers completes. When the last publisher completes, it sends the completion event.

      If any of the publisher emits a failure, the failure is passed downstream and the merge stops. This behavior can be changed using collectFailures(). In this case, the failures are accumulated and would be propagated instead of the final completion event. If multiple failures have been collected, the downstream receives a CompositeException, otherwise it receives the collected failure.

      IMPORTANT: Unlike concatenation, the order of the publisher does not matter and items from several upstream publishers can be interleaved in the resulting Multi.

      Type Parameters:
      T - the type of item
      Parameters:
      publishers - the publishers, can be empty, must not contain null
      Returns:
      the new Multi merging the passed publisher, so emitting the items from these publishers.
    • streams

      @CheckReturnValue public <T> Multi<T> streams(Iterable<? extends Flow.Publisher<T>> iterable)
      Creates a new Multi merging the items emitted by the given publishers / publishers.

      If you pass no publishers, the resulting Multi emits the completion event immediately after subscription. If you pass a single publisher, the resulting Multi emits the events from that publisher. If you pass multiple publishers, the resulting Multi emits the events from the publishers, until all the publishers completes. When the last publisher completes, it sends the completion event.

      If any of the publisher emits a failure, the failure is passed downstream and the merge stops. This behavior can be changed using collectFailures(). In this case, the failures are accumulated and would be propagated instead of the final completion event. If multiple failures have been collected, the downstream receives a CompositeException, otherwise it receives the collected failure.

      IMPORTANT: Unlike concatenation, the order of the publisher does not matter and items from several upstream publishers can be interleaved in the resulting Multi.

      Type Parameters:
      T - the type of item
      Parameters:
      iterable - the published, must not be empty, must not contain null, must not be null
      Returns:
      the new Multi emitting the items from the given set of Flow.Publisher
    • collectFailures

      @CheckReturnValue public MultiMerge collectFailures()
      Indicates that the merge process should not propagate the first received failure, but collect them until all the items from all (non-failing) participants have been emitted. Then, the failures are propagated downstream (as a CompositeException if several failures have been received).
      Returns:
      a new MultiMerge collecting failures
    • withRequests

      @CheckReturnValue public MultiMerge withRequests(int requests)
      Indicates that the merge process should consume the different streams using the given request.
      Parameters:
      requests - the request
      Returns:
      a new MultiMerge configured with the given requests
    • withConcurrency

      @CheckReturnValue public MultiMerge withConcurrency(int concurrency)
      Indicates that the merge process can consume up to concurrency streams concurrently. Items emitted by these streams may be interleaved in the resulting stream.
      Parameters:
      concurrency - the concurrency
      Returns:
      a new MultiMerge configured with the given concurrency