Merge default into amqp_0_9_1 (the usual edit of amqp_basic_consume was the only manual change)
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0
5 * The contents of this file are subject to the Mozilla Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12 * the License for the specific language governing rights and
13 * limitations under the License.
15 * The Original Code is librabbitmq.
17 * The Initial Developers of the Original Code are LShift Ltd, Cohesive
18 * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions
19 * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive
20 * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright
21 * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and
22 * Rabbit Technologies Ltd.
24 * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
25 * Ltd. Portions created by Cohesive Financial Technologies LLC are
26 * Copyright (C) 2007-2009 Cohesive Financial Technologies
27 * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C)
28 * 2007-2009 Rabbit Technologies Ltd.
30 * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010
31 * LShift Ltd and Tony Garnock-Jones.
33 * All Rights Reserved.
35 * Contributor(s): ______________________________________.
37 * Alternatively, the contents of this file may be used under the terms
38 * of the GNU General Public License Version 2 or later (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of those
40 * above. If you wish to allow use of your version of this file only
41 * under the terms of the GPL, and not to allow others to use your
42 * version of this file under the terms of the MPL, indicate your
43 * decision by deleting the provisions above and replace them with the
44 * notice and other provisions required by the GPL. If you do not
45 * delete the provisions above, a recipient may use your version of
46 * this file under the terms of any one of the MPL or the GPL.
48 * ***** END LICENSE BLOCK *****
58 #include "common_consume.h"
60 static void do_consume(amqp_connection_state_t conn, int no_ack,
61 const char * const *argv)
63 if (!amqp_basic_consume(conn, 1, setup_queue(conn),
64 AMQP_EMPTY_BYTES, 0, no_ack, 0, AMQP_EMPTY_TABLE))
65 die_rpc(amqp_get_rpc_reply(conn), "basic.consume");
70 uint64_t delivery_tag;
71 int res = amqp_simple_wait_frame(conn, &frame);
73 die_errno(-res, "waiting for header frame");
75 if (frame.frame_type != AMQP_FRAME_METHOD
76 || frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD)
79 amqp_basic_deliver_t *deliver
80 = (amqp_basic_deliver_t *)frame.payload.method.decoded;
81 delivery_tag = deliver->delivery_tag;
84 copy_body(conn, pl.infd);
86 if (finish_pipeline(&pl) && !no_ack)
87 die_errno(-amqp_basic_ack(conn, 1, delivery_tag, 0),
90 amqp_maybe_release_buffers(conn);
94 int main(int argc, const char **argv)
98 amqp_connection_state_t conn;
99 const char * const *cmd_argv;
101 struct poptOption options[] = {
102 INCLUDE_OPTIONS(connect_options),
103 INCLUDE_OPTIONS(consume_queue_options),
104 {"no-ack", 'A', POPT_ARG_NONE, &no_ack, 0,
105 "consume in no-ack mode", NULL},
107 { NULL, 0, 0, NULL, 0 }
110 opts = process_options(argc, argv, options,
111 "[OPTIONS]... <command> <args>");
113 cmd_argv = poptGetArgs(opts);
114 if (!cmd_argv || !cmd_argv[0]) {
115 fprintf(stderr, "consuming command not specified\n");
116 poptPrintUsage(opts, stderr, 0);
120 conn = make_connection();
121 do_consume(conn, no_ack, cmd_argv);
122 close_connection(conn);
126 poptFreeContext(opts);