Interface Topic<T>

  • Type Parameters:
    T - The type of message to be distributed to subscribers
    All Superinterfaces:
    DistributedPrimitive

    public interface Topic<T>
    extends DistributedPrimitive
    A distributed publish subscribe primitive.

    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.

    • Method Detail

      • publish

        CompletableFuture<Void> publish​(T message)
        Publishes a message to all subscribers.

        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.

        Parameters:
        message - The non-null message to send to all current subscribers
        Returns:
        a future that is completed when the message is logged (not necessarily delivered).
      • subscribe

        CompletableFuture<Void> subscribe​(Consumer<T> callback,
                                          Executor executor)
        Subscribes to messages published to this topic.
        Parameters:
        callback - callback that will invoked when a message published to the topic is received.
        executor - executor for running the callback
        Returns:
        a future that is completed when subscription request is completed.
      • subscribe

        default CompletableFuture<Void> subscribe​(Consumer<T> callback)
        Subscribes to messages published to this topic.
        Parameters:
        callback - callback that will invoked when a message published to the topic is received.
        Returns:
        a future that is completed when subscription request is completed.
      • unsubscribe

        CompletableFuture<Void> unsubscribe​(Consumer<T> callback)
        Unsubscribes from this topic.
        Parameters:
        callback - previously subscribed callback
        Returns:
        a future that is completed when unsubscription request is completed.