E
- the type of the messagepublic interface ITopic<E> extends 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 of 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.
Modifier and Type | Method and Description |
---|---|
UUID |
addMessageListener(MessageListener<E> listener)
Subscribes to this topic.
|
LocalTopicStats |
getLocalTopicStats()
Returns statistics about this topic, like total number of publishes/receives.
|
String |
getName()
Returns the name of this ITopic instance.
|
void |
publish(E message)
Publishes the message to all subscribers of this topic.
|
boolean |
removeMessageListener(UUID registrationId)
Stops receiving messages for the given message listener.
|
destroy, getPartitionKey, getServiceName
String getName()
getName
in interface DistributedObject
void publish(@Nonnull E message)
message
- the message to publish to all subscribers of this topicTopicOverloadException
- if the consumer is too slow
(only works in combination with reliable topic)@Nonnull UUID addMessageListener(@Nonnull MessageListener<E> listener)
MessageListener.onMessage(Message)
method of the given
MessageListener is called.
More than one message listener can be added on one instance.
See ReliableMessageListener
to better integrate with a reliable topic.listener
- the MessageListener to addNullPointerException
- if listener is null
boolean removeMessageListener(@Nonnull UUID registrationId)
If the given listener already removed, this method does nothing.
registrationId
- ID of listener registrationtrue
if registration is removed, false
otherwise@Nonnull LocalTopicStats getLocalTopicStats()
Copyright © 2020 Hazelcast, Inc.. All rights reserved.