Topic¶
-
class
Topic
(client, service_name, name)¶ Bases:
hazelcast.proxy.base.PartitionSpecificProxy
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.
-
add_listener
(on_message=None)¶ Subscribes to this topic. When someone publishes a message on this topic, on_message() function is called if provided.
Parameters: on_message – (Function), function to be called when a message is published. Returns: (str), a registration id which is used as a key to remove the listener.
-
publish
(message)¶ Publishes the message to all subscribers of this topic
Parameters: message – (object), the message to be published.
-
remove_listener
(registration_id)¶ Stops receiving messages for the given message listener. If the given listener already removed, this method does nothing.
Parameters: registration_id – (str), registration id of the listener to be removed. Returns: (bool), true
if the listener is removed,false
otherwise.
-