libbmq b6028b29b733bc7541593d2905a5f79a9f0192fc
Loading...
Searching...
No Matches
bmqa_message.h
Go to the documentation of this file.
1// Copyright 2014-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// bmqa_message.h -*-C++-*-
17#ifndef INCLUDED_BMQA_MESSAGE
18#define INCLUDED_BMQA_MESSAGE
19
59
60// BMQ
61
62#include <bmqa_queueid.h>
64#include <bmqt_correlationid.h>
65#include <bmqt_messageguid.h>
66#include <bmqt_subscription.h>
67
68// BDE
69#include <bdlbb_blob.h>
70#include <bsl_cstddef.h> // for 'size_t'
71#include <bsl_iosfwd.h>
72#include <bsl_memory.h>
73#include <bsl_string.h>
74#include <bsla_annotations.h>
75#include <bslma_allocator.h>
76
77namespace BloombergLP {
78
79// FORWARD DECLARATION
80namespace bmqimp {
81class Event;
82}
83namespace bmqp {
84class MessageProperties_Schema;
85}
86
87namespace bmqa {
88
89// FORWARD DECLARATION
90class MessageProperties;
91
92// ==================
93// struct MessageImpl
94// ==================
95
105struct MessageImpl {
106 // PUBLIC DATA
107
109 bmqimp::Event* d_event_p;
110
112 bsl::shared_ptr<bmqimp::Event> d_clonedEvent_sp;
113
115 bmqa::QueueId d_queueId;
116
118 bmqt::CorrelationId d_correlationId;
119
121 bmqt::SubscriptionHandle d_subscriptionHandle;
122
124 bsl::shared_ptr<const bmqp::MessageProperties_Schema> d_schema_sp;
125
126#ifdef BMQ_ENABLE_MSG_GROUPID
128 bsl::string d_groupId;
129#endif
130};
131
132// ===============================
133// class MessageConfirmationCookie
134// ===============================
135
138 private:
139 // DATA
140
142 bmqa::QueueId d_queueId;
143
145 bmqt::MessageGUID d_guid;
146
147 public:
148 // CREATORS
149
152
159
160 // ACCESSORS
161
164 const QueueId& queueId() const;
165
168 const bmqt::MessageGUID& messageGUID() const;
169};
170
171// =============
172// class Message
173// =============
174
176class Message {
177#ifdef BMQ_ENABLE_MSG_GROUPID
178 public:
179 // CONSTANTS
180
182 static const int k_GROUP_ID_MAX_LENGTH = 31;
183#endif
184
185 private:
186 // DATA
187 mutable MessageImpl d_impl; // pimpl
188
189 private:
190 // PRIVATE ACCESSORS
191
196 bool isInitialized() const;
197
198 public:
199 // CREATORS
200
204
205 // MANIPULATORS
206
216 BSLA_DEPRECATED_MESSAGE("Use `setDataRef() instead.")
217 Message& setData(const bdlbb::Blob* data);
218
228 BSLA_DEPRECATED_MESSAGE("Use `setDataRef() instead.")
229 Message& setData(const char* data, size_t length);
230
238 Message& setDataRef(const bdlbb::Blob* data);
239
247 Message& setDataRef(const char* data, size_t length);
248
256
263
265 Message& setCorrelationId(const bmqt::CorrelationId& correlationId);
266
270 Message&
271 setCompressionAlgorithmType(bmqt::CompressionAlgorithmType::Enum value);
272
273#ifdef BMQ_ENABLE_MSG_GROUPID
279 Message& setGroupId(const bsl::string& groupId);
280
283 Message& clearGroupId();
284#endif
285
286 // ACCESSORS
287
293 bool isValid() const; // TBD:BSLA_DEPRECATED
294
298 operator bool() const; // TBD:BSLA_DEPRECATED
299
304 Message clone(bslma::Allocator* basicAllocator = 0) const;
305
309 const bmqa::QueueId& queueId() const;
310
325
331
336
337#ifdef BMQ_ENABLE_MSG_GROUPID
341 const bsl::string& groupId() const;
342#endif
343
348
353
357 int ackStatus() const;
358
365 int getData(bdlbb::Blob* blob) const;
366
372 int dataSize() const;
373
377 bool hasProperties() const;
378
379#ifdef BMQ_ENABLE_MSG_GROUPID
383 bool hasGroupId() const;
384#endif
385
396
406 bsl::ostream&
407 print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
408};
409
410// FREE OPERATORS
411
414bsl::ostream& operator<<(bsl::ostream& stream, const Message& rhs);
415
416// ============================================================================
417// INLINE DEFINITIONS
418// ============================================================================
419
420// -------------
421// class Message
422// -------------
423
424inline Message& Message::setData(const bdlbb::Blob* data)
425{
426 return setDataRef(data);
427}
428
429inline Message& Message::setData(const char* data, size_t length)
430{
431 return setDataRef(data, length);
432}
433
434inline Message::operator bool() const
435{
436 return isInitialized();
437}
438
439// -------------------------------
440// class MessageConfirmationCookie
441// -------------------------------
442
444: d_queueId()
445, d_guid()
446{
447 // NOTHING
448}
449
451 const bmqa::QueueId& queueId,
452 const bmqt::MessageGUID& messageGUID)
453: d_queueId(queueId)
454, d_guid(messageGUID)
455{
456 // NOTHING
457}
458
459// ACCESSORS
461{
462 return d_queueId;
463}
464
466{
467 return d_guid;
468}
469} // close package namespace
470
471// -------------
472// class Message
473// -------------
474
475// FREE OPERATORS
476inline bsl::ostream& bmqa::operator<<(bsl::ostream& stream,
477 const bmqa::Message& rhs)
478{
479 return rhs.print(stream, 0, -1);
480}
481
482} // close enterprise namespace
483
484#endif
Provide a value-semantic efficient identifier for a queue.
Provide an enumeration for different compression algorithm types.
Provide a value-semantic type usable as an efficient identifier.
Provide a value-semantic global unique identifier for BlazingMQ messages.
Provide a value-semantic types for subscription related API.
Cookie for async message confirmation.
Definition bmqa_message.h:137
const bmqt::MessageGUID & messageGUID() const
Definition bmqa_message.h:465
MessageConfirmationCookie()
Create an unset instance of this class.
Definition bmqa_message.h:443
const QueueId & queueId() const
Definition bmqa_message.h:460
Provide a VST representing message properties.
Definition bmqa_messageproperties.h:94
A message sent/received to/from the BlazingMQ broker.
Definition bmqa_message.h:176
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
const bmqt::SubscriptionHandle & subscriptionHandle() const
Message & setData(const bdlbb::Blob *data)
Definition bmqa_message.h:424
int getData(bdlbb::Blob *blob) const
const bmqt::CorrelationId & correlationId() const
Message clone(bslma::Allocator *basicAllocator=0) const
Message & setPropertiesRef(const MessageProperties *properties)
const bmqa::QueueId & queueId() const
Message & setDataRef(const bdlbb::Blob *data)
const bmqt::MessageGUID & messageGUID() const
bmqt::CompressionAlgorithmType::Enum compressionAlgorithmType() const
int loadProperties(MessageProperties *buffer) const
Message & setCorrelationId(const bmqt::CorrelationId &correlationId)
Set correlation ID of this message to the specified correlationId.
Message & setCompressionAlgorithmType(bmqt::CompressionAlgorithmType::Enum value)
MessageConfirmationCookie confirmationCookie() const
Value-semantic efficient identifier for a queue.
Definition bmqa_queueid.h:59
Definition bmqt_correlationid.h:193
Definition bmqt_messageguid.h:96
Value-semantic type for unique Subscription id.
Definition bmqt_subscription.h:59
bsl::ostream & operator<<(bsl::ostream &stream, const CloseQueueStatus &rhs)
Definition bmqa_closequeuestatus.h:227
Definition bmqa_abstractsession.h:42
Enum
Definition bmqt_compressionalgorithmtype.h:46