delete_queue.c 1.2 KB

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