T
- The type of message to be distributed to subscriberspublic interface Topic<T> extends DistributedPrimitive
This primitive provides ordered message delivery guarantee i.e. all messages will be delivered to all active subscribers and messages published from each publisher will be delivered to all active subscribers in the order in which they are published.
Transient disruptions in communication such as occasional message drops are automatically handled and recovered from without loss of delivery guarantees.
However, subscribers need to remain active or alive for these guarantees to apply. A subscriber that is partitioned away for an extended duration (typically 5 seconds or more) will be marked as inactive and during that period of inactivity will be removed from the list of current subscribers.
DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS, DEFAULT_OPERTATION_TIMEOUT_MILLIS
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.CompletableFuture<java.lang.Void> |
publish(T message)
Publishes a message to all subscribers.
|
default java.util.concurrent.CompletableFuture<java.lang.Void> |
subscribe(java.util.function.Consumer<T> callback)
Subscribes to messages published to this topic.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
subscribe(java.util.function.Consumer<T> callback,
java.util.concurrent.Executor executor)
Subscribes to messages published to this topic.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
unsubscribe(java.util.function.Consumer<T> callback)
Unsubscribes from this topic.
|
addStatusChangeListener, applicationId, destroy, name, primitiveType, removeStatusChangeListener, statusChangeListeners
java.util.concurrent.CompletableFuture<java.lang.Void> publish(T message)
The message is delivered in a asynchronous fashion which means subscribers will receive the message eventually but not necessarily before the future returned by this method is completed.
message
- The non-null message to send to all current subscribersjava.util.concurrent.CompletableFuture<java.lang.Void> subscribe(java.util.function.Consumer<T> callback, java.util.concurrent.Executor executor)
callback
- callback that will invoked when a message published to the topic is received.executor
- executor for running the callbackdefault java.util.concurrent.CompletableFuture<java.lang.Void> subscribe(java.util.function.Consumer<T> callback)
callback
- callback that will invoked when a message published to the topic is received.java.util.concurrent.CompletableFuture<java.lang.Void> unsubscribe(java.util.function.Consumer<T> callback)
callback
- previously subscribed callback