2014-04-02 21:40:35 +08:00
|
|
|
#pragma once
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* ChannelImpl.h
|
|
|
|
|
*
|
|
|
|
|
* Extended channel object that is used internally by the library, but
|
|
|
|
|
* that has a private constructor so that it can not be used from outside
|
|
|
|
|
* the AMQP library
|
|
|
|
|
*
|
|
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
2014-01-06 22:49:31 +08:00
|
|
|
class ChannelImpl : public Watchable
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The actual channel object
|
|
|
|
|
* @var Channel
|
|
|
|
|
*/
|
|
|
|
|
Channel *_parent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pointer to the connection
|
2014-01-07 00:15:21 +08:00
|
|
|
* @var ConnectionImpl
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-07 00:15:21 +08:00
|
|
|
ConnectionImpl *_connection;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The handler that is notified about events
|
|
|
|
|
* @var MyChannelHandler
|
|
|
|
|
*/
|
|
|
|
|
ChannelHandler *_handler;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback when the channel is ready
|
|
|
|
|
*/
|
|
|
|
|
std::function<void(Channel *channel)> _readyCallback;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback when the channel errors out
|
|
|
|
|
*/
|
|
|
|
|
std::function<void(Channel *channel, const std::string& message)> _errorCallback;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The callbacks waiting to be called
|
|
|
|
|
*/
|
|
|
|
|
std::deque<Deferred<>> _callbacks;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callbacks with additional parameters
|
|
|
|
|
*/
|
|
|
|
|
std::deque<Deferred<const std::string&, uint32_t, uint32_t>> _queueDeclaredCallbacks;
|
|
|
|
|
std::deque<Deferred<uint32_t>> _queueRemovedCallbacks;
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* The channel number
|
|
|
|
|
* @var uint16_t
|
|
|
|
|
*/
|
|
|
|
|
uint16_t _id;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* State of the channel object
|
|
|
|
|
* @var enum
|
|
|
|
|
*/
|
|
|
|
|
enum {
|
|
|
|
|
state_connected,
|
2014-01-07 00:15:21 +08:00
|
|
|
state_closing,
|
2014-01-04 19:45:04 +08:00
|
|
|
state_closed
|
|
|
|
|
} _state = state_connected;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Is a transaction now active?
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
bool _transaction = false;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* The message that is now being received
|
|
|
|
|
* @var MessageImpl
|
|
|
|
|
*/
|
|
|
|
|
MessageImpl *_message = nullptr;
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct a channel object
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* Note that the constructor is private, and that the Channel class is
|
|
|
|
|
* a friend. By doing this we ensure that nobody can instantiate this
|
|
|
|
|
* object, and that it can thus only be used inside the library.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param parent the public channel object
|
|
|
|
|
* @param connection pointer to the connection
|
|
|
|
|
* @param handler handler that is notified on events
|
|
|
|
|
*/
|
|
|
|
|
ChannelImpl(Channel *parent, Connection *connection, ChannelHandler *handler = nullptr);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~ChannelImpl();
|
|
|
|
|
|
2014-01-07 05:34:54 +08:00
|
|
|
/**
|
|
|
|
|
* Invalidate the channel
|
|
|
|
|
* This method is called when the connection is destructed
|
|
|
|
|
*/
|
|
|
|
|
void invalidate()
|
|
|
|
|
{
|
|
|
|
|
_connection = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Pause deliveries on a channel
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* This will stop all incoming messages
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& pause();
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Resume a paused channel
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This will resume incoming messages
|
|
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& resume();
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is the channel connected?
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool connected()
|
|
|
|
|
{
|
|
|
|
|
return _state == state_connected;
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Start a transaction
|
|
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& startTransaction();
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Commit the current transaction
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& commitTransaction();
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Rollback the current transaction
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& rollbackTransaction();
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* declare an exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param name name of the exchange to declare
|
|
|
|
|
* @param type type of exchange
|
|
|
|
|
* @param flags additional settings for the exchange
|
|
|
|
|
* @param arguments additional arguments
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& declareExchange(const std::string &name, ExchangeType type, int flags, const Table &arguments);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* bind two exchanges
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param source exchange which binds to target
|
|
|
|
|
* @param target exchange to bind to
|
|
|
|
|
* @param routingKey routing key
|
|
|
|
|
* @param glags additional flags
|
|
|
|
|
* @param arguments additional arguments for binding
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* unbind two exchanges
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param source the source exchange
|
|
|
|
|
* @param target the target exchange
|
|
|
|
|
* @param routingkey the routing key
|
|
|
|
|
* @param flags optional flags
|
|
|
|
|
* @param arguments additional unbind arguments
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& unbindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* remove an exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param name name of the exchange to remove
|
|
|
|
|
* @param flags additional settings for deleting the exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& removeExchange(const std::string &name, int flags);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* declare a queue
|
|
|
|
|
* @param name queue name
|
|
|
|
|
* @param flags additional settings for the queue
|
|
|
|
|
* @param arguments additional arguments
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<const std::string&, uint32_t, uint32_t>& declareQueue(const std::string &name, int flags, const Table &arguments);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Bind a queue to an exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param exchangeName name of the exchange to bind to
|
|
|
|
|
* @param queueName name of the queue
|
|
|
|
|
* @param routingkey routingkey
|
|
|
|
|
* @param flags additional flags
|
|
|
|
|
* @param arguments additional arguments
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& bindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, int flags, const Table &arguments);
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unbind a queue from an exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param exchange the source exchange
|
|
|
|
|
* @param queue the target queue
|
|
|
|
|
* @param routingkey the routing key
|
|
|
|
|
* @param arguments additional bind arguments
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& unbindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, const Table &arguments);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Purge a queue
|
|
|
|
|
* @param queue queue to purge
|
|
|
|
|
* @param flags additional flags
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
|
|
|
|
*
|
|
|
|
|
* The onSuccess() callback that you can install should have the following signature:
|
|
|
|
|
*
|
|
|
|
|
* void myCallback(AMQP::Channel *channel, uint32_t messageCount);
|
|
|
|
|
*
|
|
|
|
|
* For example: channel.declareQueue("myqueue").onSuccess([](AMQP::Channel *channel, uint32_t messageCount) {
|
|
|
|
|
*
|
|
|
|
|
* std::cout << "Queue purged, all " << messageCount << " messages removed" << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
Deferred<uint32_t>& purgeQueue(const std::string &name, int flags);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Remove a queue
|
|
|
|
|
* @param queue queue to remove
|
|
|
|
|
* @param flags additional flags
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
|
|
|
|
*
|
|
|
|
|
* The onSuccess() callback that you can install should have the following signature:
|
|
|
|
|
*
|
|
|
|
|
* void myCallback(AMQP::Channel *channel, uint32_t messageCount);
|
|
|
|
|
*
|
|
|
|
|
* For example: channel.declareQueue("myqueue").onSuccess([](AMQP::Channel *channel, uint32_t messageCount) {
|
|
|
|
|
*
|
|
|
|
|
* std::cout << "Queue deleted, along with " << messageCount << " messages" << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
Deferred<uint32_t>& removeQueue(const std::string &name, int flags);
|
2014-01-05 04:01:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Publish a message to an exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 04:01:02 +08:00
|
|
|
* The following flags can be used
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 04:01:02 +08:00
|
|
|
* - mandatory if set, an unroutable message will be reported to the channel handler with the onReturned method
|
|
|
|
|
* - immediate if set, a message that could not immediately be consumed is returned to the onReturned method
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-07 00:15:21 +08:00
|
|
|
* If the mandatory or immediate flag is set, and the message could not immediately
|
|
|
|
|
* be published, the message will be returned to the client, and will eventually
|
|
|
|
|
* end up in your ChannelHandler::onReturned() method.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 04:01:02 +08:00
|
|
|
* @param exchange the exchange to publish to
|
|
|
|
|
* @param routingkey the routing key
|
|
|
|
|
* @param flags optional flags (see above)
|
|
|
|
|
* @param envelope the full envelope to send
|
|
|
|
|
* @param message the message to send
|
|
|
|
|
* @param size size of the message
|
|
|
|
|
*/
|
|
|
|
|
bool publish(const std::string &exchange, const std::string &routingKey, int flags, const Envelope &envelope);
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-05 21:19:35 +08:00
|
|
|
/**
|
|
|
|
|
* Set the Quality of Service (QOS) of the entire connection
|
|
|
|
|
* @param prefetchCount maximum number of messages to prefetch
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-05 21:19:35 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& setQos(uint16_t prefetchCount);
|
2014-01-05 21:19:35 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Tell the RabbitMQ server that we're ready to consume messages
|
|
|
|
|
* @param queue the queue from which you want to consume
|
|
|
|
|
* @param tag a consumer tag that will be associated with this consume operation
|
|
|
|
|
* @param flags additional flags
|
|
|
|
|
* @param arguments additional arguments
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool consume(const std::string &queue, const std::string &tag, int flags, const Table &arguments);
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Cancel a running consumer
|
|
|
|
|
* @param tag the consumer tag
|
|
|
|
|
* @param flags optional flags
|
2014-01-06 04:21:09 +08:00
|
|
|
* @return bool
|
2014-01-06 01:50:41 +08:00
|
|
|
*/
|
|
|
|
|
bool cancel(const std::string &tag, int flags);
|
2014-01-06 04:21:09 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Acknoledge a message
|
|
|
|
|
* @param deliveryTag the delivery tag
|
|
|
|
|
* @param flags optional flags
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool ack(uint64_t deliveryTag, int flags);
|
2014-01-06 21:28:58 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reject a message
|
|
|
|
|
* @param deliveryTag the delivery tag
|
|
|
|
|
* @param flags optional flags
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool reject(uint64_t deliveryTag, int flags);
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 21:38:48 +08:00
|
|
|
/**
|
|
|
|
|
* Recover messages that were not yet ack'ed
|
|
|
|
|
* @param flags optional flags
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-06 21:38:48 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& recover(int flags);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Close the current channel
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This function returns a deferred handler. Callbacks can be installed
|
|
|
|
|
* using onSuccess(), onError() and onFinalize() methods.
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
Deferred<>& close();
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the channel we're working on
|
|
|
|
|
* @return uint16_t
|
|
|
|
|
*/
|
|
|
|
|
const uint16_t id() const
|
|
|
|
|
{
|
|
|
|
|
return _id;
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Send a frame over the channel
|
|
|
|
|
* @param frame frame to send
|
2014-01-07 00:15:21 +08:00
|
|
|
* @return bool was frame succesfully sent?
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-01-07 00:15:21 +08:00
|
|
|
bool send(const Frame &frame);
|
2014-04-08 20:42:07 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a frame over the channel and
|
|
|
|
|
* get a deferred handler for it.
|
|
|
|
|
*
|
|
|
|
|
* @param frame frame to send
|
|
|
|
|
* @param message the message to trigger if the frame cannot be send at all
|
|
|
|
|
*/
|
|
|
|
|
Deferred<>& send(const Frame &frame, const char *message);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a frame over the channel and
|
|
|
|
|
* get a deferred handler for it.
|
|
|
|
|
*
|
|
|
|
|
* @param frame frame to send
|
|
|
|
|
* @param message the message to trigger if the frame cannot be send at all
|
|
|
|
|
* @param queue the queue to store the callbacks in
|
|
|
|
|
*/
|
|
|
|
|
template <typename... Arguments>
|
|
|
|
|
Deferred<Arguments...>& send(const Frame &frame, const char *message, std::deque<Deferred<Arguments...>>& queue);
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report to the handler that the channel is closed
|
|
|
|
|
*/
|
|
|
|
|
void reportClosed()
|
|
|
|
|
{
|
|
|
|
|
// change state
|
|
|
|
|
_state = state_closed;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
// inform handler
|
2014-04-08 20:42:07 +08:00
|
|
|
reportSuccess();
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
2014-04-08 20:42:07 +08:00
|
|
|
* Report success
|
|
|
|
|
*
|
|
|
|
|
* This function is called to report success for all
|
|
|
|
|
* cases where the callback does not receive any parameters
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-08 20:42:07 +08:00
|
|
|
void reportSuccess()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
2014-04-08 20:42:07 +08:00
|
|
|
// report success for the oldest request
|
|
|
|
|
_callbacks.front().success();
|
|
|
|
|
_callbacks.pop_front();
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report to the handler that the channel is opened
|
|
|
|
|
*/
|
|
|
|
|
void reportReady()
|
|
|
|
|
{
|
|
|
|
|
// inform handler
|
2014-04-08 20:42:07 +08:00
|
|
|
if (_readyCallback) _readyCallback(_parent);
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report an error message on a channel
|
|
|
|
|
* @param message
|
|
|
|
|
*/
|
2014-01-05 04:01:02 +08:00
|
|
|
void reportError(const std::string &message)
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
// change state
|
|
|
|
|
_state = state_closed;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
// inform handler
|
2014-04-08 20:42:07 +08:00
|
|
|
if (_errorCallback) _errorCallback(_parent, message);
|
2014-01-04 19:45:04 +08:00
|
|
|
|
2014-04-08 20:42:07 +08:00
|
|
|
// and all waiting deferred callbacks
|
|
|
|
|
for (auto &deferred : _callbacks) deferred.error(message);
|
|
|
|
|
for (auto &deferred : _queueDeclaredCallbacks) deferred.error(message);
|
|
|
|
|
for (auto &deferred : _queueRemovedCallbacks) deferred.error(message);
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report that the queue was succesfully declared
|
|
|
|
|
* @param queueName name of the queue which was declared
|
|
|
|
|
* @param messagecount number of messages currently in the queue
|
|
|
|
|
* @param consumerCount number of active consumers in the queue
|
|
|
|
|
*/
|
|
|
|
|
void reportQueueDeclared(const std::string &queueName, uint32_t messageCount, uint32_t consumerCount)
|
|
|
|
|
{
|
2014-04-08 20:42:07 +08:00
|
|
|
// report success for the oldest queue declare callbacks
|
|
|
|
|
_queueDeclaredCallbacks.front().success(queueName, messageCount, consumerCount);
|
|
|
|
|
_queueDeclaredCallbacks.pop_front();
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report that a queue was succesfully deleted
|
|
|
|
|
* @param messageCount number of messages left in queue, now deleted
|
|
|
|
|
*/
|
|
|
|
|
void reportQueueDeleted(uint32_t messageCount)
|
|
|
|
|
{
|
2014-04-08 20:42:07 +08:00
|
|
|
// report success for the oldest queue remove callbacks
|
|
|
|
|
_queueRemovedCallbacks.front().success(messageCount);
|
|
|
|
|
_queueRemovedCallbacks.pop_front();
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Report that a queue was succesfully purged
|
|
|
|
|
* @param messageCount number of messages purged
|
|
|
|
|
*/
|
|
|
|
|
void reportQueuePurged(uint32_t messageCount)
|
|
|
|
|
{
|
2014-04-08 20:42:07 +08:00
|
|
|
// report success for the oldest queue remove callbacks
|
|
|
|
|
_queueRemovedCallbacks.front().success(messageCount);
|
|
|
|
|
_queueRemovedCallbacks.pop_front();
|
2014-01-04 19:45:04 +08:00
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Report that a consumer has started
|
|
|
|
|
* @param tag the consumer tag
|
|
|
|
|
*/
|
|
|
|
|
void reportConsumerStarted(const std::string &tag)
|
|
|
|
|
{
|
|
|
|
|
if (_handler) _handler->onConsumerStarted(_parent, tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Report that a consumer has stopped
|
|
|
|
|
* @param tag the consumer tag
|
|
|
|
|
*/
|
|
|
|
|
void reportConsumerStopped(const std::string &tag)
|
|
|
|
|
{
|
|
|
|
|
if (_handler) _handler->onConsumerStopped(_parent, tag);
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
2014-01-06 04:21:09 +08:00
|
|
|
* Report that a message was received
|
2014-01-06 01:50:41 +08:00
|
|
|
*/
|
2014-01-06 22:49:31 +08:00
|
|
|
void reportMessage();
|
2014-01-06 01:50:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create an incoming message
|
|
|
|
|
* @param frame
|
|
|
|
|
* @return MessageImpl
|
|
|
|
|
*/
|
|
|
|
|
MessageImpl *message(const BasicDeliverFrame &frame);
|
2014-01-06 22:49:31 +08:00
|
|
|
MessageImpl *message(const BasicReturnFrame &frame);
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Retrieve the current incoming message
|
|
|
|
|
* @return MessageImpl
|
|
|
|
|
*/
|
|
|
|
|
MessageImpl *message()
|
|
|
|
|
{
|
|
|
|
|
return _message;
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* The channel class is its friend, thus can it instantiate this object
|
|
|
|
|
*/
|
|
|
|
|
friend class Channel;
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|