2018-05-15 03:05:49 +08:00
|
|
|
/**
|
2018-05-15 03:34:43 +08:00
|
|
|
* DeferredConfirm.h
|
2018-05-15 03:05:49 +08:00
|
|
|
*
|
|
|
|
|
* Deferred callback for RabbitMQ-specific publisher confirms mechanism.
|
|
|
|
|
*
|
|
|
|
|
* @author Marcin Gibula <m.gibula@gmail.com>
|
|
|
|
|
* @copyright 2018 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* We extend from the default deferred and add extra functionality
|
|
|
|
|
*/
|
|
|
|
|
class DeferredConfirm : public Deferred
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* Callback to execute when server confirms that message is processed
|
|
|
|
|
* @var AckCallback
|
|
|
|
|
*/
|
|
|
|
|
AckCallback _ackCallback;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback to execute when server sends negative acknowledgement
|
|
|
|
|
* @var NackCallback
|
|
|
|
|
*/
|
|
|
|
|
NackCallback _nackCallback;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process an ACK frame
|
|
|
|
|
*
|
|
|
|
|
* @param frame The frame to process
|
|
|
|
|
*/
|
|
|
|
|
void process(BasicAckFrame &frame);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process an ACK frame
|
|
|
|
|
*
|
|
|
|
|
* @param frame The frame to process
|
|
|
|
|
*/
|
|
|
|
|
void process(BasicNackFrame &frame);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The channel implementation may call our
|
|
|
|
|
* private members and construct us
|
|
|
|
|
*/
|
|
|
|
|
friend class ChannelImpl;
|
|
|
|
|
friend class BasicAckFrame;
|
|
|
|
|
friend class BasicNackFrame;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Protected constructor that can only be called
|
|
|
|
|
* from within the channel implementation
|
|
|
|
|
*
|
|
|
|
|
* Note: this constructor _should_ be protected, but because make_shared
|
|
|
|
|
* will then not work, we have decided to make it public after all,
|
|
|
|
|
* because the work-around would result in not-so-easy-to-read code.
|
|
|
|
|
*
|
|
|
|
|
* @param boolean are we already failed?
|
|
|
|
|
*/
|
|
|
|
|
DeferredConfirm(bool failed = false) : Deferred(failed) {}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Register the function that is called when channel is put in publisher
|
|
|
|
|
* confirmed mode
|
|
|
|
|
* @param callback
|
|
|
|
|
*/
|
2022-03-19 06:53:44 +08:00
|
|
|
inline DeferredConfirm &onSuccess(const SuccessCallback& callback) { return onSuccess(SuccessCallback(callback)); }
|
|
|
|
|
DeferredConfirm &onSuccess(SuccessCallback&& callback)
|
2018-05-15 03:05:49 +08:00
|
|
|
{
|
|
|
|
|
// call base
|
2022-03-15 21:10:45 +08:00
|
|
|
Deferred::onSuccess(std::move(callback));
|
2018-05-15 03:05:49 +08:00
|
|
|
|
|
|
|
|
// allow chaining
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2018-05-15 03:40:30 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback that is called when the broker confirmed message publication
|
|
|
|
|
* @param callback the callback to execute
|
|
|
|
|
*/
|
2022-03-19 06:53:44 +08:00
|
|
|
inline DeferredConfirm &onAck(const AckCallback& callback) { return onAck(AckCallback(callback)); }
|
|
|
|
|
DeferredConfirm &onAck(AckCallback&& callback)
|
2018-05-15 03:40:30 +08:00
|
|
|
{
|
|
|
|
|
// store callback
|
2022-03-15 21:10:45 +08:00
|
|
|
_ackCallback = std::move(callback);
|
2018-05-15 03:40:30 +08:00
|
|
|
|
|
|
|
|
// allow chaining
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback that is called when the broker denied message publication
|
|
|
|
|
* @param callback the callback to execute
|
|
|
|
|
*/
|
2022-03-19 06:53:44 +08:00
|
|
|
inline DeferredConfirm &onNack(const NackCallback& callback) { return onNack(NackCallback(callback)); }
|
|
|
|
|
DeferredConfirm &onNack(NackCallback&& callback)
|
2018-05-15 03:40:30 +08:00
|
|
|
{
|
|
|
|
|
// store callback
|
2022-03-15 21:10:45 +08:00
|
|
|
_nackCallback = std::move(callback);
|
2018-05-15 03:40:30 +08:00
|
|
|
|
|
|
|
|
// allow chaining
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2018-05-15 03:05:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|