delete_queue.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * ***** BEGIN LICENSE BLOCK *****
  3. * Version: MIT
  4. *
  5. * Portions created by Alan Antonuk are Copyright (c) 2012-2013
  6. * Alan Antonuk. All Rights Reserved.
  7. *
  8. * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
  9. * All Rights Reserved.
  10. *
  11. * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
  12. * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
  13. *
  14. * Permission is hereby granted, free of charge, to any person
  15. * obtaining a copy of this software and associated documentation
  16. * files (the "Software"), to deal in the Software without
  17. * restriction, including without limitation the rights to use, copy,
  18. * modify, merge, publish, distribute, sublicense, and/or sell copies
  19. * of the Software, and to permit persons to whom the Software is
  20. * furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be
  23. * included in all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. * ***** END LICENSE BLOCK *****
  34. */
  35. #ifdef HAVE_CONFIG_H
  36. #include "config.h"
  37. #endif
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <unistd.h>
  42. #include "common.h"
  43. int main(int argc, const char **argv) {
  44. amqp_connection_state_t conn;
  45. static char *queue = NULL;
  46. static int if_unused = 0;
  47. static int if_empty = 0;
  48. struct poptOption options[] = {
  49. INCLUDE_OPTIONS(connect_options),
  50. {"queue", 'q', POPT_ARG_STRING, &queue, 0, "the queue name to delete",
  51. "queue"},
  52. {"if-unused", 'u', POPT_ARG_VAL, &if_unused, 1,
  53. "do not delete unless queue is unused", NULL},
  54. {"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1,
  55. "do not delete unless queue is empty", NULL},
  56. POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}};
  57. process_all_options(argc, argv, options);
  58. if (queue == NULL || *queue == '\0') {
  59. fprintf(stderr, "queue name not specified\n");
  60. return 1;
  61. }
  62. conn = make_connection();
  63. {
  64. amqp_queue_delete_ok_t *reply =
  65. amqp_queue_delete(conn, 1, cstring_bytes(queue), if_unused, if_empty);
  66. if (reply == NULL) {
  67. die_rpc(amqp_get_rpc_reply(conn), "queue.delete");
  68. }
  69. printf("%u\n", reply->message_count);
  70. }
  71. close_connection(conn);
  72. return 0;
  73. }