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); } 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 * Close the current channel
* @return bool * @return bool

View File

@ -210,6 +210,25 @@ public:
*/ */
bool removeQueue(const std::string &name, int flags); 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 * Close the current channel
* @return bool * @return bool
@ -275,7 +294,7 @@ public:
* Report an error message on a channel * Report an error message on a channel
* @param message * @param message
*/ */
void reportChannelError(const std::string &message) void reportError(const std::string &message)
{ {
// change state // change state
_state = state_closed; _state = state_closed;
@ -289,7 +308,7 @@ public:
*/ */
void reportExchangeDeclared() void reportExchangeDeclared()
{ {
if(_handler) _handler->onExchangeDeclared(_parent); if (_handler) _handler->onExchangeDeclared(_parent);
} }
/** /**
@ -297,7 +316,7 @@ public:
*/ */
void reportExchangeDeleted() void reportExchangeDeleted()
{ {
if(_handler) _handler->onExchangeDeleted(_parent); if (_handler) _handler->onExchangeDeleted(_parent);
} }
/** /**
@ -305,7 +324,7 @@ public:
*/ */
void reportExchangeBound() void reportExchangeBound()
{ {
if(_handler) _handler->onExchangeBound(_parent); if (_handler) _handler->onExchangeBound(_parent);
} }
/** /**
@ -313,7 +332,7 @@ public:
*/ */
void reportExchangeUnbound() void reportExchangeUnbound()
{ {
if(_handler) _handler->onExchangeUnbound(_parent); if (_handler) _handler->onExchangeUnbound(_parent);
} }
/** /**
@ -324,7 +343,7 @@ public:
*/ */
void reportQueueDeclared(const std::string &queueName, uint32_t messageCount, uint32_t consumerCount) void reportQueueDeclared(const std::string &queueName, uint32_t messageCount, uint32_t consumerCount)
{ {
if(_handler) _handler->onQueueDeclared(_parent, queueName, messageCount, consumerCount); if (_handler) _handler->onQueueDeclared(_parent, queueName, messageCount, consumerCount);
} }
/** /**
@ -332,7 +351,7 @@ public:
*/ */
void reportQueueBound() void reportQueueBound()
{ {
if(_handler) _handler->onQueueBound(_parent); if (_handler) _handler->onQueueBound(_parent);
} }
/** /**
@ -340,7 +359,7 @@ public:
*/ */
void reportQueueUnbound() void reportQueueUnbound()
{ {
if(_handler) _handler->onQueueUnbound(_parent); if (_handler) _handler->onQueueUnbound(_parent);
} }
/** /**
@ -349,7 +368,7 @@ public:
*/ */
void reportQueueDeleted(uint32_t messageCount) void reportQueueDeleted(uint32_t messageCount)
{ {
if(_handler) _handler->onQueueDeleted(_parent, messageCount); if (_handler) _handler->onQueueDeleted(_parent, messageCount);
} }
/** /**
@ -358,7 +377,7 @@ public:
*/ */
void reportQueuePurged(uint32_t messageCount) void reportQueuePurged(uint32_t messageCount)
{ {
if(_handler) _handler->onQueuePurged(_parent, messageCount); if (_handler) _handler->onQueuePurged(_parent, messageCount);
} }
/** /**

View File

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

View File

@ -122,6 +122,12 @@ public:
*/ */
Envelope(const char *data, size_t size) : _data(data), _size(size) {} 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 * Destructor
*/ */

View File

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

View File

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

View File

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