diff options
author | Tony Garnock-Jones <tonyg@lshift.net> | 2009-05-18 15:24:55 +0100 |
---|---|---|
committer | Tony Garnock-Jones <tonyg@lshift.net> | 2009-05-18 15:24:55 +0100 |
commit | 95541b1b764510db98df07656ce0d3bda5917754 (patch) | |
tree | 1f413886ebafdce3ef42ad85d718e4271552b5c4 /examples/amqp_bind.c | |
parent | aabfa202da960cb782cf7c0b90a54cee5969e1fb (diff) | |
download | rabbitmq-c-github-ask-95541b1b764510db98df07656ce0d3bda5917754.tar.gz |
Add bind/unbind utilities, and API for unbind
Diffstat (limited to 'examples/amqp_bind.c')
-rw-r--r-- | examples/amqp_bind.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/amqp_bind.c b/examples/amqp_bind.c new file mode 100644 index 0000000..1d3055b --- /dev/null +++ b/examples/amqp_bind.c @@ -0,0 +1,55 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <stdint.h> +#include <amqp.h> +#include <amqp_framing.h> + +#include <unistd.h> + +#include "example_utils.h" + +int main(int argc, char const * const *argv) { + char const *hostname; + int port; + char const *exchange; + char const *bindingkey; + char const *queue; + + int sockfd; + amqp_connection_state_t conn; + + if (argc < 6) { + fprintf(stderr, "Usage: amqp_bind host port exchange bindingkey queue\n"); + return 1; + } + + hostname = argv[1]; + port = atoi(argv[2]); + exchange = argv[3]; + bindingkey = argv[4]; + queue = argv[5]; + + conn = amqp_new_connection(); + + die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); + amqp_set_sockfd(conn, sockfd); + die_on_amqp_error(amqp_login(conn, "/", 0, 131072, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), + "Logging in"); + amqp_channel_open(conn, 1); + die_on_amqp_error(amqp_rpc_reply, "Opening channel"); + + amqp_queue_bind(conn, 1, + amqp_cstring_bytes(queue), + amqp_cstring_bytes(exchange), + amqp_cstring_bytes(bindingkey), + AMQP_EMPTY_TABLE); + die_on_amqp_error(amqp_rpc_reply, "Unbinding"); + + die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); + die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); + amqp_destroy_connection(conn); + die_on_error(close(sockfd), "Closing socket"); + return 0; +} |