Topic
Topic allows you to distribute
number of publishers to an arbitrary number of subscribers.
A
s published by an arbitrarynumber of publishers to an arbitrary number of subscribers.
Topic has built-in back-pressure support implemented as the maximum
number of elements (
number of elements (
maxQueued
) that a subscriber is allowed to enqueue.Once that bound is hit, any publishing action will semantically
block until the lagging subscriber consumes some of its queued
elements.
block until the lagging subscriber consumes some of its queued
elements.
- Companion
- object
class Object
trait Matchable
class Any
Value members
Methods
Publishes elements from source of
Pipe equivalent of
Closes the topic when the input stream terminates.
Especially useful when the topic has a single producer.
A
to this topic.Pipe equivalent of
publish1
.Closes the topic when the input stream terminates.
Especially useful when the topic has a single producer.
This operation does not complete until after the given element
has been enqued on all subscribers, which means that if any
subscriber is at its
semantically block until that subscriber consumes an element.
has been enqued on all subscribers, which means that if any
subscriber is at its
maxQueued
limit, publish1
willsemantically block until that subscriber consumes an element.
A semantically blocked publication can be interrupted, but there is
no guarantee of atomicity, and it could result in the
received by some subscribers only.
no guarantee of atomicity, and it could result in the
A
beingreceived by some subscribers only.
Note: if
different subscribers may receive messages from different producers
in a different order.
publish1
is called concurrently by multiple producers,different subscribers may receive messages from different producers
in a different order.
Subscribes for
A
values that are published to this topic.Pulling on the returned stream opens a "subscription", which allows up to
maxQueued
elements to be enqueued as a result of publication.If at any point, the queue backing the subscription has
any further publications semantically block until elements are dequeued from the
subscription queue.
maxQueued
elements in it,any further publications semantically block until elements are dequeued from the
subscription queue.
- Value Params
- maxQueued
-
maximum number of elements to enqueue to the subscription
queue before blocking publishers
Like
a
but before it has started pulling elements.
subscribe
, but represents the subscription explicitly asa
Resource
which returns after the subscriber is subscribed,but before it has started pulling elements.
This method achieves graceful shutdown: when the topics gets
closed, its subscribers will terminate naturally after consuming all
currently enqueued elements.
closed, its subscribers will terminate naturally after consuming all
currently enqueued elements.
"Termination" here means that subscribers no longer
wait for new elements on the topic, and not that they will be
interrupted while performing another action: if you want to
interrupt a subscriber, without first processing enqueued
elements, you should use
wait for new elements on the topic, and not that they will be
interrupted while performing another action: if you want to
interrupt a subscriber, without first processing enqueued
elements, you should use
interruptWhen
on it instead.After a call to
will be no-ops.
close
, any further calls to publish1
or close
will be no-ops.
Note that
might be blocked on a bound, they will only become unblocked
if/when subscribers naturally finish to consume the respective elements.
You can
close
does not automatically unblock producers whichmight be blocked on a bound, they will only become unblocked
if/when subscribers naturally finish to consume the respective elements.
You can
race
the publish with close
to interrupt them immediately.