public interface

TopicService

com.atlassian.bitbucket.topic.TopicService

Class Overview

Provides a mechanism for publishing messages to multiple subscribers, both local and cluster-wide. When a listener subscribes to a topic, it receives all messages published to that topic from any node until the listener unsubscribes.

Messages are delivered in the order they were published on the node they were published on. If node N publishes messages m1, m2..mn, all listeners receive messages m1, m2..mn in order.

Messages are not durable and message delivery is guaranteed only to the listeners that were reachable at the time a message is published. In the case of network partitions, listeners may miss messages. Plugins that rely on TopicService to handle cluster coherency are encouraged to also listen for the various cluster node events to handle nodes joining, rejoining and leaving the cluster.

Summary

Public Methods
@Nonnull <T extends Serializable> Topic<T> getTopic(String topic, TopicSettings<T> settings)
Returns the existing topic, or creates new topic with the provided settings if it does not yet exist.
@Deprecated <T extends Serializable> void publish(String topic, T message)
This method is deprecated. in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call publish(T) instead.
@Deprecated @Nonnull <T extends Serializable> String subscribe(String topic, TopicListener<T> listener)
This method is deprecated. in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call subscribe(TopicListener) instead.
@Deprecated boolean unsubscribe(String subscriptionId)
This method is deprecated. in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call unsubscribe(String) instead.

Public Methods

@Nonnull public Topic<T> getTopic (String topic, TopicSettings<T> settings)

Returns the existing topic, or creates new topic with the provided settings if it does not yet exist.

Parameters
topic the topic name
settings the topic configuration
Returns
  • the topic

@Deprecated public void publish (String topic, T message)

This method is deprecated.
in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call publish(T) instead.

Publishes a message to all (both local and remote) listeners of the topic

Parameters
topic the topic to publish to
message the message

@Deprecated @Nonnull public String subscribe (String topic, TopicListener<T> listener)

This method is deprecated.
in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call subscribe(TopicListener) instead.

Subscribes a provided listener to a topic. The listener will receive callbacks for every message published to the topic after the listener was subscribed.

If the topic did not exist, prior to subscribing, it will be created with default settings.

Parameters
topic the topic to subscribe to
listener the listener that should receive callbacks when a message is published to the topic
Returns

@Deprecated public boolean unsubscribe (String subscriptionId)

This method is deprecated.
in 5.3 for removal in 6.0. Use getTopic(String, TopicSettings) to obtain the topic and call unsubscribe(String) instead.

Unsubscribes a listener. The listener will not receive any more messages the topic.

Parameters
subscriptionId the subscription ID that was returned by subscribe(String, TopicListener)
Returns
  • true if the listener was successfully unsubscribed, otherwise false