Hazelcast C++ Client
Hazelcast C++ Client Library
itopic.h
1 /*
2  * Copyright (c) 2008-2021, 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 
39  class itopic : public proxy::ITopicImpl {
40  friend class spi::ProxyManager;
41 
42  public:
43  static constexpr const char *SERVICE_NAME = "hz:impl:topicService";
44 
50  template<typename E>
51  boost::future<void> publish(const E &message) {
52  return proxy::ITopicImpl::publish(to_data<E>(message));
53  }
54 
70  boost::future<boost::uuids::uuid> add_message_listener(topic::listener &&listener) {
71  return proxy::ITopicImpl::add_message_listener(
72  std::shared_ptr<impl::BaseEventHandler>(new topic::impl::TopicEventHandlerImpl(get_name(),
73  get_context().get_client_cluster_service(),
74  get_context().get_serialization_service(),
75  std::move(listener))));
76  }
77 
78  private:
79  itopic(const std::string &instance_name, spi::ClientContext *context)
80  : proxy::ITopicImpl(instance_name, context) {}
81  };
82  }
83 }
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: itopic.h:39
boost::future< void > publish(const E &message)
Publishes the message to all subscribers of this topic.
Definition: itopic.h:51
boost::future< boost::uuids::uuid > add_message_listener(topic::listener &&listener)
Subscribe to this topic.
Definition: itopic.h:70
Listen to messages from an ITopic.
Definition: listener.h:41