[rabbitmq-discuss] Simple C Client to read from a Queue

Tim Watson tim at rabbitmq.com
Fri Sep 7 09:31:42 BST 2012


On 09/07/2012 08:11 AM, Sajith Kariyawasam wrote:
> Thanks for the clue,
> I tried using it with following code,
>   die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening 
> socket");
>   conn = amqp_new_connection();
>   amqp_set_sockfd(conn, sockfd);
>   die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, 
> AMQP_SASL_METHOD_PLAIN, "guest", "guest"),"Logging in");
>   if (!amqp_channel_open(conn, 1))
>                 die_on_amqp_error(amqp_get_rpc_reply(conn), "opening 
> channel");
>   reply =  amqp_basic_get(conn,1,amqp_cstring_bytes(queuename),1);

I don't actually know this library at all (apart from glancing at it a 
couple of times) but this generally looks fine. From the examples I note 
that most invocations of 
'die_on_amqp_error(amqp_get_rpc_reply(conn)....' occur regardless of the 
return value of amqp_channel_open, but apart from that you appear to be 
following the same sequence as the examples/tools do.

More information about the rabbitmq-discuss mailing list