<div dir="ltr">If you REALLY need to know the number of messages in a queue: the queue.declare method returns a queue.declare-ok which includes a message-count field - which will tell you the number of messages in a queue. Keep in mind this involves a round-trip to the broker and is worse for efficiency than polling with basic.get, if all you want to do is grab a message when it becomes available. If you'd like to do just that use basic.consume.<br>
<div><br></div><div>-Alan</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Dec 13, 2013 at 8:08 AM, kingsmasher1 <span dir="ltr"><<a href="mailto:raj.kumar.sanpui@gmail.com" target="_blank">raj.kumar.sanpui@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks a lot for the reply Alan.<br>
Seems like i made some basic mistake, my bindQueue happened inside the<br>
consume method, and i was planning to call consume only after the "select(<br>
)" validation, so that might be the reason as you suggested that the<br>
messages are dropped.<br>
<br>
In betwn. here is the functions we use, it's from an already-existing old<br>
code, which does not have "message in queue or not" validation, which i am<br>
trying to add.<br>
<br>
#define EXCHANGE "topicex"<br>
#define QUEUETYPE "topic"<br>
#define ROUTINGKEY "pname"<br>
#define QUEUENAME "MyprefetchQ"<br>
<br>
<br>
void createPrefetchQueue(void) {<br>
<div class="im"> amqConnection *conn = util.getAMQConnection ();<br>
</div><div class="im"> int rc = conn->declareExchange(EXCHANGE, QUEUETYPE, 1);<br>
if (rc != 0) {<br>
ErrLog("%s() - declare exchange %s %s failed\n",<br>
__FUNCTION__, EXCHANGE, QUEUETYPE);<br>
util.returnAMQConnection(conn);<br>
pthread_exit(0) ;<br>
}<br>
</div> // Create my prefetch queue<br>
rc = conn->createQueue(QUEUENAME, 0, 1, 1, 0);<br>
<br>
if (rc != 0) {<br>
ErrLog("%s() - create MyprefetchQ %s failed\n", __FUNCTION__,<br>
QUEUENAME);<br>
util.returnAMQConnection(conn);<br>
pthread_exit(0) ;<br>
}<br>
}<br>
<br>
int amqConnection::createQueue(std::string queue, int passive, int durable,<br>
int exclusive, int autoDelete){<br>
Debug("%s - Create queue %s \n", __FUNCTION__, queue.c_str());<br>
/*<br>
amqp_queue_declare(amqp_connection_state_t state, amqp_channel_t channel,<br>
amqp_bytes_t queue, amqp_boolean_t passive, amqp_boolean_t durable,<br>
amqp_boolean_t exclusive, amqp_boolean_t auto_delete, amqp_table_t<br>
arguments)<br>
*/<br>
int channel=1;<br>
amqp_queue_declare(conn, channel, amqp_cstring_bytes(queue.c_str()), 0<br>
, 0, 0, 1, amqp_empty_table);<br>
amqp_rpc_reply_t res = amqp_get_rpc_reply(conn);<br>
return check_amqp_error(res, "create queue");<br>
<br>
}<br>
<br>
Binding:<br>
int amqConnection::bindQueue(const char* queue, const char* exchange, const<br>
char* bindingkey) {<br>
Debug("%s() - %s %s\n", __FUNCTION__, queue, exchange, bindingkey);<br>
amqp_queue_bind(conn, 1,<br>
amqp_cstring_bytes(queue),<br>
amqp_cstring_bytes(exchange),<br>
amqp_cstring_bytes(bindingkey),<br>
amqp_empty_table);<br>
<br>
amqp_rpc_reply_t res = amqp_get_rpc_reply(conn);<br>
return check_amqp_error(res, "bind queue");<br>
}<br>
<br>
<br>
std::string amqConnection::consume(amqp_bytes_t queuename, std::string<br>
exchange, std::string routingkey) {<br>
Debug("%s q %s ex %s rk %s- \n", __FUNCTION__, (char*)queuename.bytes,<br>
exchange.c_str(), routingkey.c_str());<br>
<br>
if (exchange.length() > 0) bindQueue(queuename, exchange.c_str(),<br>
routingkey.c_str());<br>
<br>
<snip><br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://rabbitmq.1065348.n5.nabble.com/Why-is-the-select-always-getting-timed-out-in-consumer-tp32046p32073.html" target="_blank">http://rabbitmq.1065348.n5.nabble.com/Why-is-the-select-always-getting-timed-out-in-consumer-tp32046p32073.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the RabbitMQ mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
</div></div></blockquote></div><br></div>