summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDavid Wragg <david@rabbitmq.com>2010-06-06 02:48:53 +0100
committerDavid Wragg <david@rabbitmq.com>2010-06-06 02:48:53 +0100
commit872d469c5917e80b9e52e7eac7e5357c1bfcf428 (patch)
treeca905b97c45195be385fc12c78879f17ee8720c2 /tools
parent1450ae07a8797549dee1dc4db7fd64a41493f1f7 (diff)
parentf557f155ec3c7f52101415261fafcc8c56ed6ed2 (diff)
downloadrabbitmq-c-github-ask-872d469c5917e80b9e52e7eac7e5357c1bfcf428.tar.gz
Merge default into bug22825
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am24
-rw-r--r--tools/declare_queue.c102
-rw-r--r--tools/delete_queue.c101
-rw-r--r--tools/doc/declare_queue.xml122
-rw-r--r--tools/doc/delete_queue.xml94
5 files changed, 441 insertions, 2 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 3f9fd6a..9e68537 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = amqp-publish amqp-get amqp-consume
+bin_PROGRAMS = amqp-publish amqp-get amqp-consume amqp-declare-queue amqp-delete-queue
AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(PLATFORM_DIR)
AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la
@@ -16,9 +16,25 @@ endif
amqp_publish_SOURCES = publish.c $(COMMON_SOURCES)
amqp_get_SOURCES = get.c $(COMMON_SOURCES)
amqp_consume_SOURCES = consume.c $(PLATFORM_DIR)/process.c $(COMMON_SOURCES)
+amqp_declare_queue_SOURCES = declare_queue.c $(COMMON_SOURCES)
+amqp_delete_queue_SOURCES = delete_queue.c $(COMMON_SOURCES)
+
+EXTRA_DIST = \
+ doc/publish.xml \
+ doc/consume.xml \
+ doc/get.xml \
+ doc/declare_queue.xml \
+ doc/delete_queue.xml \
+ doc/librabbitmq-tools.xml
if TOOLS_DOC
-man_MANS = doc/amqp-publish.1 doc/amqp-consume.1 doc/amqp-get.1 doc/librabbitmq-tools.7
+man_MANS = \
+ doc/amqp-publish.1 \
+ doc/amqp-consume.1 \
+ doc/amqp-get.1 \
+ doc/amqp-declare-queue.1 \
+ doc/amqp-delete-queue.1 \
+ doc/librabbitmq-tools.7
MOSTLYCLEANFILES = doc/man-date.ent
# automake complains about % pattern rules, and suffix rules don't
@@ -29,6 +45,10 @@ 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/amqp-declare-queue.1: doc/declare_queue.xml doc/man-date.ent
+ $(XMLTO) man -o doc $<
+doc/amqp-delete-queue.1: doc/delete_queue.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 $<
diff --git a/tools/declare_queue.c b/tools/declare_queue.c
new file mode 100644
index 0000000..662531f
--- /dev/null
+++ b/tools/declare_queue.c
@@ -0,0 +1,102 @@
+/*
+ * ***** 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 <string.h>
+#include <unistd.h>
+
+#include <popt.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+ amqp_connection_state_t conn;
+ char *queue = NULL;
+ int durable = 0;
+
+ struct poptOption options[] = {
+ INCLUDE_OPTIONS(connect_options),
+ {"queue", 'q', POPT_ARG_STRING, &queue, 0,
+ "the queue name to declare, or the empty string", "queue"},
+ {"durable", 'd', POPT_ARG_VAL, &durable, 1,
+ "declare a durable queue", NULL},
+ POPT_AUTOHELP
+ { NULL, 0, 0, NULL, 0 }
+ };
+
+ process_all_options(argc, argv, options);
+
+ if (queue == NULL) {
+ fprintf(stderr, "queue name not specified\n");
+ return 1;
+ }
+
+ conn = make_connection();
+ {
+ amqp_queue_declare_ok_t *reply = amqp_queue_declare(conn, 1,
+ cstring_bytes(queue),
+ 0,
+ durable,
+ 0,
+ 0,
+ AMQP_EMPTY_TABLE);
+ if (reply == NULL) {
+ die_rpc(amqp_get_rpc_reply(conn), "queue.declare");
+ }
+ write(1, reply->queue.bytes, reply->queue.len);
+ write(1, "\n", strlen("\n"));
+ }
+ close_connection(conn);
+ return 0;
+}
diff --git a/tools/delete_queue.c b/tools/delete_queue.c
new file mode 100644
index 0000000..41d0d13
--- /dev/null
+++ b/tools/delete_queue.c
@@ -0,0 +1,101 @@
+/*
+ * ***** 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 <string.h>
+#include <unistd.h>
+
+#include <popt.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+ amqp_connection_state_t conn;
+ char *queue = NULL;
+ int if_unused = 0;
+ int if_empty = 0;
+
+ struct poptOption options[] = {
+ INCLUDE_OPTIONS(connect_options),
+ {"queue", 'q', POPT_ARG_STRING, &queue, 0,
+ "the queue name to delete", "queue"},
+ {"if-unused", 'u', POPT_ARG_VAL, &if_unused, 1,
+ "do not delete unless queue is unused", NULL},
+ {"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1,
+ "do not delete unless queue is empty", NULL},
+ POPT_AUTOHELP
+ { NULL, 0, 0, NULL, 0 }
+ };
+
+ process_all_options(argc, argv, options);
+
+ if (queue == NULL || *queue == '\0') {
+ fprintf(stderr, "queue name not specified\n");
+ return 1;
+ }
+
+ conn = make_connection();
+ {
+ amqp_queue_delete_ok_t *reply = amqp_queue_delete(conn, 1,
+ cstring_bytes(queue),
+ if_unused,
+ if_empty);
+ if (reply == NULL) {
+ die_rpc(amqp_get_rpc_reply(conn), "queue.delete");
+ }
+ printf("%u\n", reply->message_count);
+ }
+ close_connection(conn);
+ return 0;
+}
diff --git a/tools/doc/declare_queue.xml b/tools/doc/declare_queue.xml
new file mode 100644
index 0000000..7e9da32
--- /dev/null
+++ b/tools/doc/declare_queue.xml
@@ -0,0 +1,122 @@
+<?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-declare-queue</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>amqp-declare-queue</refname>
+ <refpurpose>Declare (create or assert the existence of) a queue on an AMQP server</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>amqp-declare-queue</command>
+ <arg choice="opt" rep="repeat">
+ <replaceable>OPTION</replaceable>
+ </arg>
+ <arg choice="opt">-d</arg>
+ <arg choice="req">-q <replaceable>queue name</replaceable></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ <command>amqp-declare-queue</command> attempts to create a
+ queue on an AMQP server, and exits. If the empty-string is
+ supplied as the queue name, a fresh queue name is
+ generated by the server and returned. In all cases, if a
+ queue was successfully declared, the (raw binary) name of
+ the queue is printed to standard output, followed by a
+ newline.
+ </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 declare. If the
+ empty string is supplied, a fresh queue name
+ is generated by the server.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-d</option></term>
+ <term><option>--durable</option></term>
+ <listitem>
+ <para>
+ Causes the queue to be declared with the
+ "durable" flag set. Durable queues survive
+ server restarts. By default, queues are declared
+ in "transient" mode.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Exit Status</title>
+ <para>
+ If the queue was successfully declared, the exit status is
+ 0. If an error occurs, the exit status is 1.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>Declare the durable queue <quote><systemitem
+ class="resource">myqueue</systemitem></quote>, and
+ display the name of the queue on standard output:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-declare-queue -d -q myqueue</userinput>
+myqueue</screen>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>Declare a fresh, server-named transient queue,
+ and display the name of the queue on standard output
+ (use <citerefentry><refentrytitle>amqp-delete-queue</refentrytitle>
+ <manvolnum>1</manvolnum></citerefentry> to delete
+ it from the server once you're done):</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-declare-queue -q ""</userinput>
+amq.gen-BW/wvociA8g6LFpb1PlqOA==</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/delete_queue.xml b/tools/doc/delete_queue.xml
new file mode 100644
index 0000000..69d03d8
--- /dev/null
+++ b/tools/doc/delete_queue.xml
@@ -0,0 +1,94 @@
+<?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-delete-queue</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+ <refname>amqp-delete-queue</refname>
+ <refpurpose>Delete a queue from an AMQP server</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>amqp-delete-queue</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-delete-queue</command> deletes a queue from
+ an AMQP server, and exits after printing to standard
+ output the number of messages that were in the queue at
+ the time of its deletion.
+ </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 delete.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Exit Status</title>
+ <para>
+ If the queue was successfully deleted, the exit status is
+ 0. If an error occurs, the exit status is 1.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>Delete the
+ queue <quote><systemitem class="resource">myqueue</systemitem></quote>
+ at a moment when it has 123 messages waiting on
+ it:</term>
+ <listitem>
+ <screen><prompt>$ </prompt><userinput>amqp-delete-queue -q myqueue</userinput>
+123</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>