get.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "common.h"
  40. static int do_get(amqp_connection_state_t conn, char *queue) {
  41. amqp_rpc_reply_t r = amqp_basic_get(conn, 1, cstring_bytes(queue), 1);
  42. die_rpc(r, "basic.get");
  43. if (r.reply.id == AMQP_BASIC_GET_EMPTY_METHOD) {
  44. return 0;
  45. }
  46. copy_body(conn, 1);
  47. return 1;
  48. }
  49. int main(int argc, const char **argv) {
  50. amqp_connection_state_t conn;
  51. static char *queue = NULL;
  52. int got_something;
  53. struct poptOption options[] = {
  54. INCLUDE_OPTIONS(connect_options),
  55. {"queue", 'q', POPT_ARG_STRING, &queue, 0, "the queue to consume from",
  56. "queue"},
  57. POPT_AUTOHELP{NULL, '\0', 0, NULL, 0, NULL, NULL}};
  58. process_all_options(argc, argv, options);
  59. if (!queue) {
  60. fprintf(stderr, "queue not specified\n");
  61. return 1;
  62. }
  63. conn = make_connection();
  64. got_something = do_get(conn, queue);
  65. close_connection(conn);
  66. return got_something ? 0 : 2;
  67. }