Class FluxUtils

java.lang.Object
org.axonframework.messaging.core.FluxUtils

public final class FluxUtils extends Object
Utility methods to work with Project Reactor's fluxes.
Since:
5.0.0
Author:
John Hendrikx
  • Method Details

    • of

      public static <M extends Message> reactor.core.publisher.Flux<MessageStream.Entry<M>> of(@Nonnull MessageStream<M> source)
      Creates a Flux containing the entries provided by the given source. Note that multiple invocations of this method on the same source, or otherwise any components consuming entries from the given source will cause entries to be consumed by only one of the fluxes or competing consumers.
      Type Parameters:
      M - The type of Message returned by the source.
      Parameters:
      source - The MessageStream providing the elements.
      Returns:
      A Flux with the elements provided by the source.
    • asMessageStream

      public static <M extends Message> MessageStream<M> asMessageStream(@Nonnull reactor.core.publisher.Flux<M> flux)
      Create a stream that provides the Messages returned by the given flux, automatically wrapped in an MessageStream.Entry.
      Type Parameters:
      M - The type of Message contained in the entries of this stream.
      Parameters:
      flux - The Flux providing the Messages to stream.
      Returns:
      A stream of entries that returns the Messages provided by the given flux.
    • asMessageStream

      public static <M extends Message> MessageStream<M> asMessageStream(@Nonnull reactor.core.publisher.Flux<M> flux, @Nonnull Function<M,Context> contextSupplier)
      Create a stream that provides the Messages returned by the given flux, automatically wrapped in an MessageStream.Entry with the resulting Context from the contextSupplier.
      Type Parameters:
      M - The type of Message contained in the entries of this stream.
      Parameters:
      flux - The Flux providing the Messages to stream.
      contextSupplier - A Function ingesting each Message from the given flux returning the Context to set for the MessageStream.Entry the Message is wrapped in.
      Returns:
      A stream of entries that returns the Messages provided by the given flux with a Context provided by the contextSupplier.
    • streamToPublisher

      public static <M extends Message> org.reactivestreams.Publisher<M> streamToPublisher(Supplier<MessageStream<M>> stream)
      Converts a Supplier of MessageStream into a reactor-core Publisher. The provided stream will supply the MessageStream, and its entries will be transformed into a reactive stream of messages.
      Type Parameters:
      M - The type of Message contained in the MessageStream.
      Parameters:
      stream - A Supplier that provides a MessageStream of messages to be published as a reactive stream.
      Returns:
      A Publisher emitting the messages from the provided MessageStream.