Interface ITopic<E>

Type Parameters:
E - the type of the message
All Superinterfaces:

public interface ITopic<E>
extends DistributedObject
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers, which is also known as a publish/subscribe (pub/sub) messaging model. Publish and subscriptions are cluster-wide.

When a member subscribes for a topic, it is actually registering for messages published by any member in the cluster, including the new members joined after you added the listener.

Messages are ordered, meaning that listeners(subscribers) will process the messages in the order they are actually published. If cluster member M publishes messages m1, m2, to a topic T, then Hazelcast makes sure that all of the subscribers of topic T will receive and process m1, m2, in order.

Since Hazelcast 3.5 it is possible to have reliable topics. Normally all topics rely on the shared eventing system and shared threads. With Hazelcast 3.5 it is possible to configure a topic to be reliable and to get its own Ringbuffer to store events and to get its own executor to process events. The events in the ringbuffer are replicated, so they won't get lost when a node goes down.

  • Method Details

    • getName

      String getName()
      Returns the name of this ITopic instance.
      Specified by:
      getName in interface DistributedObject
      name of this ITopic instance
    • publish

      void publish​(@Nonnull E message)
      Publishes the message to all subscribers of this topic.
      message - the message to publish to all subscribers of this topic
      TopicOverloadException - if the consumer is too slow (only works in combination with reliable topic)
    • addMessageListener

      @Nonnull UUID addMessageListener​(@Nonnull MessageListener<E> listener)
      Subscribes to this topic. When a message is published, the MessageListener.onMessage(Message) method of the given MessageListener is called. More than one message listener can be added on one instance.
      listener - the MessageListener to add
      returns the registration ID
      NullPointerException - if listener is null
    • removeMessageListener

      boolean removeMessageListener​(@Nonnull UUID registrationId)
      Stops receiving messages for the given message listener.

      If the given listener already removed, this method does nothing.

      registrationId - ID of listener registration
      true if registration is removed, false otherwise
    • getLocalTopicStats

      @Nonnull LocalTopicStats getLocalTopicStats()
      Returns statistics about this topic, like total number of publishes/receives. The statistics are local to this member and represent the activity on this member, not the entire cluster.
      statistics about this topic