RMQ - RabbitMQ C++ Library
rmqt_message.h
1// Copyright 2020-2023 Bloomberg Finance L.P.
2// SPDX-License-Identifier: Apache-2.0
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#ifndef INCLUDED_RMQT_MESSAGE
17#define INCLUDED_RMQT_MESSAGE
18
19#include <rmqt_fieldvalue.h>
20#include <rmqt_properties.h>
21
22#include <bdlb_guid.h>
23
24#include <bsl_cstddef.h>
25#include <bsl_memory.h>
26#include <bsl_ostream.h>
27#include <bsl_string.h>
28#include <bsl_vector.h>
29
30namespace BloombergLP {
31namespace rmqt {
32
42
43class Message {
44 public:
45 Message();
51 Message(const bsl::shared_ptr<bsl::vector<uint8_t> >& rawData,
52 const bsl::string& messageId = "",
53 const bsl::shared_ptr<rmqt::FieldTable>& headers =
54 bsl::shared_ptr<rmqt::FieldTable>());
55
60 Message(const bsl::shared_ptr<bsl::vector<uint8_t> >& rawData,
61 const rmqt::Properties& properties);
62
67 Message(const bsl::shared_ptr<const bsl::vector<uint8_t> >& rawData,
68 const rmqt::Properties& properties);
69
72 const bdlb::Guid& guid() const { return d_guid; }
73
75 const bsl::string& messageId() const
76 {
77 return d_properties.messageId.value();
78 }
79
80 const bsl::shared_ptr<rmqt::FieldTable>& headers() const
81 {
82 return d_properties.headers;
83 }
84
85 rmqt::Properties& properties() { return d_properties; }
86
87 const rmqt::Properties& properties() const { return d_properties; }
88
90 const uint8_t* payload() const
91 {
92 return d_message ? d_message->data() : NULL;
93 }
94
96 bsl::size_t payloadSize() const
97 {
98 return d_message ? d_message->size() : 0;
99 }
100
105 void updateDeliveryMode(const rmqt::DeliveryMode::Value& deliveryMode)
106 {
107 d_properties.deliveryMode = deliveryMode;
108 }
109
111 void updateMessagePriority(const bsl::uint8_t& priority)
112 {
113 d_properties.priority = priority;
114 }
115
117 bool isPersistent() const
118 {
119 return d_properties.deliveryMode.value_or(
120 rmqt::DeliveryMode::NON_PERSISTENT) ==
121 rmqt::DeliveryMode::PERSISTENT;
122 }
123
124 private:
125 bdlb::Guid d_guid;
126 bsl::shared_ptr<const bsl::vector<uint8_t> > d_message;
127 Properties d_properties;
128};
129
130bsl::ostream& operator<<(bsl::ostream& os, const rmqt::Message& message);
131bool operator==(const rmqt::Message& lhs, const rmqt::Message& rhs);
132bool operator!=(const rmqt::Message& lhs, const rmqt::Message& rhs);
133
134} // namespace rmqt
135} // namespace BloombergLP
136
137#endif
An AMQP content message.
Definition: rmqt_message.h:43
const bsl::string & messageId() const
Message id.
Definition: rmqt_message.h:75
const uint8_t * payload() const
Message payload.
Definition: rmqt_message.h:90
void updateDeliveryMode(const rmqt::DeliveryMode::Value &deliveryMode)
Update delivery-mode(Persistent or Non-persistent). Default delivery-mode is Persistent for rmqt::Mes...
Definition: rmqt_message.h:105
const bdlb::Guid & guid() const
Message GUID.
Definition: rmqt_message.h:72
void updateMessagePriority(const bsl::uint8_t &priority)
Update update-priority. Default no priority.
Definition: rmqt_message.h:111
bool isPersistent() const
Return true, if delivery-mode is persistent for the message.
Definition: rmqt_message.h:117
bsl::size_t payloadSize() const
Message payload size.
Definition: rmqt_message.h:96
Properties is an minimal abstraction of the properties one can set on a message.
Definition: rmqt_properties.h:73
bdlb::NullableValue< bsl::string > messageId
application message identifier
Definition: rmqt_properties.h:104
bdlb::NullableValue< bsl::uint8_t > deliveryMode
non-persistent (1) or persistent (2)
Definition: rmqt_properties.h:84
bsl::shared_ptr< rmqt::FieldTable > headers
message header field table
Definition: rmqt_properties.h:81
bdlb::NullableValue< bsl::uint8_t > priority
message priority, 0 to 9
Definition: rmqt_properties.h:87