| 1 |
#ifndef PROTON_MESSAGE_HPP |
| 2 |
#define PROTON_MESSAGE_HPP |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "./fwd.hpp" |
| 26 |
#include "./internal/export.hpp" |
| 27 |
#include "./duration.hpp" |
| 28 |
#include "./timestamp.hpp" |
| 29 |
#include "./value.hpp" |
| 30 |
#include "./map.hpp" |
| 31 |
|
| 32 |
#include <proton/type_compat.h> |
| 33 |
|
| 34 |
#include <string> |
| 35 |
#include <vector> |
| 36 |
|
| 37 |
/// @file |
| 38 |
/// @copybrief proton::message |
| 39 |
|
| 40 |
struct pn_message_t; |
| 41 |
|
| 42 |
namespace proton { |
| 43 |
|
| 44 |
/// An AMQP message. |
| 45 |
/// |
| 46 |
/// Value semantics: A message can be copied or assigned to make a new |
| 47 |
/// message. |
| 48 |
class message { |
| 49 |
public: |
| 50 |
/// A map of string keys and AMQP scalar values. |
| 51 |
typedef map<std::string, scalar> property_map; |
| 52 |
|
| 53 |
/// A map of AMQP annotation keys and AMQP values. |
| 54 |
typedef map<annotation_key, value> annotation_map; |
| 55 |
|
| 56 |
/// Create an empty message. |
| 57 |
PN_CPP_EXTERN message(); |
| 58 |
|
| 59 |
/// Copy a message. |
| 60 |
PN_CPP_EXTERN message(const message&); |
| 61 |
|
| 62 |
/// Copy a message. |
| 63 |
PN_CPP_EXTERN message& operator=(const message&); |
| 64 |
|
| 65 |
/// Move a message. |
| 66 |
PN_CPP_EXTERN message(message&&); |
| 67 |
|
| 68 |
/// Move a message. |
| 69 |
PN_CPP_EXTERN message& operator=(message&&); |
| 70 |
|
| 71 |
/// Create a message with its body set from any value that can be |
| 72 |
/// converted to a proton::value. |
| 73 |
PN_CPP_EXTERN message(const value& x); |
| 74 |
|
| 75 |
PN_CPP_EXTERN ~message(); |
| 76 |
|
| 77 |
/// @name Basic properties and methods |
| 78 |
/// @{ |
| 79 |
|
| 80 |
/// Clear the message content and properties. |
| 81 |
PN_CPP_EXTERN void clear(); |
| 82 |
|
| 83 |
/// Set the message ID. |
| 84 |
/// |
| 85 |
/// The message ID uniquely identifies a message within a |
| 86 |
/// messaging system. |
| 87 |
PN_CPP_EXTERN void id(const message_id&); |
| 88 |
|
| 89 |
/// Get the message ID. |
| 90 |
PN_CPP_EXTERN message_id id() const; |
| 91 |
|
| 92 |
/// Set the user name or ID. |
| 93 |
PN_CPP_EXTERN void user(const std::string&); |
| 94 |
|
| 95 |
/// Get the user name or ID. |
| 96 |
PN_CPP_EXTERN std::string user() const; |
| 97 |
|
| 98 |
/// Encode entire message into a byte vector, growing it if |
| 99 |
/// necessary. |
| 100 |
PN_CPP_EXTERN void encode(std::vector<char>&) const; |
| 101 |
|
| 102 |
/// Return encoded message as a byte vector. |
| 103 |
PN_CPP_EXTERN std::vector<char> encode() const; |
| 104 |
|
| 105 |
/// Decode from string data into the message. |
| 106 |
PN_CPP_EXTERN void decode(const std::vector<char>&); |
| 107 |
|
| 108 |
/// @} |
| 109 |
|
| 110 |
/// @name Routing |
| 111 |
/// @{ |
| 112 |
|
| 113 |
/// Set the destination address. |
| 114 |
PN_CPP_EXTERN void to(const std::string&); |
| 115 |
|
| 116 |
/// Get the destination address. |
| 117 |
PN_CPP_EXTERN std::string to() const; |
| 118 |
|
| 119 |
/// @cond INTERNAL |
| 120 |
/// These are aliases for to() |
| 121 |
PN_CPP_EXTERN void address(const std::string&); |
| 122 |
PN_CPP_EXTERN std::string address() const; |
| 123 |
/// @endcond |
| 124 |
|
| 125 |
/// Set the address for replies. |
| 126 |
PN_CPP_EXTERN void reply_to(const std::string&); |
| 127 |
|
| 128 |
/// Get the address for replies. |
| 129 |
PN_CPP_EXTERN std::string reply_to() const; |
| 130 |
|
| 131 |
/// Set the ID for matching related messages. |
| 132 |
PN_CPP_EXTERN void correlation_id(const message_id&); |
| 133 |
|
| 134 |
/// Get the ID for matching related messages. |
| 135 |
PN_CPP_EXTERN message_id correlation_id() const; |
| 136 |
|
| 137 |
/// @} |
| 138 |
|
| 139 |
/// @name Content |
| 140 |
/// @{ |
| 141 |
|
| 142 |
/// Set the body. Equivalent to `body() = x`. |
| 143 |
PN_CPP_EXTERN void body(const value& x); |
| 144 |
|
| 145 |
/// Get the body. |
| 146 |
PN_CPP_EXTERN const value& body() const; |
| 147 |
|
| 148 |
/// Get a reference to the body that can be modified in place. |
| 149 |
PN_CPP_EXTERN value& body(); |
| 150 |
|
| 151 |
/// Set the subject. |
| 152 |
PN_CPP_EXTERN void subject(const std::string&); |
| 153 |
|
| 154 |
/// Get the subject. |
| 155 |
PN_CPP_EXTERN std::string subject() const; |
| 156 |
|
| 157 |
/// Set the content type of the body. |
| 158 |
PN_CPP_EXTERN void content_type(const std::string&); |
| 159 |
|
| 160 |
/// Get the content type of the body. |
| 161 |
PN_CPP_EXTERN std::string content_type() const; |
| 162 |
|
| 163 |
/// Set the content encoding of the body. |
| 164 |
PN_CPP_EXTERN void content_encoding(const std::string&); |
| 165 |
|
| 166 |
/// Get the content encoding of the body. |
| 167 |
PN_CPP_EXTERN std::string content_encoding() const; |
| 168 |
|
| 169 |
/// Set the expiration time. |
| 170 |
PN_CPP_EXTERN void expiry_time(timestamp); |
| 171 |
|
| 172 |
/// Get the expiration time. |
| 173 |
PN_CPP_EXTERN timestamp expiry_time() const; |
| 174 |
|
| 175 |
/// Set the creation time. |
| 176 |
PN_CPP_EXTERN void creation_time(timestamp); |
| 177 |
|
| 178 |
/// Get the creation time. |
| 179 |
PN_CPP_EXTERN timestamp creation_time() const; |
| 180 |
|
| 181 |
/// Get the inferred flag. |
| 182 |
/// |
| 183 |
/// The inferred flag for a message indicates how the message |
| 184 |
/// content is encoded into AMQP sections. If the inferred is true |
| 185 |
/// then binary and list values in the body of the message will be |
| 186 |
/// encoded as AMQP DATA and AMQP SEQUENCE sections, |
| 187 |
/// respectively. If inferred is false, then all values in the |
| 188 |
/// body of the message will be encoded as AMQP VALUE sections |
| 189 |
/// regardless of their type. |
| 190 |
PN_CPP_EXTERN bool inferred() const; |
| 191 |
|
| 192 |
/// Set the inferred flag. |
| 193 |
PN_CPP_EXTERN void inferred(bool); |
| 194 |
|
| 195 |
/// @} |
| 196 |
|
| 197 |
/// @name Transfer headers |
| 198 |
/// @{ |
| 199 |
|
| 200 |
/// Get the durable flag. |
| 201 |
/// |
| 202 |
/// The durable flag indicates that any parties taking |
| 203 |
/// responsibility for the message must durably store the content. |
| 204 |
PN_CPP_EXTERN bool durable() const; |
| 205 |
|
| 206 |
/// Set the durable flag. |
| 207 |
PN_CPP_EXTERN void durable(bool); |
| 208 |
|
| 209 |
/// Get the TTL. |
| 210 |
/// |
| 211 |
/// The TTL (time to live) for a message determines how long a |
| 212 |
/// message is considered live. When a message is held for |
| 213 |
/// retransmit, the TTL is decremented. Once the TTL reaches zero, |
| 214 |
/// the message is considered dead. Once a message is considered |
| 215 |
/// dead, it may be dropped. |
| 216 |
PN_CPP_EXTERN duration ttl() const; |
| 217 |
|
| 218 |
/// Set the TTL. |
| 219 |
PN_CPP_EXTERN void ttl(duration); |
| 220 |
|
| 221 |
/// Get the priority. |
| 222 |
/// |
| 223 |
/// The priority of a message impacts ordering guarantees. Within |
| 224 |
/// a given ordered context, higher priority messages may jump |
| 225 |
/// ahead of lower priority messages. |
| 226 |
/// |
| 227 |
/// The default value set on newly constructed messages is message::default_priority. |
| 228 |
PN_CPP_EXTERN uint8_t priority() const; |
| 229 |
|
| 230 |
/// Set the priority. |
| 231 |
PN_CPP_EXTERN void priority(uint8_t); |
| 232 |
|
| 233 |
/// Get the first acquirer flag. |
| 234 |
/// |
| 235 |
/// When set to true, the first acquirer flag for a message |
| 236 |
/// indicates that the recipient of the message is the first |
| 237 |
/// recipient to acquire the message, i.e. there have been no |
| 238 |
/// failed delivery attempts to other acquirers. Note that this |
| 239 |
/// does not mean the message has not been delivered to, but not |
| 240 |
/// acquired, by other recipients. |
| 241 |
|
| 242 |
// XXX The triple-not in the last sentence above is confusing. |
| 243 |
|
| 244 |
PN_CPP_EXTERN bool first_acquirer() const; |
| 245 |
|
| 246 |
/// Set the first acquirer flag. |
| 247 |
PN_CPP_EXTERN void first_acquirer(bool); |
| 248 |
|
| 249 |
/// Get the delivery count. |
| 250 |
/// |
| 251 |
/// The delivery count field tracks how many attempts have been |
| 252 |
/// made to deliver a message. |
| 253 |
PN_CPP_EXTERN uint32_t delivery_count() const; |
| 254 |
|
| 255 |
/// Get the delivery count. |
| 256 |
PN_CPP_EXTERN void delivery_count(uint32_t); |
| 257 |
|
| 258 |
/// @} |
| 259 |
|
| 260 |
/// @name Message groups |
| 261 |
/// @{ |
| 262 |
|
| 263 |
/// Set the message group ID. |
| 264 |
PN_CPP_EXTERN void group_id(const std::string&); |
| 265 |
|
| 266 |
/// Get the message group ID. |
| 267 |
PN_CPP_EXTERN std::string group_id() const; |
| 268 |
|
| 269 |
/// Set the reply-to group ID. |
| 270 |
PN_CPP_EXTERN void reply_to_group_id(const std::string&); |
| 271 |
|
| 272 |
/// Get the reply-to group ID. |
| 273 |
PN_CPP_EXTERN std::string reply_to_group_id() const; |
| 274 |
|
| 275 |
/// Get the group sequence. |
| 276 |
/// |
| 277 |
/// The group sequence of a message identifies the relative |
| 278 |
/// ordering of messages within a group. The default value for the |
| 279 |
/// group sequence of a message is zero. |
| 280 |
PN_CPP_EXTERN int32_t group_sequence() const; |
| 281 |
|
| 282 |
/// Set the group sequence for a message. |
| 283 |
PN_CPP_EXTERN void group_sequence(int32_t); |
| 284 |
|
| 285 |
/// @} |
| 286 |
|
| 287 |
/// @name Extended attributes |
| 288 |
/// @{ |
| 289 |
|
| 290 |
/// Get the application properties map. It can |
| 291 |
/// be modified in place. |
| 292 |
PN_CPP_EXTERN property_map& properties(); |
| 293 |
|
| 294 |
/// Examine the application properties map. |
| 295 |
PN_CPP_EXTERN const property_map& properties() const; |
| 296 |
|
| 297 |
/// Get the message annotations map. It can |
| 298 |
/// be modified in place. |
| 299 |
PN_CPP_EXTERN annotation_map& message_annotations(); |
| 300 |
|
| 301 |
/// Examine the message annotations map. |
| 302 |
PN_CPP_EXTERN const annotation_map& message_annotations() const; |
| 303 |
|
| 304 |
/// Get the delivery annotations map. It can |
| 305 |
/// be modified in place. |
| 306 |
PN_CPP_EXTERN annotation_map& delivery_annotations(); |
| 307 |
|
| 308 |
/// Examine the delivery annotations map. |
| 309 |
PN_CPP_EXTERN const annotation_map& delivery_annotations() const; |
| 310 |
|
| 311 |
/// @} |
| 312 |
|
| 313 |
/// Default priority assigned to new messages. |
| 314 |
PN_CPP_EXTERN static const uint8_t default_priority; |
| 315 |
|
| 316 |
/// Human readable string representation |
| 317 |
friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const message&); |
| 318 |
|
| 319 |
/// @cond INTERNAL |
| 320 |
private: |
| 321 |
struct impl; |
| 322 |
pn_message_t* pn_msg() const; |
| 323 |
struct impl& impl() const; |
| 324 |
|
| 325 |
mutable pn_message_t* pn_msg_; |
| 326 |
|
| 327 |
PN_CPP_EXTERN friend void swap(message&, message&); |
| 328 |
/// @endcond |
| 329 |
}; |
| 330 |
|
| 331 |
/// Human readable string representation |
| 332 |
PN_CPP_EXTERN std::string to_string(const message&); |
| 333 |
|
| 334 |
} // proton |
| 335 |
|
| 336 |
#endif // PROTON_MESSAGE_HPP |