libbmq  a5f8a06ba1d16cb5a65643e1fa7f1a1d6aadef40
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 <bslma_allocator.h>
75 #include <bsls_annotation.h>
76 
77 namespace BloombergLP {
78 
79 // FORWARD DECLARATION
80 namespace bmqimp {
81 class Event;
82 }
83 
84 namespace bmqa {
85 
86 // FORWARD DECLARATION
87 class MessageProperties;
88 
89 // ==================
90 // struct MessageImpl
91 // ==================
92 
102 struct MessageImpl {
103  // PUBLIC DATA
104 
106  bmqimp::Event* d_event_p;
107 
109  bsl::shared_ptr<bmqimp::Event> d_clonedEvent_sp;
110 
112  bmqa::QueueId d_queueId;
113 
115  bmqt::CorrelationId d_correlationId;
116 
118  bmqt::SubscriptionHandle d_subscriptionHandle;
119 
120 #ifdef BMQ_ENABLE_MSG_GROUPID
122  bsl::string d_groupId;
123 #endif
124 };
125 
126 // ===============================
127 // class MessageConfirmationCookie
128 // ===============================
129 
132  private:
133  // DATA
134 
136  bmqa::QueueId d_queueId;
137 
139  bmqt::MessageGUID d_guid;
140 
141  public:
142  // CREATORS
143 
146 
153 
154  // ACCESSORS
155 
158  const QueueId& queueId() const;
159 
162  const bmqt::MessageGUID& messageGUID() const;
163 };
164 
165 // =============
166 // class Message
167 // =============
168 
170 class Message {
171 #ifdef BMQ_ENABLE_MSG_GROUPID
172  public:
173  // CONSTANTS
174 
176  static const int k_GROUP_ID_MAX_LENGTH = 31;
177 #endif
178 
179  private:
180  // DATA
181  mutable MessageImpl d_impl; // pimpl
182 
183  private:
184  // PRIVATE ACCESSORS
185 
190  bool isInitialized() const;
191 
192  public:
193  // CREATORS
194 
198 
199  // MANIPULATORS
200 
210  Message& setData(const bdlbb::Blob* data) BSLS_ANNOTATION_DEPRECATED;
211 
212  Message& setData(const char* data,
213  size_t length) BSLS_ANNOTATION_DEPRECATED;
214  // Set the payload of this message to the specified 'length' bytes
215  // starting at the specified 'data' address. The behavior is undefined
216  // unless 'data' is non-null and 'length' is greater than zero. Note
217  // that payload pointed to by 'data' is *not* copied right away, and
218  // should not be destroyed or modified until this message has been
219  // packed (see 'bmqa::MessageEventBuilder' component level
220  // documentation for correct usage).
221  //
222  // This method is deprecated, please use 'setDataRef()' instead.
223 
231  Message& setDataRef(const bdlbb::Blob* data);
232 
240  Message& setDataRef(const char* data, size_t length);
241 
249 
256 
259 
263  Message&
265 
266 #ifdef BMQ_ENABLE_MSG_GROUPID
272  Message& setGroupId(const bsl::string& groupId);
273 
276  Message& clearGroupId();
277 #endif
278 
279  // ACCESSORS
280 
286  bool isValid() const; // TBD:BSLS_ANNOTATION_DEPRECATED
287 
291  operator bool() const; // TBD:BSLS_ANNOTATION_DEPRECATED
292 
297  Message clone(bslma::Allocator* basicAllocator = 0) const;
298 
302  const bmqa::QueueId& queueId() const;
303 
318 
324 
329 
330 #ifdef BMQ_ENABLE_MSG_GROUPID
334  const bsl::string& groupId() const;
335 #endif
336 
341 
346 
350  int ackStatus() const;
351 
358  int getData(bdlbb::Blob* blob) const;
359 
365  int dataSize() const;
366 
370  bool hasProperties() const;
371 
372 #ifdef BMQ_ENABLE_MSG_GROUPID
376  bool hasGroupId() const;
377 #endif
378 
388  int loadProperties(MessageProperties* buffer) const;
389 
399  bsl::ostream&
400  print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
401 };
402 
403 // FREE OPERATORS
404 
407 bsl::ostream& operator<<(bsl::ostream& stream, const Message& rhs);
408 
409 // ============================================================================
410 // INLINE DEFINITIONS
411 // ============================================================================
412 
413 // -------------
414 // class Message
415 // -------------
416 
417 inline Message& Message::setData(const bdlbb::Blob* data)
418 {
419  return setDataRef(data);
420 }
421 
422 inline Message& Message::setData(const char* data, size_t length)
423 {
424  return setDataRef(data, length);
425 }
426 
427 inline Message::operator bool() const
428 {
429  return isInitialized();
430 }
431 
432 // -------------------------------
433 // class MessageConfirmationCookie
434 // -------------------------------
435 
437 : d_queueId()
438 , d_guid()
439 {
440  // NOTHING
441 }
442 
444  const bmqa::QueueId& queueId,
445  const bmqt::MessageGUID& messageGUID)
446 : d_queueId(queueId)
447 , d_guid(messageGUID)
448 {
449  // NOTHING
450 }
451 
452 // ACCESSORS
454 {
455  return d_queueId;
456 }
457 
459 {
460  return d_guid;
461 }
462 } // close package namespace
463 
464 // -------------
465 // class Message
466 // -------------
467 
468 // FREE OPERATORS
469 inline bsl::ostream& bmqa::operator<<(bsl::ostream& stream,
470  const bmqa::Message& rhs)
471 {
472  return rhs.print(stream, 0, -1);
473 }
474 
475 } // close enterprise namespace
476 
477 #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:131
const bmqt::MessageGUID & messageGUID() const
Definition: bmqa_message.h:458
MessageConfirmationCookie()
Create an unset instance of this class.
Definition: bmqa_message.h:436
const QueueId & queueId() const
Definition: bmqa_message.h:453
Provide a VST representing message properties.
Definition: bmqa_messageproperties.h:92
A message sent/received to/from the BlazingMQ broker.
Definition: bmqa_message.h:170
const bmqt::MessageGUID & messageGUID() const
Message & setData(const bdlbb::Blob *data) BSLS_ANNOTATION_DEPRECATED
Definition: bmqa_message.h:417
Message & setDataRef(const char *data, size_t length)
int getData(bdlbb::Blob *blob) const
const bmqt::SubscriptionHandle & subscriptionHandle() const
const bmqa::QueueId & queueId() const
Message & setPropertiesRef(const MessageProperties *properties)
Message clone(bslma::Allocator *basicAllocator=0) const
Message & setCorrelationId(const bmqt::CorrelationId &correlationId)
Set correlation ID of this message to the specified correlationId.
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Message & setCompressionAlgorithmType(bmqt::CompressionAlgorithmType::Enum value)
Message & setDataRef(const bdlbb::Blob *data)
const bmqt::CorrelationId & correlationId() const
bmqt::CompressionAlgorithmType::Enum compressionAlgorithmType() const
int loadProperties(MessageProperties *buffer) const
MessageConfirmationCookie confirmationCookie() const
Value-semantic efficient identifier for a queue.
Definition: bmqa_queueid.h:59
Definition: bmqt_correlationid.h:193
Definition: bmqt_messageguid.h:95
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