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 |
---|---|
CompletableFuture<Void> |
publish(T message)
Publishes a message to all subscribers.
|
default CompletableFuture<Void> |
subscribe(Consumer<T> callback)
Subscribes to messages published to this topic.
|
CompletableFuture<Void> |
subscribe(Consumer<T> callback,
Executor executor)
Subscribes to messages published to this topic.
|
CompletableFuture<Void> |
unsubscribe(Consumer<T> callback)
Unsubscribes from this topic.
|
addStatusChangeListener, applicationId, destroy, name, primitiveType, removeStatusChangeListener, statusChangeListeners
CompletableFuture<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 subscribersCompletableFuture<Void> subscribe(Consumer<T> callback, Executor executor)
callback
- callback that will invoked when a message published to the topic is received.executor
- executor for running the callbackdefault CompletableFuture<Void> subscribe(Consumer<T> callback)
callback
- callback that will invoked when a message published to the topic is received.CompletableFuture<Void> unsubscribe(Consumer<T> callback)
callback
- previously subscribed callback