From 95541b1b764510db98df07656ce0d3bda5917754 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 18 May 2009 15:24:55 +0100 Subject: Add bind/unbind utilities, and API for unbind --- examples/Makefile.am | 5 ++++- examples/amqp_bind.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ examples/amqp_unbind.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 examples/amqp_bind.c create mode 100644 examples/amqp_unbind.c (limited to 'examples') diff --git a/examples/Makefile.am b/examples/Makefile.am index dbb7953..39c8fab 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,5 @@ -bin_PROGRAMS = amqp_sendstring amqp_exchange_declare amqp_listen amqp_producer amqp_consumer +bin_PROGRAMS = amqp_sendstring amqp_exchange_declare amqp_listen amqp_producer amqp_consumer \ + amqp_unbind amqp_bind AM_CFLAGS = -I../librabbitmq AM_LDFLAGS = ../librabbitmq/librabbitmq.la @@ -10,3 +11,5 @@ amqp_exchange_declare_SOURCES = amqp_exchange_declare.c example_utils.c amqp_listen_SOURCES = amqp_listen.c example_utils.c amqp_producer_SOURCES = amqp_producer.c example_utils.c amqp_consumer_SOURCES = amqp_consumer.c example_utils.c +amqp_unbind_SOURCES = amqp_unbind.c example_utils.c +amqp_bind_SOURCES = amqp_bind.c example_utils.c 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 +#include +#include + +#include +#include +#include + +#include + +#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; +} diff --git a/examples/amqp_unbind.c b/examples/amqp_unbind.c new file mode 100644 index 0000000..0677203 --- /dev/null +++ b/examples/amqp_unbind.c @@ -0,0 +1,55 @@ +#include +#include +#include + +#include +#include +#include + +#include + +#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_unbind 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_unbind(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; +} -- cgit v1.2.1