| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#include "common.h" |
| 7 |
|
| 8 |
static int do_get(amqp_connection_state_t conn, char *queue) { |
| 9 |
amqp_rpc_reply_t r = amqp_basic_get(conn, 1, cstring_bytes(queue), 1); |
| 10 |
die_rpc(r, "basic.get"); |
| 11 |
|
| 12 |
if (r.reply.id == AMQP_BASIC_GET_EMPTY_METHOD) { |
| 13 |
return 0; |
| 14 |
} |
| 15 |
|
| 16 |
copy_body(conn, 1); |
| 17 |
return 1; |
| 18 |
} |
| 19 |
|
| 20 |
int main(int argc, const char **argv) { |
| 21 |
amqp_connection_state_t conn; |
| 22 |
static char *queue = NULL; |
| 23 |
int got_something; |
| 24 |
|
| 25 |
struct poptOption options[] = { |
| 26 |
INCLUDE_OPTIONS(connect_options), |
| 27 |
{"queue", 'q', POPT_ARG_STRING, &queue, 0, "the queue to consume from", |
| 28 |
"queue"}, |
| 29 |
POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}}; |
| 30 |
|
| 31 |
process_all_options(argc, argv, options); |
| 32 |
|
| 33 |
if (!queue) { |
| 34 |
fprintf(stderr, "queue not specified\n"); |
| 35 |
return 1; |
| 36 |
} |
| 37 |
|
| 38 |
conn = make_connection(); |
| 39 |
got_something = do_get(conn, queue); |
| 40 |
close_connection(conn); |
| 41 |
return got_something ? 0 : 2; |
| 42 |
} |