First setup for implementing the publish method

This commit is contained in:
Emiel Bruijntjes 2014-01-04 12:01:02 -08:00
parent 24a4b866c1
commit 9c1e44f512
7 changed files with 66 additions and 14 deletions

View File

@ -248,6 +248,30 @@ public:
*/
bool removeQueue(const std::string &name, int flags = 0) { return _implementation.removeQueue(name, flags); }
/**
* Publish a message to an exchange
*
* The following flags can be used
*
* - 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
*
* @todo implement to onReturned() method
*
* @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) { return _implementation.publish(exchange, routingKey, flags, envelope); }
bool publish(const std::string &exchange, const std::string &routingKey, const Envelope &envelope) { return _implementation.publish(exchange, routingKey, 0, envelope); }
bool publish(const std::string &exchange, const std::string &routingKey, int flags, const std::string &message) { return _implementation.publish(exchange, routingKey, flags, Envelope(message)); }
bool publish(const std::string &exchange, const std::string &routingKey, const std::string &message) { return _implementation.publish(exchange, routingKey, 0, Envelope(message)); }
bool publish(const std::string &exchange, const std::string &routingKey, int flags, const char *message, size_t size) { return _implementation.publish(exchange, routingKey, flags, Envelope(message, size)); }
bool publish(const std::string &exchange, const std::string &routingKey, const char *message, size_t size) { return _implementation.publish(exchange, routingKey, 0, Envelope(message, size)); }
/**
* Close the current channel
* @return bool

View File

@ -210,6 +210,25 @@ public:
*/
bool removeQueue(const std::string &name, int flags);
/**
* Publish a message to an exchange
*
* The following flags can be used
*
* - 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
*
* @todo implement to onReturned() method
*
* @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);
/**
* Close the current channel
* @return bool
@ -275,7 +294,7 @@ public:
* Report an error message on a channel
* @param message
*/
void reportChannelError(const std::string &message)
void reportError(const std::string &message)
{
// change state
_state = state_closed;

View File

@ -241,9 +241,10 @@ public:
* Report an error message
* @param message
*/
void reportConnectionError(const std::string &message)
void reportError(const std::string &message)
{
// close everything
// @todo is this not duplicate?
close();
// set connection state to closed

View File

@ -122,6 +122,12 @@ public:
*/
Envelope(const char *data, size_t size) : _data(data), _size(size) {}
/**
* Constructor based on a string
* @param message
*/
Envelope(const std::string &data) : _data(data.data()), _size(data.size()) {}
/**
* Destructor
*/

View File

@ -29,7 +29,7 @@ bool ChannelCloseFrame::process(ConnectionImpl *connection)
if (!channel) return false;
// report to the handler
channel->reportChannelError(text());
channel->reportError(text());
// done
return true;

View File

@ -19,12 +19,14 @@ namespace AMQP {
*/
bool ConnectionCloseFrame::process(ConnectionImpl *connection)
{
// @todo connection could be destructed after frame was sent
// send back the ok frame
connection->send(ConnectionCloseOKFrame());
// no need to check for a channel, the error is connection wide
// report the error on the connection
connection->reportConnectionError(text());
connection->reportError(text());
// done
return true;

View File

@ -138,7 +138,7 @@ size_t ConnectionImpl::parse(char *buffer, size_t size)
catch (const ProtocolException &exception)
{
// something terrible happened on the protocol (like data out of range)
reportConnectionError(exception.what());
reportError(exception.what());
// done
return processed;