Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::client::reliable_topic Class 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 <reliable_topic.h>

Inheritance diagram for hazelcast::client::reliable_topic:

Public Member Functions

template<typename E>
boost::future< void > publish (const E &message)
 Publishes the message to all subscribers of this topic Current implementation only supports DISCARD_OLDEST policy as in Java client.
template<typename Listener>
std::string add_message_listener (Listener &&listener)
 Subscribes to this topic.
bool remove_message_listener (const std::string &registration_id)
 Stops receiving messages for the given message listener.

Static Public Attributes

static constexpr const char * SERVICE_NAME = "hz:impl:reliableTopicService"

Protected Member Functions

void on_shutdown () override
void on_destroy () override
void post_destroy () override

Friends

class spi::ProxyManager
class hazelcast_client

Detailed Description

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.

Definition at line 52 of file reliable_topic.h.

Member Function Documentation

◆ add_message_listener()

template<typename Listener>
std::string hazelcast::client::reliable_topic::add_message_listener ( Listener && 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.

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.

Warning 3: Make sure that the MessageListener object is not destroyed until the removeListener is called, since the library will use the MessageListener reference to deliver incoming messages.

Parameters
listenerthe MessageListener to add.
Returns
returns registration id.

Definition at line 98 of file reliable_topic.h.

99 {
100 int id = ++runner_counter_;
101 std::shared_ptr<MessageRunner<Listener>> runner(
102 new MessageRunner<Listener>(id,
103 std::forward<Listener>(listener),
104 ringbuffer_.get(),
105 get_name(),
106 get_serialization_service(),
107 batch_size_,
108 logger_,
109 execution_service_,
110 executor_,
111 shared_from_this()));
112 runners_map_.put(id, runner);
113 runner->next();
114 return std::to_string(id);
115 }

◆ on_destroy()

void hazelcast::client::reliable_topic::on_destroy ( )
overrideprotected

Definition at line 87 of file proxy.cpp.

88{
89 // cancel all runners
90 for (auto& entry : runners_map_.clear()) {
91 entry.second->cancel();
92 }
93}

◆ on_shutdown()

void hazelcast::client::reliable_topic::on_shutdown ( )
overrideprotected

Definition at line 78 of file proxy.cpp.

79{
80 // cancel all runners
81 for (auto& entry : runners_map_.clear()) {
82 entry.second->cancel();
83 }
84}

◆ post_destroy()

void hazelcast::client::reliable_topic::post_destroy ( )
overrideprotected

Definition at line 96 of file proxy.cpp.

97{
98 // destroy the underlying ringbuffer
99 ringbuffer_.get()->destroy().get();
100}

◆ publish()

template<typename E>
boost::future< void > hazelcast::client::reliable_topic::publish ( const E & message)
inline

Publishes the message to all subscribers of this topic Current implementation only supports DISCARD_OLDEST policy as in Java client.

The other policies will be available when async API is completed. Using this policy the oldest item is overwritten no matter it is not old enough to retire.

Parameters
messageThe message to be published

Definition at line 72 of file reliable_topic.h.

73 {
74 topic::impl::reliable::ReliableTopicMessage reliable_message(
75 to_data(message), nullptr);
76 return to_void_future(ringbuffer_.get()->add(reliable_message));
77 }

◆ remove_message_listener()

bool hazelcast::client::reliable_topic::remove_message_listener ( const std::string & registration_id)

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

Definition at line 66 of file proxy.cpp.

67{
68 int id = util::IOUtil::to_value<int>(registration_id);
69 auto runner = runners_map_.get(id);
70 if (!runner) {
71 return false;
72 }
73 runner->cancel();
74 return true;
75}

◆ hazelcast_client

friend class hazelcast_client
friend

Definition at line 57 of file reliable_topic.h.

◆ spi::ProxyManager

friend class spi::ProxyManager
friend

Definition at line 56 of file reliable_topic.h.

Member Data Documentation

◆ SERVICE_NAME

const char* hazelcast::client::reliable_topic::SERVICE_NAME = "hz:impl:reliableTopicService"
staticconstexpr

Definition at line 60 of file reliable_topic.h.


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