RMQ - RabbitMQ C++ Library
rmqa_messageguard.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_RMQA_MESSAGEGUARD
17#define INCLUDED_RMQA_MESSAGEGUARD
18
19#include <rmqp_messageguard.h>
20#include <rmqt_consumerack.h>
21#include <rmqt_envelope.h>
22#include <rmqt_message.h>
23
24#include <bsls_keyword.h>
25
26#include <bsl_functional.h>
27#include <bsl_memory.h>
28#include <bsl_ostream.h>
29#include <bslma_managedptr.h>
30
31namespace BloombergLP {
32namespace rmqp {
33class Consumer;
34}
35namespace rmqa {
36
44
46 public:
47 class Factory {
48 public:
49 virtual bslma::ManagedPtr<rmqa::MessageGuard>
50 create(const rmqt::Message& message,
52 const MessageGuardCallback& ackCallback,
54
55 virtual ~Factory();
56 };
57
65 const MessageGuardCallback& ackCallback,
67
70 MessageGuard(const MessageGuard& obj);
71
74 ~MessageGuard() BSLS_KEYWORD_OVERRIDE;
75
77 const rmqt::Message& message() const BSLS_KEYWORD_OVERRIDE;
78
80 const rmqt::Envelope& envelope() const BSLS_KEYWORD_OVERRIDE;
81
88 void ack() BSLS_KEYWORD_OVERRIDE;
89
95 void nack(bool requeue = true) BSLS_KEYWORD_OVERRIDE;
96
98 virtual rmqp::Consumer* consumer() const BSLS_KEYWORD_OVERRIDE;
99
105 rmqp::TransferrableMessageGuard transferOwnership() BSLS_KEYWORD_OVERRIDE;
106
107 protected:
111 enum State { READY, TRANSFERRED, RESOLVED };
112
113 State state() const { return d_state; }
114
115 private:
116 mutable State d_state;
117
118 rmqt::Message d_message;
119 rmqt::Envelope d_envelope;
120 MessageGuardCallback d_ackCallback;
121 rmqp::Consumer* d_consumer;
122
123 private:
124 void resolve(rmqt::ConsumerAck::Type ackOption);
125
127 MessageGuard& operator=(const MessageGuard& other);
128
129 friend bsl::ostream& operator<<(bsl::ostream& os, const MessageGuard& mg);
130}; // class MessageGuard
131
133bsl::ostream& operator<<(bsl::ostream& os, const MessageGuard& mg);
134
135} // namespace rmqa
136} // namespace BloombergLP
137
138#endif // ! INCLUDED_RMQA_MESSAGEGUARD
Provide a RabbitMQ Async Consumer API.
Definition: rmqa_consumer.h:41
Definition: rmqa_messageguard.h:47
Controls acknowledgements passed to broker for consumed messages.
Definition: rmqa_messageguard.h:45
void nack(bool requeue=true) BSLS_KEYWORD_OVERRIDE
Definition: rmqa_messageguard.cpp:108
virtual rmqp::Consumer * consumer() const BSLS_KEYWORD_OVERRIDE
Pointer to the Consumer, e.g. to cancel the message flow.
Definition: rmqa_messageguard.cpp:104
void ack() BSLS_KEYWORD_OVERRIDE
Definition: rmqa_messageguard.cpp:106
friend bsl::ostream & operator<<(bsl::ostream &os, const MessageGuard &mg)
Stream out.
Definition: rmqa_messageguard.cpp:138
MessageGuard(const rmqt::Message &message, const rmqt::Envelope &envelope, const MessageGuardCallback &ackCallback, rmqp::Consumer *consumer)
Definition: rmqa_messageguard.cpp:41
~MessageGuard() BSLS_KEYWORD_OVERRIDE
Definition: rmqa_messageguard.cpp:76
const rmqt::Message & message() const BSLS_KEYWORD_OVERRIDE
Access the received message.
Definition: rmqa_messageguard.cpp:102
rmqp::TransferrableMessageGuard transferOwnership() BSLS_KEYWORD_OVERRIDE
Definition: rmqa_messageguard.cpp:129
const rmqt::Envelope & envelope() const BSLS_KEYWORD_OVERRIDE
Access the received message envelope (delivery details)
Definition: rmqa_messageguard.cpp:103
State
Definition: rmqa_messageguard.h:111
Provide a RabbitMQ Async Consumer API.
Definition: rmqp_consumer.h:38
An interface for MessageGuard class.
Definition: rmqp_messageguard.h:39
Provide a class that holds additional data about rmqt::Message.
Definition: rmqt_envelope.h:32
An AMQP content message.
Definition: rmqt_message.h:43