pulsar-client-cpp
Message.h
1 
19 #ifndef MESSAGE_HPP_
20 #define MESSAGE_HPP_
21 
22 #include <pulsar/defines.h>
23 
24 #include <map>
25 #include <memory>
26 #include <string>
27 
28 #include "KeyValue.h"
29 #include "MessageId.h"
30 
31 namespace pulsar {
32 namespace proto {
33 class CommandMessage;
34 class MessageMetadata;
35 class SingleMessageMetadata;
36 } // namespace proto
37 
38 class SharedBuffer;
39 class MessageBuilder;
40 class MessageImpl;
41 class PulsarWrapper;
42 
43 class PULSAR_PUBLIC Message {
44  public:
45  typedef std::map<std::string, std::string> StringMap;
46 
47  Message();
48 
55  const StringMap& getProperties() const;
56 
64  bool hasProperty(const std::string& name) const;
65 
72  const std::string& getProperty(const std::string& name) const;
73 
80  const void* getData() const;
81 
87  std::size_t getLength() const;
88 
97 #if defined(_MSC_VER) && !defined(NDEBUG)
98  const std::string& getDataAsString() const;
99 #else
100  std::string getDataAsString() const;
101 #endif
102 
108  KeyValue getKeyValueData() const;
109 
119  const MessageId& getMessageId() const;
120 
125  void setMessageId(const MessageId& messageId) const;
126 
131  const std::string& getPartitionKey() const;
132 
136  bool hasPartitionKey() const;
137 
143  const std::string& getOrderingKey() const;
144 
151  bool hasOrderingKey() const;
152 
157  uint64_t getPublishTimestamp() const;
158 
162  uint64_t getEventTimestamp() const;
163 
167  const std::string& getTopicName() const;
168 
172  const int getRedeliveryCount() const;
173 
177  bool hasSchemaVersion() const;
178 
184  int64_t getLongSchemaVersion() const;
185 
189  const std::string& getSchemaVersion() const;
190 
191  bool operator==(const Message& msg) const;
192 
193  protected:
194  typedef std::shared_ptr<MessageImpl> MessageImplPtr;
195  MessageImplPtr impl_;
196 
197  Message(MessageImplPtr& impl);
198  Message(const MessageId& messageId, proto::MessageMetadata& metadata, SharedBuffer& payload);
200  Message(const MessageId& messageId, proto::MessageMetadata& metadata, SharedBuffer& payload,
201  proto::SingleMessageMetadata& singleMetadata, const std::shared_ptr<std::string>& topicName);
202  friend class PartitionedProducerImpl;
203  friend class MultiTopicsConsumerImpl;
204  friend class MessageBuilder;
205  friend class ConsumerImpl;
206  friend class ProducerImpl;
207  friend class Commands;
208  friend class BatchMessageContainerBase;
209  friend class BatchAcknowledgementTracker;
210  friend class PulsarWrapper;
211  friend class MessageBatch;
212  friend struct OpSendMsg;
213 
214  friend PULSAR_PUBLIC std::ostream& operator<<(std::ostream& s, const StringMap& map);
215  friend PULSAR_PUBLIC std::ostream& operator<<(std::ostream& s, const Message& msg);
216  friend class PulsarFriend;
217 };
218 } // namespace pulsar
219 
220 #endif /* MESSAGE_HPP_ */
pulsar::MessageId
Definition: MessageId.h:34
pulsar::MessageBatch
Definition: MessageBatch.h:29
pulsar::Message
Definition: Message.h:43
pulsar::KeyValue
Definition: KeyValue.h:35
pulsar::MessageBuilder
Definition: MessageBuilder.h:33
pulsar
Definition: Authentication.h:31