--- parser3/src/classes/amqp.C 2026/01/08 15:45:25 1.8 +++ parser3/src/classes/amqp.C 2026/01/09 03:36:59 1.12 @@ -23,7 +23,7 @@ #include #endif -volatile const char * IDENT_AMQP_C="$Id: amqp.C,v 1.8 2026/01/08 15:45:25 moko Exp $" IDENT_PA_VAMQP_H; +volatile const char * IDENT_AMQP_C="$Id: amqp.C,v 1.12 2026/01/09 03:36:59 moko Exp $" IDENT_PA_VAMQP_H; class MAmqp: public Methoded { public: // VStateless_class @@ -398,7 +398,7 @@ static void _declare(Request& r, MethodP const char* exchange_c = 0; const char* queue_c = 0; const char* type_c = "direct"; - bool passive=false, durable=false, auto_delete=true, nowait=false; + bool passive=false, durable=false, auto_delete=false, internal=false, exclusive=false; if(HashStringValue* options=params.as_hash(0)){ for(HashStringValue::Iterator i(*options); i; i.next()){ String::Body key=i.key(); @@ -415,8 +415,10 @@ static void _declare(Request& r, MethodP durable=r.process(*value).as_bool(); } else if(key=="auto_delete"){ auto_delete=r.process(*value).as_bool(); - } else if(key=="nowait"){ - nowait=r.process(*value).as_bool(); + } else if(key=="internal"){ + internal=r.process(*value).as_bool(); + } else if(key=="exclusive"){ + exclusive=r.process(*value).as_bool(); } else throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } @@ -425,12 +427,12 @@ static void _declare(Request& r, MethodP throw Exception("amqp", 0, "exchange or queue must be specified"); if(exchange_c){ - amqp_exchange_declare(self.connection(), self.channel(), amqp_cstring_bytes(exchange_c), amqp_cstring_bytes(type_c), passive, durable, auto_delete, nowait, amqp_empty_table); + amqp_exchange_declare(self.connection(), self.channel(), amqp_cstring_bytes(exchange_c), amqp_cstring_bytes(type_c), passive, durable, auto_delete, internal, amqp_empty_table); check(amqp_get_rpc_reply(self.connection())); } if(queue_c){ - amqp_queue_declare_ok_t *ok = amqp_queue_declare(self.connection(), self.channel(), *queue_c ? amqp_cstring_bytes(queue_c) : amqp_empty_bytes, passive, durable, auto_delete, nowait, amqp_empty_table); + amqp_queue_declare_ok_t *ok = amqp_queue_declare(self.connection(), self.channel(), *queue_c ? amqp_cstring_bytes(queue_c) : amqp_empty_bytes, passive, durable, exclusive, auto_delete, amqp_empty_table); check(amqp_get_rpc_reply(self.connection())); if(!*queue_c && ok){ r.write(*AMQP_STRING(ok->queue.bytes, ok->queue.len)); @@ -442,7 +444,7 @@ static void _delete(Request& r, MethodPa VAmqp& self=GET_SELF(r, VAmqp); const char* exchange_c = 0; const char* queue_c = 0; - bool if_unused=false, if_empty=false, nowait=false; + bool if_unused=false, if_empty=false; if(HashStringValue* options=params.as_hash(0)){ for(HashStringValue::Iterator i(*options); i; i.next()){ String::Body key=i.key(); @@ -455,8 +457,6 @@ static void _delete(Request& r, MethodPa if_unused=r.process(*value).as_bool(); } else if(key=="if_empty"){ if_empty=r.process(*value).as_bool(); - } else if(key=="nowait"){ - nowait=r.process(*value).as_bool(); } else throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } @@ -539,8 +539,9 @@ static void _purge(Request& r, MethodPar if(!queue_c) throw Exception("amqp", 0, "queue must be specified"); - amqp_queue_purge(self.connection(), self.channel(), amqp_cstring_bytes(queue_c)); + amqp_queue_purge_ok_t *ok = amqp_queue_purge(self.connection(), self.channel(), amqp_cstring_bytes(queue_c)); check(amqp_get_rpc_reply(self.connection())); + r.write(*new VInt(ok ? ok->message_count : 0)); } static void _info(Request& r, MethodParams& params) { @@ -566,9 +567,11 @@ static void _info(Request& r, MethodPara check(amqp_get_rpc_reply(self.connection())); Value& result=*new VHash; - result.put_element(*new String("queue"), AMQP_VSTRING(ok->queue.bytes, ok->queue.len)); - result.put_element(*new String("messages"), new VInt(ok->message_count)); - result.put_element(*new String("consumers"), new VInt(ok->consumer_count)); + if(ok){ + result.put_element(*new String("queue"), AMQP_VSTRING(ok->queue.bytes, ok->queue.len)); + result.put_element(*new String("messages"), new VInt(ok->message_count)); + result.put_element(*new String("consumers"), new VInt(ok->consumer_count)); + } r.write(result); } @@ -586,7 +589,7 @@ static void _consume(Request& r, MethodP VAmqp& self=GET_SELF(r, VAmqp); const char* queue_c=0; const char* consumer_tag_c=0; - bool no_ack=true, nowait=false; + bool no_ack=true, exclusive=false; int count=1; Junction* callback=0; @@ -602,8 +605,8 @@ static void _consume(Request& r, MethodP consumer_tag_c=value->as_string().cstr(); } else if(key=="no_ack"){ no_ack=r.process(*value).as_bool(); - } else if(key=="nowait"){ - nowait=r.process(*value).as_bool(); + } else if(key=="exclusive"){ + exclusive=r.process(*value).as_bool(); } else if(key=="count"){ count=r.process(*value).as_int(); } else @@ -613,9 +616,9 @@ static void _consume(Request& r, MethodP if(!queue_c) throw Exception("amqp", 0, "queue must be specified"); - amqp_basic_consume(self.connection(), self.channel(), amqp_cstring_bytes(queue_c), + amqp_basic_consume_ok_t *ok = amqp_basic_consume(self.connection(), self.channel(), amqp_cstring_bytes(queue_c), consumer_tag_c ? amqp_cstring_bytes(consumer_tag_c) : amqp_empty_bytes, - 0 /*no_local*/, no_ack, nowait, amqp_empty_table); + 0 /*no_local*/, no_ack, exclusive, amqp_empty_table); check(amqp_get_rpc_reply(self.connection())); if(callback){ @@ -657,6 +660,11 @@ static void _consume(Request& r, MethodP } r.write(result); } + + if(ok){ + amqp_basic_cancel(self.connection(), self.channel(), ok->consumer_tag); + check(amqp_get_rpc_reply(self.connection())); + } } static void _stop_consume(Request& r, MethodParams&) {