2014-04-02 21:40:35 +08:00
|
|
|
#pragma once
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Class describing a (mid-level) AMQP channel implementation
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
class Channel
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The implementation for the channel
|
|
|
|
|
* @var ChannelImpl
|
|
|
|
|
*/
|
|
|
|
|
ChannelImpl _implementation;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct a channel object
|
|
|
|
|
* @param connection
|
|
|
|
|
*/
|
2014-04-10 18:51:04 +08:00
|
|
|
Channel(Connection *connection) : _implementation(this, connection) {}
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Channel() {}
|
|
|
|
|
|
2014-04-08 20:42:07 +08:00
|
|
|
/**
|
|
|
|
|
* Callback that is called when the channel was succesfully created.
|
|
|
|
|
*
|
|
|
|
|
* Only one callback can be registered. Calling this function multiple
|
|
|
|
|
* times will remove the old callback.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback to execute
|
|
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
void onReady(const SuccessCallback &callback)
|
2014-04-08 20:42:07 +08:00
|
|
|
{
|
|
|
|
|
// store callback in implementation
|
|
|
|
|
_implementation._readyCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback that is called when an error occurs.
|
|
|
|
|
*
|
|
|
|
|
* Only one error callback can be registered. Calling this function
|
|
|
|
|
* multiple times will remove the old callback.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback to execute
|
|
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
void onError(const ErrorCallback &callback)
|
2014-04-08 20:42:07 +08:00
|
|
|
{
|
|
|
|
|
// store callback in implementation
|
|
|
|
|
_implementation._errorCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
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-15 16:43:33 +08:00
|
|
|
Deferred &pause()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.pause();
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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-15 16:43:33 +08:00
|
|
|
Deferred &resume()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.resume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is the channel connected?
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool connected()
|
|
|
|
|
{
|
|
|
|
|
return _implementation.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
|
|
|
*
|
|
|
|
|
* 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-15 16:43:33 +08:00
|
|
|
Deferred &startTransaction()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.startTransaction();
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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-15 16:43:33 +08:00
|
|
|
Deferred &commitTransaction()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.commitTransaction();
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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-15 16:43:33 +08:00
|
|
|
Deferred &rollbackTransaction()
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.rollbackTransaction();
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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
|
|
|
* If an empty name is supplied, a name will be assigned by the server.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The following flags can be used for the exchange:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - durable exchange survives a broker restart
|
|
|
|
|
* - autodelete exchange is automatically removed when all connected queues are removed
|
|
|
|
|
* - passive only check if the exchange exist
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param name name of the exchange
|
|
|
|
|
* @param type exchange type
|
|
|
|
|
* @param flags exchange 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-15 16:43:33 +08:00
|
|
|
Deferred &declareExchange(const std::string &name, ExchangeType type, int flags, const Table &arguments) { return _implementation.declareExchange(name, type, flags, arguments); }
|
|
|
|
|
Deferred &declareExchange(const std::string &name, ExchangeType type, const Table &arguments) { return _implementation.declareExchange(name, type, 0, arguments); }
|
|
|
|
|
Deferred &declareExchange(const std::string &name, ExchangeType type = fanout, int flags = 0) { return _implementation.declareExchange(name, type, flags, Table()); }
|
|
|
|
|
Deferred &declareExchange(ExchangeType type, int flags, const Table &arguments) { return _implementation.declareExchange(std::string(), type, flags, arguments); }
|
|
|
|
|
Deferred &declareExchange(ExchangeType type, const Table &arguments) { return _implementation.declareExchange(std::string(), type, 0, arguments); }
|
|
|
|
|
Deferred &declareExchange(ExchangeType type = fanout, int flags = 0) { return _implementation.declareExchange(std::string(), type, flags, Table()); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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
|
|
|
* The following flags can be used for the exchange:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - ifunused only delete if no queues are connected
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
* @param name name of the exchange to remove
|
|
|
|
|
* @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-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
Deferred &removeExchange(const std::string &name, int flags = 0) { return _implementation.removeExchange(name, flags); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Bind two exchanges to each other
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The following flags can be used for the exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - nowait do not wait on response
|
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 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-15 16:43:33 +08:00
|
|
|
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.bindExchange(source, target, routingkey, flags, arguments); }
|
|
|
|
|
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments) { return _implementation.bindExchange(source, target, routingkey, 0, arguments); }
|
|
|
|
|
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags = 0) { return _implementation.bindExchange(source, target, routingkey, flags, Table()); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Unbind two exchanges from one another
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The following flags can be used for the exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - nowait do not wait on response
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param target the target exchange
|
|
|
|
|
* @param source the source 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-15 16:43:33 +08:00
|
|
|
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.unbindExchange(target, source, routingkey, flags, arguments); }
|
|
|
|
|
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, const Table &arguments) { return _implementation.unbindExchange(target, source, routingkey, 0, arguments); }
|
|
|
|
|
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, int flags = 0) { return _implementation.unbindExchange(target, source, routingkey, flags, Table()); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Declare a queue
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* If you do not supply a name, a name will be assigned by the server.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The flags can be a combination of the following values:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - durable queue survives a broker restart
|
|
|
|
|
* - autodelete queue is automatically removed when all connected consumers are gone
|
|
|
|
|
* - passive only check if the queue exist
|
|
|
|
|
* - exclusive the queue only exists for this connection, and is automatically removed when connection is gone
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param name name of the queue
|
|
|
|
|
* @param flags combination of flags
|
|
|
|
|
* @param arguments optional 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.
|
|
|
|
|
*
|
|
|
|
|
* The onSuccess() callback that you can install should have the following signature:
|
|
|
|
|
*
|
|
|
|
|
* void myCallback(AMQP::Channel *channel, const std::string &name, uint32_t messageCount, uint32_t consumerCount);
|
|
|
|
|
*
|
|
|
|
|
* For example: channel.declareQueue("myqueue").onSuccess([](AMQP::Channel *channel, const std::string &name, uint32_t messageCount, uint32_t consumerCount) {
|
|
|
|
|
*
|
|
|
|
|
* std::cout << "Queue '" << name << "' has been declared with " << messageCount << " messages and " << consumerCount << " consumers" << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
DeferredQueue &declareQueue(const std::string &name, int flags, const Table &arguments) { return _implementation.declareQueue(name, flags, arguments); }
|
|
|
|
|
DeferredQueue &declareQueue(const std::string &name, const Table &arguments) { return _implementation.declareQueue(name, 0, arguments); }
|
|
|
|
|
DeferredQueue &declareQueue(const std::string &name, int flags = 0) { return _implementation.declareQueue(name, flags, Table()); }
|
|
|
|
|
DeferredQueue &declareQueue(int flags, const Table &arguments) { return _implementation.declareQueue(std::string(), flags, arguments); }
|
|
|
|
|
DeferredQueue &declareQueue(const Table &arguments) { return _implementation.declareQueue(std::string(), 0, arguments); }
|
|
|
|
|
DeferredQueue &declareQueue(int flags = 0) { return _implementation.declareQueue(std::string(), flags, Table()); }
|
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
|
|
|
* The following flags can be used for the exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - nowait do not wait on response
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param exchange the source exchange
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param queue the target queue
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param routingkey the routing key
|
|
|
|
|
* @param flags additional flags
|
|
|
|
|
* @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-15 16:43:33 +08:00
|
|
|
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.bindQueue(exchange, queue, routingkey, flags, arguments); }
|
|
|
|
|
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, const Table &arguments) { return _implementation.bindQueue(exchange, queue, routingkey, 0, arguments); }
|
|
|
|
|
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, int flags = 0) { return _implementation.bindQueue(exchange, queue, routingkey, flags, Table()); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Unbind a queue from an exchange
|
|
|
|
|
* @param exchange the source exchange
|
2014-01-05 20:08:35 +08:00
|
|
|
* @param queue the target queue
|
2014-01-04 19:45:04 +08:00
|
|
|
* @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-15 16:43:33 +08:00
|
|
|
Deferred &unbindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, const Table &arguments) { return _implementation.unbindQueue(exchange, queue, routingkey, arguments); }
|
|
|
|
|
Deferred &unbindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey) { return _implementation.unbindQueue(exchange, queue, routingkey, Table()); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Purge a queue
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The following flags can be used for the exchange
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - nowait do not wait on response
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* @param name name of the queue
|
|
|
|
|
* @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;
|
|
|
|
|
*
|
|
|
|
|
* });
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
DeferredDelete &purgeQueue(const std::string &name, int flags = 0){ return _implementation.purgeQueue(name, flags); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Remove a queue
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-04 19:45:04 +08:00
|
|
|
* The following flags can be used for the exchange:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 01:20:45 +08:00
|
|
|
* - ifunused only delete if no consumers are connected
|
|
|
|
|
* - ifempty only delete if the queue is empty
|
2014-01-04 19:45:04 +08:00
|
|
|
*
|
|
|
|
|
* @param name name of the queue to remove
|
|
|
|
|
* @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.
|
|
|
|
|
*
|
|
|
|
|
* The onSuccess() callback that you can install should have the following signature:
|
|
|
|
|
*
|
|
|
|
|
* void myCallback(AMQP::Channel *channel, uint32_t messageCount);
|
|
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* For example: channel.removeQueue("myqueue").onSuccess([](AMQP::Channel *channel, uint32_t messageCount) {
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* std::cout << "Queue deleted, along with " << messageCount << " messages" << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
DeferredDelete &removeQueue(const std::string &name, int flags = 0) { return _implementation.removeQueue(name, flags); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
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
|
|
|
* @param exchange the exchange to publish to
|
|
|
|
|
* @param routingkey the routing key
|
|
|
|
|
* @param envelope the full envelope to send
|
|
|
|
|
* @param message the message to send
|
|
|
|
|
* @param size size of the message
|
|
|
|
|
*/
|
2014-04-10 18:51:04 +08:00
|
|
|
bool publish(const std::string &exchange, const std::string &routingKey, const Envelope &envelope) { return _implementation.publish(exchange, routingKey, envelope); }
|
|
|
|
|
bool publish(const std::string &exchange, const std::string &routingKey, const std::string &message) { return _implementation.publish(exchange, routingKey, Envelope(message)); }
|
|
|
|
|
bool publish(const std::string &exchange, const std::string &routingKey, const char *message, size_t size) { return _implementation.publish(exchange, routingKey, Envelope(message, size)); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-05 21:19:35 +08:00
|
|
|
/**
|
|
|
|
|
* Set the Quality of Service (QOS) for this channel
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* When you consume messages, every single message needs to be ack'ed to inform
|
2014-01-06 01:50:41 +08:00
|
|
|
* the RabbitMQ server that is has been received. The Qos setting specifies the
|
|
|
|
|
* number of unacked messages that may exist in the client application. The server
|
|
|
|
|
* stops delivering more messages if the number of unack'ed messages has reached
|
|
|
|
|
* the prefetchCount
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-05 21:19:35 +08:00
|
|
|
* @param prefetchCount maximum number of messages to prefetch
|
|
|
|
|
* @return bool whether the Qos frame is sent.
|
|
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
Deferred &setQos(uint16_t prefetchCount)
|
2014-01-05 21:19:35 +08:00
|
|
|
{
|
|
|
|
|
return _implementation.setQos(prefetchCount);
|
|
|
|
|
}
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Tell the RabbitMQ server that we're ready to consume messages
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* After this method is called, RabbitMQ starts delivering messages to the client
|
|
|
|
|
* application. The consume tag is a string identifier that will be passed to
|
2014-04-08 20:42:07 +08:00
|
|
|
* each received message, so that you can associate incoming messages with a
|
2014-01-06 01:50:41 +08:00
|
|
|
* consumer. If you do not specify a consumer tag, the server will assign one
|
|
|
|
|
* for you.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* The following flags are supported:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* - nolocal if set, messages published on this channel are not also consumed
|
|
|
|
|
* - noack if set, consumed messages do not have to be acked, this happens automatically
|
|
|
|
|
* - exclusive request exclusive access, only this consumer can access the queue
|
|
|
|
|
* - nowait the server does not have to send a response back that consuming is active
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* The method Deferred::onSuccess() will be called when the
|
2014-01-06 01:50:41 +08:00
|
|
|
* consumer has started (unless the nowait option was set, in which case
|
|
|
|
|
* no confirmation method is called)
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* @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
|
2014-04-10 18:51:04 +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, const std::string& tag);
|
|
|
|
|
*
|
|
|
|
|
* For example: channel.consume("myqueue").onSuccess([](AMQP::Channel *channel, const std::string& tag) {
|
|
|
|
|
*
|
|
|
|
|
* std::cout << "Started consuming under tag " << tag << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
2014-01-06 01:50:41 +08:00
|
|
|
*/
|
2014-04-15 20:49:03 +08:00
|
|
|
DeferredConsumer &consume(const std::string &queue, const std::string &tag, int flags, const Table &arguments) { return _implementation.consume(queue, tag, flags, arguments); }
|
|
|
|
|
DeferredConsumer &consume(const std::string &queue, const std::string &tag, int flags = 0) { return _implementation.consume(queue, tag, flags, Table()); }
|
|
|
|
|
DeferredConsumer &consume(const std::string &queue, const std::string &tag, const Table &arguments) { return _implementation.consume(queue, tag, 0, arguments); }
|
|
|
|
|
DeferredConsumer &consume(const std::string &queue, int flags, const Table &arguments) { return _implementation.consume(queue, std::string(), flags, arguments); }
|
|
|
|
|
DeferredConsumer &consume(const std::string &queue, int flags = 0) { return _implementation.consume(queue, std::string(), flags, Table()); }
|
|
|
|
|
DeferredConsumer &consume(const std::string &queue, const Table &arguments) { return _implementation.consume(queue, std::string(), 0, arguments); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Cancel a running consume call
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* If you want to stop a running consumer, you can use this method with the consumer tag
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* The following flags are supported:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* - nowait the server does not have to send a response back that the consumer has been cancelled
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* The method Deferred::onSuccess() will be called when the consumer
|
2014-01-06 01:50:41 +08:00
|
|
|
* was succesfully stopped (unless the nowait option was used, in which case no
|
|
|
|
|
* confirmation method is called)
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 01:50:41 +08:00
|
|
|
* @param tag the consumer tag
|
|
|
|
|
* @param flags optional additional flags
|
2014-04-10 18:51:04 +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, const std::string& tag);
|
|
|
|
|
*
|
|
|
|
|
* For example: channel.cancel("myqueue").onSuccess([](AMQP::Channel *channel, const std::string& tag) {
|
|
|
|
|
*
|
|
|
|
|
* std::cout << "Stopped consuming under tag " << tag << std::endl;
|
|
|
|
|
*
|
|
|
|
|
* });
|
2014-01-06 01:50:41 +08:00
|
|
|
*/
|
2014-04-15 16:43:33 +08:00
|
|
|
DeferredCancel &cancel(const std::string &tag, int flags = 0) { return _implementation.cancel(tag, flags); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 04:21:09 +08:00
|
|
|
/**
|
|
|
|
|
* Acknoldge a received message
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* When a message is received in the DeferredConsumer::onReceived() method,
|
|
|
|
|
* you must acknowledge it so that RabbitMQ removes it from the queue (unless
|
2014-01-06 04:21:09 +08:00
|
|
|
* you are consuming with the noack option). This method can be used for
|
2014-04-10 18:51:04 +08:00
|
|
|
* this acknowledging.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 04:21:09 +08:00
|
|
|
* The following flags are supported:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* - multiple acknowledge multiple messages: all un-acked messages that were earlier delivered are acknowledged too
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:28:58 +08:00
|
|
|
* @param deliveryTag the unique delivery tag of the message
|
|
|
|
|
* @param flags optional flags
|
2014-01-06 04:21:09 +08:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool ack(uint64_t deliveryTag, int flags=0) { return _implementation.ack(deliveryTag, flags); }
|
2014-04-08 20:42:07 +08:00
|
|
|
|
2014-01-06 21:28:58 +08:00
|
|
|
/**
|
|
|
|
|
* Reject or nack a message
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-04-10 18:51:04 +08:00
|
|
|
* When a message was received in the DeferredConsumer::onReceived() method,
|
|
|
|
|
* and you don't want to acknowledge it, you can also choose to reject it by
|
2014-04-08 20:42:07 +08:00
|
|
|
* calling this reject method.
|
|
|
|
|
*
|
2014-01-06 21:28:58 +08:00
|
|
|
* The following flags are supported:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:28:58 +08:00
|
|
|
* - multiple reject multiple messages: all un-acked messages that were earlier delivered are unacked too
|
|
|
|
|
* - requeue if set, the message is put back in the queue, otherwise it is dead-lettered/removed
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:28:58 +08:00
|
|
|
* @param deliveryTag the unique delivery tag of the message
|
|
|
|
|
* @param flags optional flags
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
bool reject(uint64_t deliveryTag, int flags=0) { return _implementation.reject(deliveryTag, flags); }
|
2014-01-06 21:38:48 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recover all messages that were not yet acked
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
|
|
|
|
* This method asks the server to redeliver all unacknowledged messages on a specified
|
2014-01-06 21:38:48 +08:00
|
|
|
* channel. Zero or more messages may be redelivered.
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:38:48 +08:00
|
|
|
* The following flags are supported:
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:38:48 +08:00
|
|
|
* - requeue if set, the server will requeue the messages, so the could also end up with at different consumer
|
2014-04-08 20:42:07 +08:00
|
|
|
*
|
2014-01-06 21:38:48 +08:00
|
|
|
* @param 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-15 16:43:33 +08:00
|
|
|
Deferred &recover(int flags = 0) { return _implementation.recover(flags); }
|
2014-01-06 21:38:48 +08:00
|
|
|
|
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-15 16:43:33 +08:00
|
|
|
Deferred &close() { return _implementation.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 _implementation.id();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* end namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|