[rabbitmq-discuss] rabbitmq-c should I start a thread for amqp_simple_wait_frame() to get mesage?

3k4b251 314992959 at qq.com
Tue Jul 2 03:38:46 BST 2013


for  example.   here  is   a    simple   receive server  code.

//connection
amqp_connection_state_t    conn  =   amqp_new_connection(); 

//socket 
amqp_socket_t *socket  = amqp_tcp_socket_new();

//login
amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest",
"guest")

//open socket
amqp_socket_open(socket, hostname, port)

//set soket for connection
amqp_set_socket(conn, socket);




//after  link  to  rabbitmq server. we  start  to  listen  to the  queue   
consumer_1



//open  one  channel       one question:  why we need channel....  
amqp_channel_open(conn, 1);

//declare queue  "test_1"   .   I   usually try to  declare  queue  before  
declare consumer   to make sure the queue  already  be  there.

amqp_queue_declare(conn,1,amqp_cstring_bytes("consumer_1"),0,0,0,1,amqp_empty_table);

//request  consume
amqp_basic_consume(conn, 1, amqp_cstring_bytes("consumer_1"), 
amqp_cstring_bytes("consumer_1"),  0, 1, 0, amqp_empty_table);

// now  I  will  try  to receive  message 
while(1)
{
amqp_frame_t frame;
amqp_simple_wait_frame(conn,&frame);
.........................
........................
...................
}

//So   when  the  client  send  message  to  the  queue   "consumer_1",  I
will   receive  the message. And if there  is no message,  it will block  at
amqp_simple_wait_frame();  


//but  what  I want to do  in  online server is that   one  consumer 
login,I  create a  queue  "consumer_1"  for him,  and  request queue
listener  by  amqp_basic_consume().  when  the consumer quit, I  want  to  
remove  the listener  by amqp_basic_cancel().    but  I can't  do this  in 
the simple  example.  I  will  block  in  the amqp_simple_wait_frame(). I
could  just  wait  the someone  send  message to queue "consumer_1"So  I try 
to  start    thread  for   message receving.  if  I do  like  this, I share
connection in two  threads.   I feel very confused .........



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/rabbitmq-c-should-I-start-a-thread-for-amqp-simple-wait-frame-to-get-mesage-tp27666p27729.html
Sent from the RabbitMQ mailing list archive at Nabble.com.


More information about the rabbitmq-discuss mailing list