123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
- // SPDX-License-Identifier: mit
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <rabbitmq-c/amqp.h>
- #include <rabbitmq-c/tcp_socket.h>
- #include "utils.h"
- int main(int argc, char const *const *argv) {
- char const *hostname;
- int port, status;
- char const *exchange;
- char const *bindingkey;
- char const *queue;
- amqp_socket_t *socket = NULL;
- amqp_connection_state_t conn;
- if (argc < 6) {
- fprintf(stderr, "Usage: amqp_unbind host port exchange bindingkey queue\n");
- return 1;
- }
- hostname = argv[1];
- port = atoi(argv[2]);
- exchange = argv[3];
- bindingkey = argv[4];
- queue = argv[5];
- conn = amqp_new_connection();
- socket = amqp_tcp_socket_new(conn);
- if (!socket) {
- die("creating TCP socket");
- }
- status = amqp_socket_open(socket, hostname, port);
- if (status) {
- die("opening TCP socket");
- }
- die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
- "guest", "guest"),
- "Logging in");
- amqp_channel_open(conn, 1);
- die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");
- amqp_queue_unbind(conn, 1, amqp_cstring_bytes(queue),
- amqp_cstring_bytes(exchange),
- amqp_cstring_bytes(bindingkey), amqp_empty_table);
- die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding");
- die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS),
- "Closing channel");
- die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS),
- "Closing connection");
- die_on_error(amqp_destroy_connection(conn), "Ending connection");
- return 0;
- }
|