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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Topic.Command<T>
Not for user extensionstatic class
Topic.GetTopicStats$
Scala API: Get a summary of the state for a local topic actor.static class
Topic.Publish$
Scala API: Publish the message to all currently known subscribers.static class
Topic.Subscribe$
Scala API: Subscribe to this topic.static interface
Topic.TopicStats
Response to theGetTopicStats
query.static class
Topic.Unsubscribe$
Scala API: Unsubscribe a previously subscribed actor from this topic.
-
Constructor Summary
Constructors Constructor Description Topic()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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.static <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.static <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 classstatic <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.static <T> Topic.Command<T>
getTopicStats(ActorRef<Topic.TopicStats> replyTo)
Java API: Get a summary of the state for a local topic actor.static <T> Topic.Command<T>
publish(T message)
Java API: Publish the message to all currently known subscribers.static <T> Topic.Command<T>
subscribe(ActorRef<T> subscriber)
Java API: Subscribe to this topic.static <T> Topic.Command<T>
unsubscribe(ActorRef<T> subscriber)
Java API: Unsubscribe a previously subscribed actor from this topic.
-
-
-
Method Detail
-
publish
public static <T> Topic.Command<T> publish(T message)
Java API: Publish the message to all currently known subscribers.
-
subscribe
public static <T> Topic.Command<T> subscribe(ActorRef<T> subscriber)
Java API: Subscribe to this topic. Should only be used for local subscribers.
-
getTopicStats
public static <T> Topic.Command<T> getTopicStats(ActorRef<Topic.TopicStats> replyTo)
Java API: Get a summary of the state for a local topic actor.See
Topic.TopicStats
for caveats
-
unsubscribe
public static <T> Topic.Command<T> unsubscribe(ActorRef<T> subscriber)
Java API: Unsubscribe a previously subscribed actor from this topic.
-
apply
public static <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 static <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 static <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 static <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.
-
-