Debian Codegraph @

tools/delete_queue.c

raw symbols SCIP
1 // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
2 // SPDX-License-Identifier: mit
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8
9 #include "common.h"
10
11 int main(int argc, const char **argv) {
12 amqp_connection_state_t conn;
13 static char *queue = NULL;
14 static int if_unused = 0;
15 static int if_empty = 0;
16
17 struct poptOption options[] = {
18 INCLUDE_OPTIONS(connect_options),
19 {"queue", 'q', POPT_ARG_STRING, &queue, 0, "the queue name to delete",
20 "queue"},
21 {"if-unused", 'u', POPT_ARG_VAL, &if_unused, 1,
22 "do not delete unless queue is unused", NULL},
23 {"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1,
24 "do not delete unless queue is empty", NULL},
25 POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}};
26
27 process_all_options(argc, argv, options);
28
29 if (queue == NULL || *queue == '\0') {
30 fprintf(stderr, "queue name not specified\n");
31 return 1;
32 }
33
34 conn = make_connection();
35 {
36 amqp_queue_delete_ok_t *reply =
37 amqp_queue_delete(conn, 1, cstring_bytes(queue), if_unused, if_empty);
38 if (reply == NULL) {
39 die_rpc(amqp_get_rpc_reply(conn), "queue.delete");
40 }
41 printf("%u\n", reply->message_count);
42 }
43 close_connection(conn);
44 return 0;
45 }