From f5540e9af2d44211159cf5067a5cc0f199064a12 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Tue, 6 Feb 2018 21:54:56 +0100 Subject: [PATCH] fixed autodelete flag for declaring an exchange and added support for internal exchange. this fixes #183 --- include/amqpcpp/channel.h | 3 ++- include/amqpcpp/flags.h | 3 ++- src/channelimpl.cpp | 11 +++++++++-- src/exchangedeclareframe.h | 31 +++++++++++++++++++++++++------ src/flags.cpp | 3 ++- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/include/amqpcpp/channel.h b/include/amqpcpp/channel.h index bff4085..c41e0aa 100644 --- a/include/amqpcpp/channel.h +++ b/include/amqpcpp/channel.h @@ -1,7 +1,7 @@ /** * Class describing a (mid-level) AMQP channel implementation * - * @copyright 2014 - 2017 Copernica BV + * @copyright 2014 - 2018 Copernica BV */ /** @@ -170,6 +170,7 @@ public: * - durable exchange survives a broker restart * - autodelete exchange is automatically removed when all connected queues are removed * - passive only check if the exchange exist + * - internal create an internal exchange * * @param name name of the exchange * @param type exchange type diff --git a/include/amqpcpp/flags.h b/include/amqpcpp/flags.h index 3a4a2c3..37779af 100644 --- a/include/amqpcpp/flags.h +++ b/include/amqpcpp/flags.h @@ -3,7 +3,7 @@ * * The various flags that are supported * - * @copyright 2014 Copernica BV + * @copyright 2014 - 2018 Copernica BV */ /** @@ -38,6 +38,7 @@ extern const int multiple; extern const int requeue; extern const int readable; extern const int writable; +extern const int internal; /** * End of namespace diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index 9d32874..e655657 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -252,7 +252,7 @@ Deferred &ChannelImpl::close() Deferred &ChannelImpl::declareExchange(const std::string &name, ExchangeType type, int flags, const Table &arguments) { // convert exchange type - std::string exchangeType; + const char *exchangeType = ""; // convert the exchange type into a string if (type == ExchangeType::fanout) exchangeType = "fanout"; @@ -261,8 +261,15 @@ Deferred &ChannelImpl::declareExchange(const std::string &name, ExchangeType typ else if (type == ExchangeType::headers) exchangeType = "headers"; else if (type == ExchangeType::consistent_hash) exchangeType = "x-consistent-hash"; + // the boolean options + bool passive = flags & AMQP::passive; + bool durable = flags & AMQP::durable; + bool autodelete = flags & AMQP::autodelete; + bool internal = flags & AMQP::internal; + bool nowait = flags & AMQP::nowait; + // send declare exchange frame - return push(ExchangeDeclareFrame(_id, name, exchangeType, (flags & passive) != 0, (flags & durable) != 0, false, arguments)); + return push(ExchangeDeclareFrame(_id, name, exchangeType, passive, durable, autodelete, internal, nowait, arguments)); } /** diff --git a/src/exchangedeclareframe.h b/src/exchangedeclareframe.h index cb45f01..5e02b2c 100644 --- a/src/exchangedeclareframe.h +++ b/src/exchangedeclareframe.h @@ -1,7 +1,7 @@ /** * Class describing an AMQP exchange declare frame * - * @copyright 2014 Copernica BV + * @copyright 2014 - 2018 Copernica BV */ /** @@ -77,16 +77,17 @@ public: * @param type exchange type * @param passive do not create exchange if it does not exist * @param durable durable exchange + * @param autodelete is this an auto-delete exchange? + * @param internal is this an internal exchange * @param noWait do not wait on response * @param arguments additional arguments */ - ExchangeDeclareFrame(uint16_t channel, const std::string& name, const std::string& type, bool passive, bool durable, bool noWait, const Table& arguments) : - ExchangeFrame(channel, (uint32_t)(name.length() + type.length() + arguments.size() + 5)), // size of name, type and arguments + 1 (all booleans are stored in 1 byte) + 2 (deprecated short) + 2 (string sizes) + ExchangeDeclareFrame(uint16_t channel, const std::string& name, const char *type, bool passive, bool durable, bool autodelete, bool internal, bool nowait, const Table& arguments) : + ExchangeFrame(channel, (uint32_t)(name.length() + strlen(type) + arguments.size() + 5)), // size of name, type and arguments + 1 (all booleans are stored in 1 byte) + 2 (deprecated short) + 2 (string sizes) _name(name), _type(type), - _bools(passive, durable, false, false, noWait), - _arguments(arguments) - {} + _bools(passive, durable, autodelete, internal, nowait), + _arguments(arguments) {} /** * Construct parsing a declare frame from a received frame @@ -162,6 +163,24 @@ public: { return _bools.get(1); } + + /** + * Is this an autodelete exchange? + * @return bool + */ + bool autoDelete() const + { + return _bools.get(2); + } + + /** + * Is this an internal exchange? + * @return bool + */ + bool internal() const + { + return _bools.get(3); + } /** * Do not wait for a response diff --git a/src/flags.cpp b/src/flags.cpp index 946b51c..24351cb 100644 --- a/src/flags.cpp +++ b/src/flags.cpp @@ -3,7 +3,7 @@ * * The various flags that are supported * - * @copyright 2014 Copernica BV + * @copyright 2014 - 2018 Copernica BV */ #include "includes.h" @@ -32,6 +32,7 @@ const int immediate = 0x1000; const int redelivered = 0x2000; const int multiple = 0x4000; const int requeue = 0x8000; +const int internal = 0x10000; /** * Flags for event loops