Hazelcast C++ Client
Hazelcast C++ Client Library
itopic.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "hazelcast/client/proxy/ITopicImpl.h"
19 #include "hazelcast/client/topic/impl/TopicEventHandlerImpl.h"
20 
21 namespace hazelcast {
22 namespace client {
23 namespace topic {
24 class listener;
25 }
26 
42 class itopic : public proxy::ITopicImpl
43 {
44  friend class spi::ProxyManager;
45 
46 public:
47  static constexpr const char* SERVICE_NAME = "hz:impl:topicService";
48 
54  template<typename E>
55  boost::future<void> publish(const E& message)
56  {
57  return proxy::ITopicImpl::publish(to_data<E>(message));
58  }
59 
75  boost::future<boost::uuids::uuid> add_message_listener(
76  topic::listener&& listener)
77  {
78  return proxy::ITopicImpl::add_message_listener(
79  std::shared_ptr<impl::BaseEventHandler>(
80  new topic::impl::TopicEventHandlerImpl(
81  get_name(),
82  get_context().get_client_cluster_service(),
83  get_context().get_serialization_service(),
84  std::move(listener))));
85  }
86 
87 private:
88  itopic(const std::string& instance_name, spi::ClientContext* context)
89  : proxy::ITopicImpl(instance_name, context)
90  {}
91 };
92 } // namespace client
93 } // namespace hazelcast
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: itopic.h:43
boost::future< void > publish(const E &message)
Publishes the message to all subscribers of this topic.
Definition: itopic.h:55
boost::future< boost::uuids::uuid > add_message_listener(topic::listener &&listener)
Subscribe to this topic.
Definition: itopic.h:75
Listen to messages from an ITopic.
Definition: listener.h:42