diff --git a/include/cppamqp.h b/include/cppamqp.h index 55f3266..cffd710 100644 --- a/include/cppamqp.h +++ b/include/cppamqp.h @@ -16,4 +16,5 @@ #include #include #include -#include \ No newline at end of file +#include +#include \ No newline at end of file diff --git a/include/cppamqp/channel.h b/include/cppamqp/channel.h index 49ad863..b62c11c 100644 --- a/include/cppamqp/channel.h +++ b/include/cppamqp/channel.h @@ -42,7 +42,7 @@ namespace cppamqp inline channel_number handle () const; inline const connection_t& connection () const; - queue_declaration declare_queue (const std::string& name, const queue_flags& flags); + queue_declaration declare_queue (const std::string& name, const queue_flags& flags, const table& args = empty_table); void bind_queue (const std::string& queue, const std::string& exchange, const std::string& routing_key); void publish (const std::string& exchange, const std::string& routing_key, const publish_flags& flags, const std::string& message, const publish_options* options = nullptr); std::string consume (const std::string& queue, const std::string& consumer_tag, const consume_flags& flags); diff --git a/include/cppamqp/types.h b/include/cppamqp/types.h index c5cb7d1..8681feb 100644 --- a/include/cppamqp/types.h +++ b/include/cppamqp/types.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace cppamqp @@ -14,4 +15,27 @@ namespace cppamqp using channel_number = amqp_channel_t; + struct field_value + : private amqp_field_value_t + { + private: + template + inline void set(T_value&& value); + + public: + inline field_value(); + + template + inline field_value(T_value&& value); + + template + inline field_value& operator=(T_value&& value); + + inline const amqp_field_value_t& get() const; + }; + + using table = std::map; + + const table empty_table; + } \ No newline at end of file diff --git a/include/cppamqp/types.inl b/include/cppamqp/types.inl new file mode 100644 index 0000000..5e81cda --- /dev/null +++ b/include/cppamqp/types.inl @@ -0,0 +1,105 @@ +#pragma once + +#include + +namespace cppamqp +{ + + template<> + inline void field_value::set(bool&& value) + { + this->kind = AMQP_FIELD_KIND_BOOLEAN; + this->value.boolean = static_cast(value); + } + + template<> + inline void field_value::set(int8_t&& value) + { + this->kind = AMQP_FIELD_KIND_I8; + this->value.i8 = value; + } + + template<> + inline void field_value::set(uint8_t&& value) + { + this->kind = AMQP_FIELD_KIND_U8; + this->value.u8 = value; + } + + template<> + inline void field_value::set(int16_t&& value) + { + this->kind = AMQP_FIELD_KIND_I16; + this->value.i16 = value; + } + + template<> + inline void field_value::set(uint16_t&& value) + { + this->kind = AMQP_FIELD_KIND_U16; + this->value.u16 = value; + } + + template<> + inline void field_value::set(int32_t&& value) + { + this->kind = AMQP_FIELD_KIND_I32; + this->value.i32 = value; + } + + template<> + inline void field_value::set(uint32_t&& value) + { + this->kind = AMQP_FIELD_KIND_U32; + this->value.u32 = value; + } + + template<> + inline void field_value::set(int64_t&& value) + { + this->kind = AMQP_FIELD_KIND_I64; + this->value.i64 = value; + } + + template<> + inline void field_value::set(uint64_t&& value) + { + this->kind = AMQP_FIELD_KIND_U64; + this->value.u64 = value; + } + + template<> + inline void field_value::set(float&& value) + { + this->kind = AMQP_FIELD_KIND_F32; + this->value.f32 = value; + } + + template<> + inline void field_value::set(double&& value) + { + this->kind = AMQP_FIELD_KIND_F64; + this->value.f64 = value; + } + + + field_value::field_value() + { + this->kind = AMQP_FIELD_KIND_VOID; + } + + template + field_value::field_value(T_value&& value) + { set(std::forward(value)); } + + template + field_value& field_value::operator=(T_value&& value) + { + set(std::forward(value)); + return *this; + } + + inline const amqp_field_value_t& field_value::get() const + { return *this; } + +} \ No newline at end of file diff --git a/src/cppamqp/channel.cpp b/src/cppamqp/channel.cpp index 298f42f..e204b53 100644 --- a/src/cppamqp/channel.cpp +++ b/src/cppamqp/channel.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -28,8 +29,20 @@ channel::internal::~internal() true); } -queue_declaration channel::declare_queue(const std::string& name, const queue_flags& flags) +queue_declaration channel::declare_queue(const std::string& name, const queue_flags& flags, const table& args) { + size_t i = 0; + amqp_table_t arg_table; + amqp_table_entry_t entries[args.size()]; + arg_table.num_entries = static_cast(args.size()); + arg_table.entries = &entries[0]; + for (auto& kvp : args) + { + arg_table.entries[i].key = __impl::make_bytes(kvp.first); + arg_table.entries[i].value = kvp.second.get(); + ++i; + } + auto ret = amqp_queue_declare( connection().handle(), handle(), @@ -38,7 +51,7 @@ queue_declaration channel::declare_queue(const std::string& name, const queue_fl flags.is_set(queue_flag::durable) ? 1 : 0, flags.is_set(queue_flag::exclusive) ? 1 : 0, flags.is_set(queue_flag::auto_delete) ? 1 : 0, - amqp_empty_table); + arg_table); __impl::check_and_raise( amqp_get_rpc_reply(connection().handle()), std::string("unable to declare queue '") + name + "'",