Topic¶
-
class
Topic
(service_name, name, context)¶ 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
A registration id which is used as a key to remove the listener.
- Return type
-
publish
(message)¶ Publishes the message to all subscribers of this topic
- Parameters
message – The message to be published.
- Returns
- Return type
hazelcast.future.Future[None]
-
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
True
if the listener is removed,False
otherwise.- Return type
hazelcast.future.Future[bool]
-