From af9315c575b8788b28bb3c5d959a9462b12b9a15 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 25 Apr 2009 22:11:44 +0100 Subject: More work --- examples/amqp_sendstring.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/amqp_sendstring.c b/examples/amqp_sendstring.c index 9258f7f..bdf4285 100644 --- a/examples/amqp_sendstring.c +++ b/examples/amqp_sendstring.c @@ -3,10 +3,52 @@ #include #include -#include "amqp.h" +#include + +#include + +static void die_on_error(int x, char const *context) { + if (x < 0) { + fprintf(stderr, "%s: %s\n", context, strerror(-x)); + exit(1); + } +} int main(int argc, char const * const *argv) { - amqp_connection_state_t conn = amqp_new_connection(); + char const *hostname; + int port; + char const *exchange; + char const *routingkey; + char const *messagebody; + + int sockfd; + amqp_connection_state_t conn; + + if (argc < 6) { + fprintf(stderr, "Usage: amqp_sendstring host port exchange routingkey messagebody\n"); + return 1; + } + + hostname = argv[1]; + port = atoi(argv[2]); + exchange = argv[3]; + routingkey = argv[4]; + messagebody = argv[5]; + + die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); + amqp_send_header((amqp_writer_fun_t) write, sockfd); + + conn = amqp_new_connection(); + + while (1) { + amqp_frame_t frame; + printf("Result %d\n", amqp_simple_wait_frame(conn, sockfd, &frame)); + printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); + } + amqp_destroy_connection(conn); + + die_on_error(close(sockfd), "Closing socket"); + return 0; } -- cgit v1.2.1