Search Results for

    Show / Hide Table of Contents

    Class PartitionHub

    A PartitionHub is a special streaming hub that is able to route streamed elements to a dynamic set of consumers. It consists of two parts, a Sink<TIn, TMat> and a Source<TOut, TMat>. The Sink<TIn, TMat> e elements from a producer to the actually live consumers it has.The selection of consumer is done with a function. Each element can be routed to only one consumer.Once the producer has been materialized, the Sink<TIn, TMat> it feeds into returns a materialized value which is the corresponding Source<TOut, TMat>. This Source<TOut, TMat> can be materialized an arbitrary number of times, where each of the new materializations will receive their elements from the original Sink<TIn, TMat>.

    Inheritance
    object
    PartitionHub
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Akka.Streams.Dsl
    Assembly: Akka.Streams.dll
    Syntax
    public static class PartitionHub

    Methods

    | Edit this page View Source

    Sink<T>(Func<int, T, int>, int, int)

    Creates a Sink<TIn, TMat> that receives elements from its upstream producer and routes them to a dynamic set of consumers.After the Sink<TIn, TMat> returned by this method is materialized, it returns a Source<TOut, TMat> as materialized value. This Source<TOut, TMat> can be materialized an arbitrary number of times and each materialization will receive the elements from the original Sink<TIn, TMat>.

    Every new materialization of the Sink<TIn, TMat> results in a new, independent hub, which materializes to its own Source<TOut, TMat> for consuming the Sink<TIn, TMat> of that materialization.

    If the original Sink<TIn, TMat> is failed, then the failure is immediately propagated to all of its materialized Source<TOut, TMat>s (possibly jumping over already buffered elements). If the original Sink<TIn, TMat> is completed, then all corresponding Source<TOut, TMat>s are completed.Both failure and normal completion is "remembered" and later materializations of the Source<TOut, TMat> will see the same (failure or completion) state. Source<TOut, TMat>s that are cancelled are simply removed from the dynamic set of consumers.

    This Sink<T>(Func<int, T, int>, int, int) should be used when the routing function is stateless, e.g. based on a hashed value of the elements. Otherwise the StatefulSink<T>(Func<Func<IConsumerInfo, T, long>>, int, int) can be used to implement more advanced routing logic.
    Declaration
    public static Sink<T, Source<T, NotUsed>> Sink<T>(Func<int, T, int> partitioner, int startAfterNrOfConsumers, int bufferSize = 256)
    Parameters
    Type Name Description
    Func<int, T, int> partitioner

    Function that decides where to route an element. The function takes two parameters; the first is the number of active consumers and the second is the stream element. The function should return the index of the selected consumer for the given element, i.e. int greater than or equal to 0 and less than number of consumers. E.g. (size, elem) => math.abs(elem.hashCode) % size.

    int startAfterNrOfConsumers

    Elements are buffered until this number of consumers have been connected. This is only used initially when the stage is starting up, i.e.it is not honored when consumers have been removed (canceled).

    int bufferSize

    Total number of elements that can be buffered. If this buffer is full, the producer is backpressured.

    Returns
    Type Description
    Sink<T, Source<T, NotUsed>>
    Type Parameters
    Name Description
    T
    | Edit this page View Source

    StatefulSink<T>(Func<Func<IConsumerInfo, T, long>>, int, int)

    Creates a Sink<TIn, TMat> that receives elements from its upstream producer and routes them to a dynamic set of consumers.After the Sink<TIn, TMat> returned by this method is materialized, it returns a Source<TOut, TMat> as materialized value. This Source<TOut, TMat> can be materialized an arbitrary number of times and each materialization will receive the elements from the original Sink<TIn, TMat>.

    Every new materialization of the Sink<TIn, TMat> results in a new, independent hub, which materializes to its own Source<TOut, TMat> for consuming the Sink<TIn, TMat> of that materialization.

    If the original Sink<TIn, TMat> is failed, then the failure is immediately propagated to all of its materialized Source<TOut, TMat>s (possibly jumping over already buffered elements). If the original Sink<TIn, TMat> is completed, then all corresponding Source<TOut, TMat>s are completed.Both failure and normal completion is "remembered" and later materializations of the Source<TOut, TMat> will see the same (failure or completion) state. Source<TOut, TMat>s that are cancelled are simply removed from the dynamic set of consumers.

    This StatefulSink<T>(Func<Func<IConsumerInfo, T, long>>, int, int) should be used when there is a need to keep mutable state in the partition function, e.g. for implemening round-robin or sticky session kind of routing. If state is not needed the Sink<T>(Func<int, T, int>, int, int) can be more convenient to use.
    Declaration
    public static Sink<T, Source<T, NotUsed>> StatefulSink<T>(Func<Func<PartitionHub.IConsumerInfo, T, long>> partitioner, int startAfterNrOfConsumers, int bufferSize = 256)
    Parameters
    Type Name Description
    Func<Func<PartitionHub.IConsumerInfo, T, long>> partitioner

    Function that decides where to route an element.It is a factory of a function to to be able to hold stateful variables that are unique for each materialization.The function takes two parameters; the first is information about active consumers, including an array of consumer identifiers and the second is the stream element.The function should return the selected consumer identifier for the given element.The function will never be called when there are no active consumers, i.e.there is always at least one element in the array of identifiers.

    int startAfterNrOfConsumers

    Elements are buffered until this number of consumers have been connected. This is only used initially when the stage is starting up, i.e.it is not honored when consumers have been removed (canceled).

    int bufferSize

    Total number of elements that can be buffered. If this buffer is full, the producer is backpressured.

    Returns
    Type Description
    Sink<T, Source<T, NotUsed>>
    Type Parameters
    Name Description
    T
    In this article
    • githubEdit this page
    • View Source
    Back to top
    Contribute
    • Project Chat
    • Discussion Forum
    • Source Code
    Support
    • Akka.NET Support Plans
    • Akka.NET Observability Tools
    • Akka.NET Training & Consulting
    Maintained By
    • Petabridge - The Akka.NET Company
    • Learn Akka.NET