get.c 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
  2. // SPDX-License-Identifier: mit
  3. #include <stdio.h>
  4. #include "common.h"
  5. static int do_get(amqp_connection_state_t conn, char *queue) {
  6. amqp_rpc_reply_t r = amqp_basic_get(conn, 1, cstring_bytes(queue), 1);
  7. die_rpc(r, "basic.get");
  8. if (r.reply.id == AMQP_BASIC_GET_EMPTY_METHOD) {
  9. return 0;
  10. }
  11. copy_body(conn, 1);
  12. return 1;
  13. }
  14. int main(int argc, const char **argv) {
  15. amqp_connection_state_t conn;
  16. static char *queue = NULL;
  17. int got_something;
  18. struct poptOption options[] = {
  19. INCLUDE_OPTIONS(connect_options),
  20. {"queue", 'q', POPT_ARG_STRING, &queue, 0, "the queue to consume from",
  21. "queue"},
  22. POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}};
  23. process_all_options(argc, argv, options);
  24. if (!queue) {
  25. fprintf(stderr, "queue not specified\n");
  26. return 1;
  27. }
  28. conn = make_connection();
  29. got_something = do_get(conn, queue);
  30. close_connection(conn);
  31. return got_something ? 0 : 2;
  32. }