From 5929e7cc940c2c43ae3b2e37ead5aa2145da05a4 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Sat, 7 Aug 2010 19:16:02 +0100 Subject: make distcheck was failing because of a missing $(srcdir) relative-reference --- tools/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index ef7a9bc..ccd36ca 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS=doc bin_PROGRAMS = amqp-publish amqp-get amqp-consume amqp-declare-queue amqp-delete-queue -AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(PLATFORM_DIR) +AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(srcdir)/$(PLATFORM_DIR) AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la LDADD=$(LIBPOPT) -- cgit v1.2.1 From 0a7540f14ce26b9c1f6fba4996c8096cfdce4890 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Sun, 8 Aug 2010 00:11:43 +0100 Subject: Refine amqp-consume options for 0-9-1 queue declaration semantics --- tools/consume.c | 90 +++++++++++++++++++++------------------------------ tools/doc/consume.xml | 58 +++++++++++++++++---------------- 2 files changed, 67 insertions(+), 81 deletions(-) (limited to 'tools') diff --git a/tools/consume.c b/tools/consume.c index 2117bba..a641708 100644 --- a/tools/consume.c +++ b/tools/consume.c @@ -84,61 +84,45 @@ static char *stringify_bytes(amqp_bytes_t bytes) static amqp_bytes_t setup_queue(amqp_connection_state_t conn, char *queue, char *exchange, - char *exchange_type, char *routing_key) + char *routing_key, int declare) { - amqp_bytes_t queue_bytes; - amqp_queue_declare_ok_t *res; + amqp_bytes_t queue_bytes = cstring_bytes(queue); /* if an exchange name wasn't provided, check that we don't have options that require it. */ - if (!exchange) { - char *opt = NULL; - if (routing_key) - opt = "--routing-key"; - else if (exchange_type) - opt = "--exchange-type"; - - if (opt) { - fprintf(stderr, - "%s option requires an exchange name to be " - "provided with --exchange\n", opt); - exit(1); - } + if (!exchange && routing_key) { + fprintf(stderr, "--routing-key option requires an exchange" + " name to be provided with --exchange\n"); + exit(1); } - /* Declare the queue as auto-delete. If the queue already - exists, this won't have any effect. */ - queue_bytes = cstring_bytes(queue); - res = amqp_queue_declare(conn, 1, queue_bytes, 0, 0, 0, 1, - AMQP_EMPTY_TABLE); - if (!res) - die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); - - if (!queue) { - /* the server should have provided a queue name */ - char *sq; - queue_bytes = amqp_bytes_malloc_dup(res->queue); - sq = stringify_bytes(queue_bytes); - fprintf(stderr, "Server provided queue name: %s\n", sq); - free(sq); - } + if (!queue || exchange || declare) { + /* Declare the queue as auto-delete. */ + amqp_queue_declare_ok_t *res = amqp_queue_declare(conn, 1, + queue_bytes, 0, 0, 1, 1, + AMQP_EMPTY_TABLE); + if (!res) + die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); + + if (!queue) { + /* the server should have provided a queue name */ + char *sq; + queue_bytes = amqp_bytes_malloc_dup(res->queue); + sq = stringify_bytes(queue_bytes); + fprintf(stderr, "Server provided queue name: %s\n", + sq); + free(sq); + } - /* Bind to an exchange if requested */ - if (exchange) { - amqp_bytes_t eb = amqp_cstring_bytes(exchange); - - if (exchange_type) { - /* we should create the exchange */ - if (!amqp_exchange_declare(conn, 1, eb, - amqp_cstring_bytes(exchange_type), - 0, 0, 1, AMQP_EMPTY_TABLE)) - die_rpc(amqp_get_rpc_reply(conn), "exchange.declare"); + /* Bind to an exchange if requested */ + if (exchange) { + amqp_bytes_t eb = amqp_cstring_bytes(exchange); + if (!amqp_queue_bind(conn, 1, queue_bytes, eb, + cstring_bytes(routing_key), + AMQP_EMPTY_TABLE)) + die_rpc(amqp_get_rpc_reply(conn), + "queue.bind"); } - - if (!amqp_queue_bind(conn, 1, queue_bytes, eb, - cstring_bytes(routing_key), - AMQP_EMPTY_TABLE)) - die_rpc(amqp_get_rpc_reply(conn), "queue.bind"); } return queue_bytes; @@ -181,13 +165,13 @@ static void do_consume(amqp_connection_state_t conn, amqp_bytes_t queue, int main(int argc, const char **argv) { poptContext opts; - int no_ack; amqp_connection_state_t conn; const char * const *cmd_argv; char *queue = NULL; char *exchange = NULL; - char *exchange_type = NULL; char *routing_key = NULL; + int declare; + int no_ack; amqp_bytes_t queue_bytes; struct poptOption options[] = { @@ -196,11 +180,10 @@ int main(int argc, const char **argv) "the queue to consume from", "queue"}, {"exchange", 'e', POPT_ARG_STRING, &exchange, 0, "bind the queue to this exchange", "exchange"}, - {"exchange-type", 't', POPT_ARG_STRING, &exchange_type, 0, - "create auto-delete exchange of this type for binding", - "type"}, {"routing-key", 'r', POPT_ARG_STRING, &routing_key, 0, "the routing key to bind with", "routing key"}, + {"declare", 'd', POPT_ARG_NONE, &declare, 0, + "declare an exclusive queue", NULL}, {"no-ack", 'A', POPT_ARG_NONE, &no_ack, 0, "consume in no-ack mode", NULL}, POPT_AUTOHELP @@ -218,8 +201,7 @@ int main(int argc, const char **argv) } conn = make_connection(); - queue_bytes = setup_queue(conn, queue, exchange, exchange_type, - routing_key); + queue_bytes = setup_queue(conn, queue, exchange, routing_key, declare); do_consume(conn, queue_bytes, no_ack, cmd_argv); close_connection(conn); return 0; diff --git a/tools/doc/consume.xml b/tools/doc/consume.xml index 448ade6..16d61ad 100644 --- a/tools/doc/consume.xml +++ b/tools/doc/consume.xml @@ -50,8 +50,7 @@ amqp-consume can consume from an existing queue, or it can create a new queue. It can - optionally bind the queue to an existing exchange, or to a - newly created exchange. + optionally bind the queue to an existing exchange. By default, messages will be consumed with explicit @@ -72,13 +71,16 @@ The name of the queue to consume messages - from. If the specified queue does not exist, - an auto-delete queue is created with the given - name. If this option is omitted, a new - auto-delete queue will be created, with a - unique name assigned to the queue by the AMQP - server; that unique name will be displayed on - stderr. + from. + + + + If the option is + omitted, the AMQP server will assign a unique + name to the queue, and that server-assigned + name will be dixsplayed on stderr; this case + implies that an exclusive queue should be + declared. @@ -87,34 +89,36 @@ =exchange name - The name of the exchange to bind the queue to. - If omitted, binding is not performed. The - specified exchange should already exist unless - the option is - used to request the creation of an exchange. + Specifies that an exclusive queue should + be declared, and bound to the given exchange. + The specified exchange should already exist + unless the + option is used to request the creation of an + exchange. - - =type + + =routing key - This option indicates that an auto-delete - exchange of the specified type should be - created. The name of the exchange should be - given by the - option. + The routing key for binding. If omitted, an + empty routing key is assumed. - - =routing key + + - The routing key for the binding. If omitted, - an empty routing key is assumed. + Forces an exclusive queue to be declared, + even when it otherwise would not. That is, + when a queue name is specified with the + option, but no + binding to an exchange is requested with the + option. @@ -138,7 +142,7 @@ Examples - Consume messages from the queue + Consume messages from an existing queue myqueue, and output the message bodies on standard output via @@ -149,7 +153,7 @@ - Bind a newly created auto-delete queue to an + Bind a new exclusive queue to an exchange myexch, and send each message body to the script -- cgit v1.2.1 From 55a5ffa8b12a5b1de877e820786be814131340e6 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Mon, 9 Aug 2010 17:30:09 +0100 Subject: add missing initializers --- tools/consume.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/consume.c b/tools/consume.c index a641708..943406b 100644 --- a/tools/consume.c +++ b/tools/consume.c @@ -170,8 +170,8 @@ int main(int argc, const char **argv) char *queue = NULL; char *exchange = NULL; char *routing_key = NULL; - int declare; - int no_ack; + int declare = 0; + int no_ack = 0; amqp_bytes_t queue_bytes; struct poptOption options[] = { -- cgit v1.2.1