diff options
author | Tony Garnock-Jones <tonyg@kcbbs.gen.nz> | 2009-04-25 22:11:44 +0100 |
---|---|---|
committer | Tony Garnock-Jones <tonyg@kcbbs.gen.nz> | 2009-04-25 22:11:44 +0100 |
commit | af9315c575b8788b28bb3c5d959a9462b12b9a15 (patch) | |
tree | 615ddf61ed58796bcbeb32dc9165f9c2fd925582 /examples | |
parent | 67970c9c56ebd49b57e61d50255b04fa1ac7d27d (diff) | |
download | rabbitmq-c-github-ask-af9315c575b8788b28bb3c5d959a9462b12b9a15.tar.gz |
More work
Diffstat (limited to 'examples')
-rw-r--r-- | examples/amqp_sendstring.c | 46 |
1 files changed, 44 insertions, 2 deletions
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 <string.h> #include <stdint.h> -#include "amqp.h" +#include <amqp.h> + +#include <unistd.h> + +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; } |