Interface ITopic<E>
- Type Parameters:
E- the type of the message
- All Superinterfaces:
DistributedObject
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, m3...mn to a topic T, then Hazelcast makes sure that all the subscribers of topic T will receive and process m1, m2, m3...mn 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 Summary
Modifier and TypeMethodDescriptionaddMessageListener(MessageListener<E> listener) Subscribes to this topic.Returns statistics about this topic, like total number of publishes/receives.getName()Returns the name of this ITopic instance.voidPublishes the message to all subscribers of this topic.voidpublishAll(Collection<? extends E> messages) Publishes all messages to all subscribers of this topic.publishAllAsync(Collection<? extends E> messages) Publishes all messages asynchronously to all subscribers of this topic.publishAsync(E message) Publishes the message asynchronously to all subscribers of this topic.booleanremoveMessageListener(UUID registrationId) Stops receiving messages for the given message listener.Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getDestroyContextForTenant, getPartitionKey, getServiceName
-
Method Details
-
getName
String getName()Returns the name of this ITopic instance.- Specified by:
getNamein interfaceDistributedObject- Returns:
- name of this ITopic instance
-
publish
Publishes the message to all subscribers of this topic.- Parameters:
message- the message to publish to all subscribers of this topic- Throws:
TopicOverloadException- if the consumer is too slow (only works in combination with reliable topic)
-
publishAsync
Publishes the message asynchronously to all subscribers of this topic.- Parameters:
message- the message to publish asynchronously to all subscribers of this topic- Returns:
- the CompletionStage to synchronize on completion.
-
addMessageListener
Subscribes to this topic. When a message is published, theMessageListener.onMessage(Message)method of the given MessageListener is called. More than one message listener can be added on one instance. SeeReliableMessageListenerto better integrate with a reliable topic.- Parameters:
listener- the MessageListener to add- Returns:
- returns the registration ID
- Throws:
NullPointerException- if listener isnull
-
removeMessageListener
Stops receiving messages for the given message listener.If the given listener already removed, this method does nothing.
- Parameters:
registrationId- ID of listener registration- Returns:
trueif registration is removed,falseotherwise
-
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.- Returns:
- statistics about this topic
-
publishAll
void publishAll(@Nonnull Collection<? extends E> messages) throws ExecutionException, InterruptedException Publishes all messages to all subscribers of this topic.- Parameters:
messages- the messages to publish to all subscribers of this topic- Throws:
TopicOverloadException- if the consumer is too slow (only works in combination with reliable topic)ExecutionExceptionInterruptedException
-
publishAllAsync
Publishes all messages asynchronously to all subscribers of this topic.- Parameters:
messages- the messages to publish asynchronously to all subscribers of this topic- Returns:
- the CompletionStage to synchronize on completion.
-