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 --- .hgignore | 2 ++ examples/Makefile.am | 5 ++++- examples/amqp_bind.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ examples/amqp_unbind.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ librabbitmq/amqp.h | 7 +++++++ librabbitmq/amqp_api.c | 14 +++++++++++++ 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 examples/amqp_bind.c create mode 100644 examples/amqp_unbind.c diff --git a/.hgignore b/.hgignore index 325dba1..bcc9d8c 100644 --- a/.hgignore +++ b/.hgignore @@ -25,3 +25,5 @@ ^examples/amqp_listen$ ^examples/amqp_producer$ ^examples/amqp_consumer$ +^examples/amqp_unbind$ +^examples/amqp_bind$ 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; +} diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h index d485093..563c429 100644 --- a/librabbitmq/amqp.h +++ b/librabbitmq/amqp.h @@ -254,6 +254,13 @@ extern struct amqp_queue_bind_ok_t_ *amqp_queue_bind(amqp_connection_state_t sta amqp_bytes_t routing_key, amqp_table_t arguments); +extern struct amqp_queue_unbind_ok_t_ *amqp_queue_unbind(amqp_connection_state_t state, + amqp_channel_t channel, + amqp_bytes_t queue, + amqp_bytes_t exchange, + amqp_bytes_t binding_key, + amqp_table_t arguments); + extern struct amqp_basic_consume_ok_t_ *amqp_basic_consume(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index 476cb2d..b5c9007 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -155,6 +155,20 @@ amqp_queue_bind_ok_t *amqp_queue_bind(amqp_connection_state_t state, return RPC_REPLY(amqp_queue_bind_ok_t); } +amqp_queue_unbind_ok_t *amqp_queue_unbind(amqp_connection_state_t state, + amqp_channel_t channel, + amqp_bytes_t queue, + amqp_bytes_t exchange, + amqp_bytes_t binding_key, + amqp_table_t arguments) +{ + amqp_rpc_reply = + AMQP_SIMPLE_RPC(state, channel, QUEUE, UNBIND, UNBIND_OK, + amqp_queue_unbind_t, + 0, queue, exchange, binding_key, arguments); + return RPC_REPLY(amqp_queue_unbind_ok_t); +} + amqp_basic_consume_ok_t *amqp_basic_consume(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, -- cgit v1.2.1