--- parser3/src/classes/amqp.C 2026/01/08 15:45:25 1.8 +++ parser3/src/classes/amqp.C 2026/01/09 03:19:37 1.10 @@ -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.10 2026/01/09 03:19:37 moko Exp $" IDENT_PA_VAMQP_H; class MAmqp: public Methoded { public: // VStateless_class @@ -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&) {