<div dir="ltr">Ok, now I have a better understanding of what you're trying to accomplish.<div><br></div><div style>First a bit of a warning: as you've already noticed, the rabbitmq-c API doesn't lend itself to doing RPC-style commands (such as amqp_basic_consume, or amqp_queue_declare, etc) while waiting on a message to be delivered with amqp_simple_wait_frame(). So the following solutions won't be the most natural solutions out there, they may also may suffer from performance issues. If these solutions don't work for you - I would encourage you to explore using other RabbitMQ clients.</div>
<div style><br></div><div style><br></div><div style>My first suggestion would be to declare a command queue on the broker and have your message reading thread consume from that command queue. When a user logs into the chat, using a different connection publish a message to that command queue "start consuming from queue X". Your message reading thread should then read that message, then create the consumer, and go back to waiting for messages. You could use a similar process to stop a consumer.</div>
<div style><br></div><div style>The upside is this is fairly easy to implement, the downside (and you would need to do some performance testing) is that there is a certain cost for having the message go to the broker and back, also if your message reading thread is consuming a lot of messages from different consumers, there could be a significant delay between the time you send the message from one thread, and the time the message is received in your message reading thread.</div>
<div style><br></div><div style><br></div><div style>My second suggestion would be to create a pipe (<a href="http://linux.die.net/man/7/pipe">http://linux.die.net/man/7/pipe</a>) and before the first amqp_simple_wait_frame() call, extract the socket fd from the amqp_connection_state_t with amqp_get_sockfd() and do a select() call with both the read-end of the pipe and the socket fd. If the pipe can be read that will be the signal that a consumer should be started or stopped, otherwise a message should be read.</div>
<div style><br></div><div style>In the other thread, when a new user logs in write a command to the pipe indicating what other amqp commands the message reader thread should do (start or stop a consumer).</div><div style>
<br></div><div style>The upside is that this will likely be more performant than my first suggestion. The downside is that this is a fair bit more complicated in terms of programming effort, and understanding how pipes work, and outside of Linux i'm not 100% sure this will work (I know it will require a different approach on Win32).</div>
<div style><br></div><div style>HTH</div><div style>-Alan</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 2, 2013 at 8:51 PM, 3k4b251 <span dir="ltr"><<a href="mailto:314992959@qq.com" target="_blank">314992959@qq.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
1. 【 For example when a new person signs on to this chat, what happens on<br>
the broker? Do new queues get created? Do you start some consumer?】<br>
<br>
Re: when a new person login in the online server, the online Server<br>
ask rabbitmq-server to create a queue for him. and start a<br>
consumer for the queue. (if he already have the queue on mq server,<br>
the create fail, but we don't care about that. the only thing we care<br>
about is that when a new person login in ,there will be a queue<br>
server for him) every person only have one queue and one consumer<br>
for the queue in rabbitmq-server.<br>
<br>
<br>
<br>
2. 【When a person sends a message to another person over this chat what<br>
<div class="im">queues does it get routed to? How does the message get back to the<br>
</div>application the user is using.】<br>
<br>
Re: when he want to chart to another person A. he send message to A's<br>
only queue. and A may receive the message by him only consumer. if A want<br>
to reply to sender, he need to send message to sender's only queue. it's<br>
seems like email. maybe we need talk group, so I'd like to create<br>
exchange for talk group. we can bind the group memebers to a exchange. and<br>
send message to the exchange.<br>
<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://rabbitmq.1065348.n5.nabble.com/rabbitmq-c-should-I-start-a-thread-for-amqp-simple-wait-frame-to-get-mesage-tp27666p27760.html" target="_blank">http://rabbitmq.1065348.n5.nabble.com/rabbitmq-c-should-I-start-a-thread-for-amqp-simple-wait-frame-to-get-mesage-tp27666p27760.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>