Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
Public Member Functions | Friends | List of all members
hazelcast::client::ITopic< E > Class Template Reference

Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers which is also known as publish/subscribe (pub/sub) messaging model. More...

#include <ITopic.h>

+ Inheritance diagram for hazelcast::client::ITopic< E >:

Public Member Functions

void publish (const E &message)
 Publishes the message to all subscribers of this topic. More...
 
template<typename L >
std::string addMessageListener (L &listener)
 Subscribes to this topic. More...
 
bool removeMessageListener (const std::string &registrationId)
 Stops receiving messages for the given message listener. More...
 

Friends

class HazelcastClient
 

Detailed Description

template<typename E>
class hazelcast::client::ITopic< E >

Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers which is also known as 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, 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.

Member Function Documentation

template<typename E >
template<typename L >
std::string hazelcast::client::ITopic< E >::addMessageListener ( L &  listener)
inline

Subscribes to this topic.

When someone publishes a message on this topic. onMessage() function of the given MessageListener is called. More than one message listener can be added on one instance. listener class should implement onMessage function like in the following example:

 class MyMessageListener {
 public:
     //....

     void onMessage(topic::Message<std::string> message) {
         /....
     }
}

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listener
Returns
returns registration id.
template<typename E >
void hazelcast::client::ITopic< E >::publish ( const E &  message)
inline

Publishes the message to all subscribers of this topic.

Parameters
message
template<typename E >
bool hazelcast::client::ITopic< E >::removeMessageListener ( const std::string &  registrationId)
inline

Stops receiving messages for the given message listener.

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

Parameters
registrationIdId of listener registration.
Returns
true if registration is removed, false otherwise

The documentation for this class was generated from the following file: