declare_queue.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 durable = 0;
  12. struct poptOption options[] = {
  13. INCLUDE_OPTIONS(connect_options),
  14. {"queue", 'q', POPT_ARG_STRING, &queue, 0,
  15. "the queue name to declare, or the empty string", "queue"},
  16. {"durable", 'd', POPT_ARG_VAL, &durable, 1, "declare a durable queue",
  17. NULL},
  18. POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}};
  19. process_all_options(argc, argv, options);
  20. if (queue == NULL) {
  21. fprintf(stderr, "queue name not specified\n");
  22. return 1;
  23. }
  24. conn = make_connection();
  25. {
  26. amqp_queue_declare_ok_t *reply = amqp_queue_declare(
  27. conn, 1, cstring_bytes(queue), 0, durable, 0, 0, amqp_empty_table);
  28. if (reply == NULL) {
  29. die_rpc(amqp_get_rpc_reply(conn), "queue.declare");
  30. }
  31. printf("%.*s\n", (int)reply->queue.len, (char *)reply->queue.bytes);
  32. }
  33. close_connection(conn);
  34. return 0;
  35. }