summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am29
-rw-r--r--tools/common.c4
-rw-r--r--tools/common_consume.c160
-rw-r--r--tools/common_consume.h54
-rw-r--r--tools/consume.c119
-rw-r--r--tools/doc/consume.xml173
-rw-r--r--tools/doc/get.xml95
-rw-r--r--tools/doc/librabbitmq-tools.xml90
-rw-r--r--tools/doc/publish.xml160
-rw-r--r--tools/get.c16
-rw-r--r--tools/publish.c2
11 files changed, 669 insertions, 233 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 965e726..04397b2 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -5,10 +5,33 @@ AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la
LDADD=$(LIBPOPT)
-noinst_HEADERS = common.h common_consume.h
+noinst_HEADERS = common.h
amqp_publish_SOURCES = publish.c common.c
-amqp_get_SOURCES = get.c common.c common_consume.c
-amqp_consume_SOURCES = consume.c common.c common_consume.c
+amqp_get_SOURCES = get.c common.c
+amqp_consume_SOURCES = consume.c common.c
amqp_declare_queue_SOURCES = declare_queue.c common.c
amqp_delete_queue_SOURCES = delete_queue.c common.c
+
+if TOOLS_DOC
+man_MANS = doc/amqp-publish.1 doc/amqp-consume.1 doc/amqp-get.1 doc/librabbitmq-tools.7
+MOSTLYCLEANFILES = doc/man-date.ent
+
+# automake complains about % pattern rules, and suffix rules don't
+# support multiple dependencies, so we have to expand all these out.
+doc/amqp-publish.1: doc/publish.xml doc/man-date.ent
+ $(XMLTO) man -o doc $<
+doc/amqp-consume.1: doc/consume.xml doc/man-date.ent
+ $(XMLTO) man -o doc $<
+doc/amqp-get.1: doc/get.xml doc/man-date.ent
+ $(XMLTO) man -o doc $<
+doc/librabbitmq-tools.7: doc/librabbitmq-tools.xml doc/man-date.ent
+ $(XMLTO) man -o doc $<
+
+doc/man-date.ent:
+ date +'%Y-%m-%d' >$@
+
+clean::
+ rm -f doc/man-date.ent
+
+endif
diff --git a/tools/common.c b/tools/common.c
index 0772738..6a38a95 100644
--- a/tools/common.c
+++ b/tools/common.c
@@ -187,7 +187,7 @@ static char *amqp_password = "guest";
const char *connect_options_title = "Connection options";
struct poptOption connect_options[] = {
{"server", 's', POPT_ARG_STRING, &amqp_server, 0,
- "the AMQP server to connect to", "server"},
+ "the AMQP server to connect to", "hostname:port"},
{"vhost", 0, POPT_ARG_STRING, &amqp_vhost, 0,
"the vhost to use when connecting", "vhost"},
{"username", 0, POPT_ARG_STRING, &amqp_username, 0,
@@ -377,7 +377,7 @@ poptContext process_options(int argc, const char **argv,
poptSetOtherOptionHelp(opts, help);
while ((c = poptGetNextOpt(opts)) >= 0) {
- // no options require explicit handling
+ /* no options require explicit handling */
}
if (c < -1) {
diff --git a/tools/common_consume.c b/tools/common_consume.c
deleted file mode 100644
index 318fa2c..0000000
--- a/tools/common_consume.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and
- * limitations under the License.
- *
- * The Original Code is librabbitmq.
- *
- * The Initial Developers of the Original Code are LShift Ltd, Cohesive
- * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions
- * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive
- * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright
- * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and
- * Rabbit Technologies Ltd.
- *
- * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
- * Ltd. Portions created by Cohesive Financial Technologies LLC are
- * Copyright (C) 2007-2009 Cohesive Financial Technologies
- * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C)
- * 2007-2009 Rabbit Technologies Ltd.
- *
- * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010
- * LShift Ltd and Tony Garnock-Jones.
- *
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * Alternatively, the contents of this file may be used under the terms
- * of the GNU General Public License Version 2 or later (the "GPL"), in
- * which case the provisions of the GPL are applicable instead of those
- * above. If you wish to allow use of your version of this file only
- * under the terms of the GPL, and not to allow others to use your
- * version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the
- * notice and other provisions required by the GPL. If you do not
- * delete the provisions above, a recipient may use your version of
- * this file under the terms of any one of the MPL or the GPL.
- *
- * ***** END LICENSE BLOCK *****
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <popt.h>
-
-#include "common.h"
-
-static char *queue;
-static char *exchange;
-static char *exchange_type;
-static char *routing_key;
-
-const char *consume_queue_options_title = "Source queue options";
-struct poptOption consume_queue_options[] = {
- {"queue", 'q', POPT_ARG_STRING, &queue, 0,
- "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"},
- { NULL, 0, 0, NULL, 0 }
-};
-
-/* Convert a amqp_bytes_t to an escaped string form for printing. We
- use the same escaping conventions as rabbitmqctl. */
-static char *stringify_bytes(amqp_bytes_t bytes)
-{
- /* W will need up to 4 chars per byte, plus the terminating 0 */
- char *res = malloc(bytes.len * 4 + 1);
- uint8_t *data = bytes.bytes;
- char *p = res;
- size_t i;
-
- for (i = 0; i < bytes.len; i++) {
- if (data[i] >= 32 && data[i] != 127) {
- *p++ = data[i];
- }
- else {
- *p++ = '\\';
- *p++ = '0' + (data[i] >> 6);
- *p++ = '0' + (data[i] >> 3 & 0x7);
- *p++ = '0' + (data[i] & 0x7);
- }
- }
-
- *p = 0;
- return res;
-}
-
-amqp_bytes_t setup_queue(amqp_connection_state_t conn)
-{
- /* 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);
- }
- }
-
- /* Declare the queue. If the queue already exists, this won't have
- any effect. */
- amqp_bytes_t queue_bytes = cstring_bytes(queue);
- amqp_queue_declare_ok_t *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);
- }
-
- /* 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");
- }
-
- 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;
-}
diff --git a/tools/common_consume.h b/tools/common_consume.h
deleted file mode 100644
index 703f4bd..0000000
--- a/tools/common_consume.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and
- * limitations under the License.
- *
- * The Original Code is librabbitmq.
- *
- * The Initial Developers of the Original Code are LShift Ltd, Cohesive
- * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions
- * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive
- * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright
- * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and
- * Rabbit Technologies Ltd.
- *
- * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
- * Ltd. Portions created by Cohesive Financial Technologies LLC are
- * Copyright (C) 2007-2009 Cohesive Financial Technologies
- * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C)
- * 2007-2009 Rabbit Technologies Ltd.
- *
- * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010
- * LShift Ltd and Tony Garnock-Jones.
- *
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * Alternatively, the contents of this file may be used under the terms
- * of the GNU General Public License Version 2 or later (the "GPL"), in
- * which case the provisions of the GPL are applicable instead of those
- * above. If you wish to allow use of your version of this file only
- * under the terms of the GPL, and not to allow others to use your
- * version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the
- * notice and other provisions required by the GPL. If you do not
- * delete the provisions above, a recipient may use your version of
- * this file under the terms of any one of the MPL or the GPL.
- *
- * ***** END LICENSE BLOCK *****
- */
-
-extern const char *consume_queue_options_title;
-extern struct poptOption consume_queue_options[];
-extern amqp_bytes_t setup_queue(amqp_connection_state_t conn);
-
diff --git a/tools/consume.c b/tools/consume.c
index 7ede926..40b61d1 100644
--- a/tools/consume.c
+++ b/tools/consume.c
@@ -51,17 +51,105 @@
#include "config.h"
#include <stdio.h>
+#include <stdlib.h>
#include <popt.h>
#include "common.h"
-#include "common_consume.h"
-static void do_consume(amqp_connection_state_t conn, int no_ack,
- const char * const *argv)
+/* Convert a amqp_bytes_t to an escaped string form for printing. We
+ use the same escaping conventions as rabbitmqctl. */
+static char *stringify_bytes(amqp_bytes_t bytes)
{
- if (!amqp_basic_consume(conn, 1, setup_queue(conn),
- AMQP_EMPTY_BYTES, 0, no_ack, 0))
+ /* We will need up to 4 chars per byte, plus the terminating 0 */
+ char *res = malloc(bytes.len * 4 + 1);
+ uint8_t *data = bytes.bytes;
+ char *p = res;
+ size_t i;
+
+ for (i = 0; i < bytes.len; i++) {
+ if (data[i] >= 32 && data[i] != 127) {
+ *p++ = data[i];
+ }
+ else {
+ *p++ = '\\';
+ *p++ = '0' + (data[i] >> 6);
+ *p++ = '0' + (data[i] >> 3 & 0x7);
+ *p++ = '0' + (data[i] & 0x7);
+ }
+ }
+
+ *p = 0;
+ return res;
+}
+
+static amqp_bytes_t setup_queue(amqp_connection_state_t conn,
+ char *queue, char *exchange,
+ char *exchange_type, char *routing_key)
+{
+ amqp_bytes_t queue_bytes;
+ amqp_queue_declare_ok_t *res;
+
+ /* 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);
+ }
+ }
+
+ /* 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);
+ }
+
+ /* 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");
+ }
+
+ 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;
+}
+
+static void do_consume(amqp_connection_state_t conn, amqp_bytes_t queue,
+ int no_ack, const char * const *argv)
+{
+ if (!amqp_basic_consume(conn, 1, queue, AMQP_EMPTY_BYTES, 0, no_ack,
+ 0))
die_rpc(amqp_get_rpc_reply(conn), "basic.consume");
for (;;) {
@@ -97,10 +185,23 @@ int main(int argc, const char **argv)
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;
+ amqp_bytes_t queue_bytes;
+
struct poptOption options[] = {
INCLUDE_OPTIONS(connect_options),
- INCLUDE_OPTIONS(consume_queue_options),
+ {"queue", 'q', POPT_ARG_STRING, &queue, 0,
+ "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"},
{"no-ack", 'A', POPT_ARG_NONE, &no_ack, 0,
"consume in no-ack mode", NULL},
POPT_AUTOHELP
@@ -118,7 +219,9 @@ int main(int argc, const char **argv)
}
conn = make_connection();
- do_consume(conn, no_ack, cmd_argv);
+ queue_bytes = setup_queue(conn, queue, exchange, exchange_type,
+ routing_key);
+ 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
new file mode 100644
index 0000000..448ade6
--- /dev/null
+++ b/tools/doc/consume.xml
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"
+[
+<!ENTITY date SYSTEM "man-date.ent" >
+]
+>
+<refentry lang="en">
+ <refentryinfo>
+ <productname>RabbitMQ C Client</productname>
+ <authorgroup>
+ <corpauthor>The RabbitMQ Team &lt;<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>&gt;</corpauthor>
+ </authorgroup>
+ <date>&date;</date>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>amqp-consume</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>amqp-consume</refname>
+ <refpurpose>Consume messages from a queue on an AMQP server</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>amqp-consume</command>
+ <arg choice="opt" rep="repeat">
+ <replaceable>OPTION</replaceable>
+ </arg>
+ <arg choice="req">
+ <replaceable>command</replaceable>
+ </arg>
+ <arg choice="opt" rep="repeat">
+ <replaceable>args</replaceable>
+ </arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ <command>amqp-consume</command> consumes messages from a
+ queue on an AMQP server. For each message that arrives, a
+ receiving command is run, with the message body supplied
+ to it on standard input.
+ </para>
+ <para>
+ <command>amqp-consume</command> 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.
+ </para>
+ <para>
+ By default, messages will be consumed with explicit
+ acknowledgements. A message will only be acknowledged if
+ the receiving command exits successfully (i.e. with an
+ exit code of zero). The AMQP <quote>no ack</quote> mode
+ (a.k.a. auto-ack mode) can be enable with the
+ <option>-A</option> option.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Options</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>-q</option></term>
+ <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term>
+ <listitem>
+ <para>
+ 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.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-e</option></term>
+ <term><option>--exchange</option>=<replaceable class="parameter">exchange name</replaceable></term>
+ <listitem>
+ <para>
+ 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>--exchange-type</option> option is
+ used to request the creation of an exchange.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-t</option></term>
+ <term><option>--exchange-type</option>=<replaceable class="parameter">type</replaceable></term>
+ <listitem>
+ <para>
+ 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>--exchange</option>
+ option.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-r</option></term>
+ <term><option>--routing-key</option>=<replaceable class="parameter">routing key</replaceable></term>
+ <listitem>
+ <para>
+ The routing key for the binding. If omitted,
+ an empty routing key is assumed.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-A</option></term>
+ <term><option>--no-ack</option>=<replaceable class="parameter">routing key</replaceable></term>
+ <listitem>
+ <para>
+ Enable <quote>no ack</quote> mode: The AMQP
+ server will unconditionally acknowledge each
+ message that is delivered, regardless of
+ whether the target command exits successfully
+ or not.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>Consume messages from the queue
+ <quote><systemitem
+ class="resource">myqueue</systemitem></quote>, and
+ output the message bodies on standard output via
+ <command>cat</command>:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-publish -q myqueue cat</userinput></screen>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>Bind a newly created auto-delete queue to an
+ exchange <quote><systemitem
+ class="resource">myexch</systemitem></quote>, and send
+ each message body to the script
+ <filename>myscript</filename>, automatically
+ acknowledging them on the server:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-consume -A -e myexch ./myscript</userinput></screen>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ describes connection-related options common to all the
+ RabbitMQ C Client tools.
+ </para>
+ </refsect1>
+</refentry>
diff --git a/tools/doc/get.xml b/tools/doc/get.xml
new file mode 100644
index 0000000..9770a8b
--- /dev/null
+++ b/tools/doc/get.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"
+[
+<!ENTITY date SYSTEM "man-date.ent" >
+]
+>
+<refentry lang="en">
+ <refentryinfo>
+ <productname>RabbitMQ C Client</productname>
+ <authorgroup>
+ <corpauthor>The RabbitMQ Team &lt;<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>&gt;</corpauthor>
+ </authorgroup>
+ <date>&date;</date>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>amqp-get</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>amqp-get</refname>
+ <refpurpose>Get a message from a queue on an AMQP server</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>amqp-get</command>
+ <arg choice="opt" rep="repeat">
+ <replaceable>OPTION</replaceable>
+ </arg>
+ <arg choice="req">-q <replaceable>queue name</replaceable></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ <command>amqp-get</command> attempts to consume a single
+ message from a queue on an AMQP server, and exits. Unless
+ the queue was empty, the body of the resulting message is
+ sent to standard output.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Options</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>-q</option></term>
+ <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term>
+ <listitem>
+ <para>
+ The name of the queue to consume messages
+ from.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Exit Status</title>
+ <para>
+ If the queue is not empty, and a message is successfully
+ retrieved, the exit status is 0. If an error occurs, the
+ exit status is 1. If the queue is found to be empty, the
+ exit status is 2.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>Get a message from the queue <quote><systemitem
+ class="resource">myqueue</systemitem></quote>, and
+ display its body on standard output:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-get -q myqueue</userinput></screen>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ describes connection-related options common to all the
+ RabbitMQ C Client tools.
+ </para>
+ </refsect1>
+</refentry>
diff --git a/tools/doc/librabbitmq-tools.xml b/tools/doc/librabbitmq-tools.xml
new file mode 100644
index 0000000..41f092a
--- /dev/null
+++ b/tools/doc/librabbitmq-tools.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"
+[
+<!ENTITY date SYSTEM "man-date.ent" >
+]
+>
+<refentry lang="en">
+ <refentryinfo>
+ <productname>RabbitMQ C Client</productname>
+ <authorgroup>
+ <corpauthor>The RabbitMQ Team &lt;<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>&gt;</corpauthor>
+ </authorgroup>
+ <date>&date;</date>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>librabbitmq-tools</refentrytitle>
+ <manvolnum>7</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>librabbitmq-tools</refname>
+ <refpurpose>Command line AMQP tools</refpurpose>
+ </refnamediv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ A set of command line AMQP tools based on <systemitem
+ class="library">librabbitmq</systemitem>. This page
+ describes common options and conventions used by all of
+ the tools.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Common Options</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>-s</option></term>
+ <term><option>--server</option>=<replaceable class="parameter">hostname:port</replaceable></term>
+ <listitem>
+ <para>
+ The host name (or address) to connect to.
+ Defaults to localhost. The port number may
+ also be specified; if omitted, it defaults to
+ the standard AMQP port number (5672).
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--vhost</option>=<replaceable class="parameter">vhost</replaceable></term>
+ <listitem>
+ <para>
+ The AMQP vhost to specify when connnecting.
+ Defaults to <literal>/</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--username</option>=<replaceable class="parameter">username</replaceable></term>
+ <listitem>
+ <para>
+ The username to authenticate to the AMQP server with. Defaults to <literal>guest</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--password</option>=<replaceable class="parameter">password</replaceable></term>
+ <listitem>
+ <para>
+ The password to authenticate to the AMQP server with. Defaults to <literal>guest</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <simplelist type='inline'>
+ <member><citerefentry><refentrytitle>amqp-publish</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
+ <member><citerefentry><refentrytitle>amqp-consume</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
+ <member><citerefentry><refentrytitle>amqp-get</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
+ </simplelist>
+ </para>
+ </refsect1>
+</refentry>
diff --git a/tools/doc/publish.xml b/tools/doc/publish.xml
new file mode 100644
index 0000000..d2e8d2e
--- /dev/null
+++ b/tools/doc/publish.xml
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"
+[
+<!ENTITY date SYSTEM "man-date.ent" >
+]
+>
+<refentry lang="en">
+ <refentryinfo>
+ <productname>RabbitMQ C Client</productname>
+ <authorgroup>
+ <corpauthor>The RabbitMQ Team &lt;<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>&gt;</corpauthor>
+ </authorgroup>
+ <date>&date;</date>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>amqp-publish</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>amqp-publish</refname>
+ <refpurpose>Publish a message on an AMQP server</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>amqp-publish</command>
+ <arg choice="opt" rep="repeat">
+ <replaceable>OPTION</replaceable>
+ </arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ Publishes a message to an exchange on an AMQP server.
+ Options allow the various properties of the message and
+ parameters of the AMQP <function>basic.publish</function>
+ method to be specified.
+ </para>
+ <para>
+ By default, the message body is read from standard input.
+ Alternatively, the <option>-b</option> option allows the message
+ body to be provided as part of the command.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Options</title>
+ <variablelist>
+ <varlistentry>
+ <term><option>-e</option></term>
+ <term><option>--exchange</option>=<replaceable class="parameter">exchange name</replaceable></term>
+ <listitem>
+ <para>
+ The name of the exchange to publish to. If
+ omitted, the default exchange (also known as
+ the nameless exchange) is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-r</option></term>
+ <term><option>--routing-key</option>=<replaceable class="parameter">routing key</replaceable></term>
+ <listitem>
+ <para>
+ The routing key to publish with. If omitted,
+ an empty routing key is assumed. A routing
+ key must be specified when publishing to the
+ default exchange; in that case, accoding to
+ the AMQP specification, the routing key
+ corresponds to a queue name.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-p</option></term>
+ <term><option>--persistent</option></term>
+ <listitem>
+ <para>
+ Use the persistent delivery mode. Without
+ this option, non-persistent delivery is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-C</option></term>
+ <term><option>--content-type</option>=<replaceable class="parameter">MIME type</replaceable></term>
+ <listitem>
+ <para>
+ Specifies the content-type property for the
+ message. If omitted, the content-type
+ property is not set on the message.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-E</option></term>
+ <term><option>--content-encoding</option>=<replaceable class="parameter">content coding</replaceable></term>
+ <listitem>
+ <para>
+ Specifies the content-encoding property for
+ the message. If omitted, the content-encoding
+ property is not set on the message.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-b</option></term>
+ <term><option>--body</option>=<replaceable class="parameter">message body</replaceable></term>
+ <listitem>
+ <para>
+ Specifies the message body. If omitted, the
+ message body is read from standard input.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>Send a short message, consisting of the word
+ <quote><literal>Hello</literal></quote> to the queue
+ <quote><systemitem
+ class="resource">myqueue</systemitem></quote> via the
+ default exchange:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-publish -r myqueue -b Hello</userinput></screen>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>Send some XML data from a file to the exchange
+ <quote><systemitem
+ class="resource">events</systemitem></quote>, with
+ persistent delivery mode, setting the content-type
+ property on the message to make the data format
+ explicit:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-publish -e events -p -C text/xml &lt;event.xml</userinput></screen>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ describes connection-related options common to all the
+ RabbitMQ C Client tools.
+ </para>
+ </refsect1>
+</refentry>
diff --git a/tools/get.c b/tools/get.c
index b433e2b..f746fd1 100644
--- a/tools/get.c
+++ b/tools/get.c
@@ -55,12 +55,11 @@
#include <popt.h>
#include "common.h"
-#include "common_consume.h"
-static int do_get(amqp_connection_state_t conn)
+static int do_get(amqp_connection_state_t conn, char *queue)
{
amqp_rpc_reply_t r
- = amqp_basic_get(conn, 1, setup_queue(conn), 1);
+ = amqp_basic_get(conn, 1, cstring_bytes(queue), 1);
die_rpc(r, "basic.get");
if (r.reply.id == AMQP_BASIC_GET_EMPTY_METHOD)
@@ -73,19 +72,26 @@ static int do_get(amqp_connection_state_t conn)
int main(int argc, const char **argv)
{
amqp_connection_state_t conn;
+ char *queue = NULL;
int got_something;
struct poptOption options[] = {
INCLUDE_OPTIONS(connect_options),
- INCLUDE_OPTIONS(consume_queue_options),
+ {"queue", 'q', POPT_ARG_STRING, &queue, 0,
+ "the queue to consume from", "queue"},
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
process_all_options(argc, argv, options);
+
+ if (!queue) {
+ fprintf(stderr, "queue not specified\n");
+ return 1;
+ }
conn = make_connection();
- got_something = do_get(conn);
+ got_something = do_get(conn, queue);
close_connection(conn);
return got_something ? 0 : 2;
}
diff --git a/tools/publish.c b/tools/publish.c
index a5b86b2..21314b2 100644
--- a/tools/publish.c
+++ b/tools/publish.c
@@ -111,7 +111,7 @@ int main(int argc, const char **argv)
memset(&props, 0, sizeof props);
props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG;
- props.delivery_mode = 2; // persistent delivery mode
+ props.delivery_mode = 2; /* persistent delivery mode */
if (content_type) {
props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG;