Skip to content

Commit 5297803

Browse files
ihsandemirSerdaro
andauthored
Update the documentation for the reliable_topic listener callback on_cancel [API-2183] (#1217)
* Updated the documentation for the reliable_topic listener callback function usages including the new callback on_cancel. Co-authored-by: Serdar Ozmen <[email protected]>
1 parent cf53b40 commit 5297803

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Reference_Manual.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,15 +1910,26 @@ A reliable_topic usage example is shown below.
19101910
hazelcast::client::topic::reliable_listener make_listener(std::atomic<int> &n_received_messages, int64_t sequence_id = -1) {
19111911
using namespace hazelcast::client::topic;
19121912
1913-
return reliable_listener(false, sequence_id).on_received([&n_received_messages](message &&message){
1914-
++n_received_messages;
1915-
auto object = message.get_message_object().get<std::string>();
1916-
if (object) {
1917-
std::cout << "[GenericListener::onMessage] Received message: " << *object << " for topic:" << message.get_name() << std::endl;
1918-
} else {
1919-
std::cout << "[GenericListener::onMessage] Received message with NULL object for topic:" << message.get_name() << std::endl;
1920-
}
1921-
});
1913+
return reliable_listener(false, sequence_id)
1914+
.on_received([&n_received_messages](message &&message){
1915+
++n_received_messages;
1916+
auto object = message.get_message_object().get<std::string>();
1917+
if (object) {
1918+
std::cout << "[GenericListener::onMessage] Received message: " << *object << " for topic:" << message.get_name() << std::endl;
1919+
} else {
1920+
std::cout << "[GenericListener::onMessage] Received message with NULL object for topic:" << message.get_name() << std::endl;
1921+
}
1922+
})
1923+
.on_store_sequence_id([](int64_t seq_no) {
1924+
std::cout << "The last received item sequence id is : " << seq_no << std::endl;
1925+
})
1926+
.terminate_on_exception([state](const exception::iexception& par_exception) -> bool{
1927+
std::cout << "terminate_on_exception is called" << std::endl;
1928+
return true;
1929+
})
1930+
.on_cancel([]() {
1931+
std::cout << "on_cancel is called" << std::endl;
1932+
});
19221933
}
19231934
19241935
void listen_with_default_config() {
@@ -1972,6 +1983,7 @@ void listen_with_config() {
19721983
client.shutdown().get();
19731984
}
19741985
```
1986+
The above examples compose a reliable topic listener that listens to the new messages and increments the received message count atomically. The listener also prints a debug message for each callback function available in the listener. The `on_store_sequence_id` callback function is used to store the last received message's sequence ID. The `terminate_on_exception` function allows you to evaluate the exception and continue or terminate the listener. The `on_cancel` callback function notifies you before the listener is cancelled for any reason so that you can take the necessary action. The first example uses a default configuration for the reliable topic, and the second one uses a custom configuration.
19751987

19761988
### 7.4.9 Using pn_counter
19771989

0 commit comments

Comments
 (0)