From f23dc72a4fdcb174f372ea29b361b2f2ddaf35d5 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 26 Jan 2015 14:47:30 +0100 Subject: [PATCH] Fixed documentation, removed references to the ChannelHandler - an object that is no longer supported by AMQP-CPP --- README.md | 14 +++++++------- include/channelimpl.h | 4 ++-- include/message.h | 2 +- src/connectionstartframe.h | 19 ++++++++++++++++++- tests/myconnection.cpp | 23 ++++------------------- tests/myconnection.h | 4 ++-- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 1e0fdd2..cbc6bf1 100644 --- a/README.md +++ b/README.md @@ -444,16 +444,16 @@ in almost any form: * * The following flags can be used * - * - mandatory if set, an unroutable message will be reported to the - * channel handler with the onReturned method + * - mandatory if set, an unroutable message will be sent back to + * the client (currently not supported) * * - immediate if set, a message that could not immediately be consumed - * is returned to the onReturned method + * is returned to the client (currently not supported) * * If either of the two flags is set, and the message could not immediately - * be published, the message is returned by the server to the client. If you - * want to catch such returned messages, you need to implement the - * ChannelHandler::onReturned() method. + * be published, the message is returned by the server to the client. However, + * at this moment in time, the AMQP-CPP library does not support catching + * such returned messages. * * @param exchange the exchange to publish to * @param routingkey the routing key @@ -543,7 +543,7 @@ The full documentation from the C++ Channel.h headerfile looks like this: * - exclusive request exclusive access, only this consumer can * access the queue * - * The method ChannelHandler::onConsumerStarted() will be called when the + * The callback registered with DeferredConsumer::onSuccess() will be called when the * consumer has started. * * @param queue the queue from which you want to consume diff --git a/include/channelimpl.h b/include/channelimpl.h index 409e259..a7fab39 100644 --- a/include/channelimpl.h +++ b/include/channelimpl.h @@ -371,8 +371,8 @@ public: * Publish a message to an exchange * * 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 onReturned() handler method. + * be published, the message will be returned to the client. However, the AMQP-CPP + * library does not yet report such returned messages. * * @param exchange the exchange to publish to * @param routingkey the routing key diff --git a/include/message.h b/include/message.h index c92cc5e..92157ff 100644 --- a/include/message.h +++ b/include/message.h @@ -6,7 +6,7 @@ * message, plus some additional information. * * Message objects can not be constructed by end users, they are only constructed - * by the AMQP library, and passed to the ChannelHandler::onDelivered() method + * by the AMQP library, and passed to user callbacks. * * @copyright 2014 Copernica BV */ diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h index 806bbf0..b7cdb37 100644 --- a/src/connectionstartframe.h +++ b/src/connectionstartframe.h @@ -38,7 +38,7 @@ private: * @var Table */ Table _properties; - + /** * Available security mechanisms * @var LongString @@ -147,6 +147,16 @@ public: return _properties; } + /** + * The capabilities of the connection + * @return Table + */ + const Table& capabilities() const + { + // retrieve the capabilities + return _properties.get("capabilities"); + } + /** * Available security mechanisms * @return string @@ -173,6 +183,12 @@ public: */ virtual bool process(ConnectionImpl *connection) override { + // the capabilities + Table capabilities; + + // we want a special treatment for authentication failures + capabilities["authentication_failure_close"] = true; + // the peer properties Table properties; @@ -182,6 +198,7 @@ public: properties["platform"] = "Unknown"; properties["copyright"] = "Copyright 2014 Copernica BV"; properties["information"] = "http://www.copernica.com"; + properties["capabilities"] = capabilities; // move connection to handshake mode connection->setProtocolOk(); diff --git a/tests/myconnection.cpp b/tests/myconnection.cpp index dd6e265..50bbe2d 100644 --- a/tests/myconnection.cpp +++ b/tests/myconnection.cpp @@ -27,9 +27,7 @@ using namespace Copernica; * Constructor */ MyConnection::MyConnection(const std::string &ip) : - _socket(Event::MainLoop::instance(), this), - _connection(nullptr), - _channel(nullptr) + _socket(Event::MainLoop::instance(), this) { // start connecting if (_socket.connect(Network::Ipv4Address(ip), 5672)) return; @@ -43,11 +41,6 @@ MyConnection::MyConnection(const std::string &ip) : */ MyConnection::~MyConnection() { - // do we still have a channel? - if (_channel) delete _channel; - - // do we still have a connection? - if (_connection) delete _connection; } /** @@ -83,8 +76,8 @@ void MyConnection::onConnected(Network::TcpSocket *socket) if (_connection) return; // create amqp connection, and a new channel - _connection = new AMQP::Connection(this, AMQP::Login("guest", "guest"), "/"); - _channel = new AMQP::Channel(_connection); + _connection = std::make_shared(this, AMQP::Login("guest1", "guest2"), "/"); + _channel = std::make_shared(_connection.get()); // install a handler when channel is in error _channel->onError([](const char *message) { @@ -130,10 +123,6 @@ void MyConnection::onClosed(Network::TcpSocket *socket) // show std::cout << "myconnection closed" << std::endl; - // close the channel and connection - if (_channel) delete _channel; - if (_connection) delete _connection; - // set to null _channel = nullptr; _connection = nullptr; @@ -148,10 +137,6 @@ void MyConnection::onLost(Network::TcpSocket *socket) // report error std::cout << "connection lost" << std::endl; - // close the channel and connection - if (_channel) delete _channel; - if (_connection) delete _connection; - // set to null _channel = nullptr; _connection = nullptr; @@ -229,6 +214,6 @@ void MyConnection::onConnected(AMQP::Connection *connection) std::cout << "AMQP login success" << std::endl; // create channel if it does not yet exist - if (!_channel) _channel = new AMQP::Channel(connection); + if (!_channel) _channel = std::make_shared(connection); } diff --git a/tests/myconnection.h b/tests/myconnection.h index 25fb710..7b9d4b1 100644 --- a/tests/myconnection.h +++ b/tests/myconnection.h @@ -24,13 +24,13 @@ private: * The AMQP connection * @var Connection */ - AMQP::Connection *_connection; + std::shared_ptr _connection; /** * The AMQP channel * @var Channel */ - AMQP::Channel *_channel; + std::shared_ptr _channel; /** * Method that is called when the connection failed