amqp_unbind.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <stdint.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <amqp.h>
  40. #include <amqp_tcp_socket.h>
  41. #include "utils.h"
  42. int main(int argc, char const *const *argv) {
  43. char const *hostname;
  44. int port, status;
  45. char const *exchange;
  46. char const *bindingkey;
  47. char const *queue;
  48. amqp_socket_t *socket = NULL;
  49. amqp_connection_state_t conn;
  50. if (argc < 6) {
  51. fprintf(stderr, "Usage: amqp_unbind host port exchange bindingkey queue\n");
  52. return 1;
  53. }
  54. hostname = argv[1];
  55. port = atoi(argv[2]);
  56. exchange = argv[3];
  57. bindingkey = argv[4];
  58. queue = argv[5];
  59. conn = amqp_new_connection();
  60. socket = amqp_tcp_socket_new(conn);
  61. if (!socket) {
  62. die("creating TCP socket");
  63. }
  64. status = amqp_socket_open(socket, hostname, port);
  65. if (status) {
  66. die("opening TCP socket");
  67. }
  68. die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
  69. "guest", "guest"),
  70. "Logging in");
  71. amqp_channel_open(conn, 1);
  72. die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");
  73. amqp_queue_unbind(conn, 1, amqp_cstring_bytes(queue),
  74. amqp_cstring_bytes(exchange),
  75. amqp_cstring_bytes(bindingkey), amqp_empty_table);
  76. die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding");
  77. die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS),
  78. "Closing channel");
  79. die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS),
  80. "Closing connection");
  81. die_on_error(amqp_destroy_connection(conn), "Ending connection");
  82. return 0;
  83. }