Hi,<br><br>I am very new to RabbitMQ. we are using Rabbit MQ C API to talk with the broker.<br>We are playing with the examples(with few modifications) given by RabbitMQ. <br>We created one producer and one consumer with the same connection but difference channels.<br>

In the following code amqp_channel_open(conn, 2) statement is causing the my main thread to block <br>but if i move this statement before creating of consumer thread then every thing seems to be working.<br><br>My code is as follows.<br>

static void send_batch(amqp_connection_<div id=":aj" class="ii gt">state_t conn,<br>���������������������� char const *queue_name,<br>���������������������� int rate_limit,<br>���������������������� int message_count)<br>
{<br>� char message[256] = &quot;test&quot;;<br>
� die_on_error(amqp_basic_publish(conn,<br>����������������������������������� 2,<br>����������������������������������� amqp_cstring_bytes(&quot;amq.direct&quot;),<br>����������������������������������� amqp_cstring_bytes(queue_name),<br>

����������������������������������� 0,<br>����������������������������������� 0,<br>����������������������������������� NULL,<br>����������������������������������� (amqp_bytes_t) {.len = sizeof(message), .bytes = message}),<br>

���������������� &quot;Publishing&quot;);<br>��� printf(&quot;Message sent by producer\n&quot;);<br>}<br><br>static void run(amqp_connection_state_t conn)<br>{<br>� amqp_frame_t frame;<br>� int result;<br>� size_t body_received;<br>

� size_t body_target;<br>� int� received = 0;��� <br>� while (1) {<br>��� amqp_maybe_release_buffers(conn);<br>��� result = amqp_simple_wait_frame(conn, &amp;frame);<br>��� if (result &lt;= 0) return;<br>��� if (frame.frame_type != AMQP_FRAME_METHOD)<br>

����� continue;<br>��� if (<a href="http://frame.payload.method.id/" target="_blank">frame.payload.method.id</a> != AMQP_BASIC_DELIVER_METHOD)<br>����� continue;<br>��� result = amqp_simple_wait_frame(conn, &amp;frame);<br>
��� if (result &lt;= 0) return;<br>
��� if (frame.frame_type != AMQP_FRAME_HEADER) {<br>����� abort();<br>��� }<br>��� body_target = frame.payload.properties.body_size;<br>��� body_received = 0;<br>��� while (body_received &lt; body_target) {<br>����� result = amqp_simple_wait_frame(conn, &amp;frame);<br>

����� if (result &lt;= 0) return;<br>����� if (frame.frame_type != AMQP_FRAME_BODY) {<br>��� abort();<br>����� }<br>����� body_received += frame.payload.body_fragment.len;<br>����� assert(body_received &lt;= body_target);<br>

��� }<br>��� received++;<br>��� printf(&quot;received=%d\n&quot;,received);<br>� }<br>}<br>void*� consume(void* conn){<br>� run(*((amqp_connection_state_t*)conn));<br>}<br>int main(int argc, char const * const *argv) {<br>

� char const *hostname=&quot;127.0.0.1&quot;;<br>� int port=&quot;5672&quot;;<br>� char const *exchange;<br>� char const *bindingkey;<br>� int sockfd;<br>� amqp_connection_state_t conn;<br>� amqp_bytes_t queuename;<br>� exchange = &quot;amq.direct&quot;; //argv[3];<br>

� bindingkey = &quot;test queue&quot;; //argv[4];<br>� int rate_limit = 100;<br>� int message_count = 10000;<br>� conn = amqp_new_connection();<br>� die_on_error(sockfd = amqp_open_socket(hostname, port), &quot;Opening socket&quot;);<br>

� amqp_set_sockfd(conn, sockfd);<br>� die_on_amqp_error(amqp_login(conn, &quot;/&quot;, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, &quot;guest&quot;, &quot;guest&quot;),<br>��� ��� ��� &quot;Logging in&quot;);<br>� amqp_channel_open(conn, 1);<br>

� die_on_amqp_error(amqp_rpc_reply, &quot;Opening channel&quot;);<br>� {<br>��� amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, AMQP_EMPTY_BYTES, 0, 0, 0, 1,<br>��� ��� ��� ��� ��� ��� ��� AMQP_EMPTY_TABLE);<br>
��� die_on_amqp_error(amqp_rpc_reply, &quot;Declaring queue&quot;);<br>
��� queuename = amqp_bytes_malloc_dup(r-&gt;queue);<br>��� if (queuename.bytes == NULL) {<br>����� die_on_error(-ENOMEM, &quot;Copying queue name&quot;);<br>��� }<br>� }<br>� amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey),<br>

��� ��� � AMQP_EMPTY_TABLE);<br>� die_on_amqp_error(amqp_rpc_reply, &quot;Binding queue&quot;);<br><br>� amqp_basic_consume(conn, 1, queuename, AMQP_EMPTY_BYTES, 0, 1, 0);<br>� die_on_amqp_error(amqp_rpc_reply, &quot;Consuming&quot;);<br>

� pthread_t threadId;<br>� pthread_create(&amp;threadId,NULL,consume,(void*)&amp;conn);<br>� sleep(1);<br>� amqp_channel_open(conn, 2);<br>� send_batch(conn, &quot;test queue&quot;, rate_limit, message_count);<br>� die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), &quot;Closing channel&quot;);<br>

� die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), &quot;Closing connection&quot;);<br>� amqp_destroy_connection(conn);<br>� die_on_error(close(sockfd), &quot;Closing socket&quot;);<br>� return 0;<br>}<br>

<br>Please provide me the reasons for blocking.<br><br>Thanks,<br>Ragavendra.<br>
</div>