Class Topic$
- java.lang.Object
-
- akka.actor.typed.pubsub.Topic$
-
public class Topic$ extends java.lang.Object
A pub sub topic is an actor that handles subscribing to a topic and publishing messages to all subscribed actors.It is mostly useful in a clustered setting, where it is intended to be started once on every node that want to house subscribers or publish messages to the topic, but it also works in a local setting without cluster.
In a clustered context messages are deduplicated so that there is at most one message sent to each node for each publish and if there are no subscribers on a node, no message is sent to it. Note that the list of subscribers is eventually consistent and there are no delivery guarantees built in.
Each topic results in a
ServiceKey
in theReceptionist
so the same scaling recommendation holds for topics, see docs: https://doc.akka.io/libraries/akka-core/current/typed/actor-discovery.html#receptionist-scalability
-
-
Constructor Summary
Constructors Constructor Description Topic$()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Behavior<Topic.Command<T>>
apply(java.lang.String topicName, scala.concurrent.duration.FiniteDuration ttl, scala.reflect.ClassTag<T> classTag)
Scala API: Create a topic actor behavior for the given topic name and message type with a TTL making it terminate itself after a time period with no local subscribers and no locally published messages.<T> Behavior<Topic.Command<T>>
apply(java.lang.String topicName, scala.reflect.ClassTag<T> classTag)
Scala API: Create a topic actor behavior for the given topic name and message type.<T> Behavior<Topic.Command<T>>
create(java.lang.Class<T> messageClass, java.lang.String topicName)
Java API: Create a topic actor behavior for the given topic name and message class<T> Behavior<Topic.Command<T>>
create(java.lang.Class<T> messageClass, java.lang.String topicName, java.time.Duration ttl)
Java API: Create a topic actor behavior for the given topic name and message class with a TTL making it terminate itself after a time period with no local subscribers and no locally published messages.<T> Topic.Command<T>
getTopicStats(ActorRef<Topic.TopicStats> replyTo)
Java API: Get a summary of the state for a local topic actor.<T> Topic.Command<T>
publish(T message)
Java API: Publish the message to all currently known subscribers.<T> Topic.Command<T>
subscribe(ActorRef<T> subscriber)
Java API: Subscribe to this topic.<T> Topic.Command<T>
unsubscribe(ActorRef<T> subscriber)
Java API: Unsubscribe a previously subscribed actor from this topic.
-
-
-
Field Detail
-
MODULE$
public static final Topic$ MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Method Detail
-
publish
public <T> Topic.Command<T> publish(T message)
Java API: Publish the message to all currently known subscribers.
-
subscribe
public <T> Topic.Command<T> subscribe(ActorRef<T> subscriber)
Java API: Subscribe to this topic. Should only be used for local subscribers.
-
getTopicStats
public <T> Topic.Command<T> getTopicStats(ActorRef<Topic.TopicStats> replyTo)
Java API: Get a summary of the state for a local topic actor.See
TopicStats
for caveats
-
unsubscribe
public <T> Topic.Command<T> unsubscribe(ActorRef<T> subscriber)
Java API: Unsubscribe a previously subscribed actor from this topic.
-
apply
public <T> Behavior<Topic.Command<T>> apply(java.lang.String topicName, scala.reflect.ClassTag<T> classTag)
Scala API: Create a topic actor behavior for the given topic name and message type.Note: for many use cases it is more convenient to use the
PubSub
registry to have an ActorSystem global set of re-usable topics instead of manually creating and managing the topic actors.
-
apply
public <T> Behavior<Topic.Command<T>> apply(java.lang.String topicName, scala.concurrent.duration.FiniteDuration ttl, scala.reflect.ClassTag<T> classTag)
Scala API: Create a topic actor behavior for the given topic name and message type with a TTL making it terminate itself after a time period with no local subscribers and no locally published messages.Note: for many use cases it is more convenient to use the
PubSub
registry to have an ActorSystem global set of re-usable topics instead of manually creating and managing the topic actors.
-
create
public <T> Behavior<Topic.Command<T>> create(java.lang.Class<T> messageClass, java.lang.String topicName)
Java API: Create a topic actor behavior for the given topic name and message classNote: for many use cases it is more convenient to use the
PubSub
registry to have an ActorSystem global set of re-usable topics instead of manually creating and managing the topic actors.
-
create
public <T> Behavior<Topic.Command<T>> create(java.lang.Class<T> messageClass, java.lang.String topicName, java.time.Duration ttl)
Java API: Create a topic actor behavior for the given topic name and message class with a TTL making it terminate itself after a time period with no local subscribers and no locally published messages.Note: for many use cases it is more convenient to use the
PubSub
registry to have an ActorSystem global set of re-usable topics instead of manually creating and managing the topic actors.
-
-