Blame examples/amqp_exchange_declare.c

Packit 12c978
/*
Packit 12c978
 * ***** BEGIN LICENSE BLOCK *****
Packit 12c978
 * Version: MIT
Packit 12c978
 *
Packit 12c978
 * Portions created by Alan Antonuk are Copyright (c) 2012-2013
Packit 12c978
 * Alan Antonuk. All Rights Reserved.
Packit 12c978
 *
Packit 12c978
 * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
Packit 12c978
 * All Rights Reserved.
Packit 12c978
 *
Packit 12c978
 * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
Packit 12c978
 * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
Packit 12c978
 *
Packit 12c978
 * Permission is hereby granted, free of charge, to any person
Packit 12c978
 * obtaining a copy of this software and associated documentation
Packit 12c978
 * files (the "Software"), to deal in the Software without
Packit 12c978
 * restriction, including without limitation the rights to use, copy,
Packit 12c978
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 12c978
 * of the Software, and to permit persons to whom the Software is
Packit 12c978
 * furnished to do so, subject to the following conditions:
Packit 12c978
 *
Packit 12c978
 * The above copyright notice and this permission notice shall be
Packit 12c978
 * included in all copies or substantial portions of the Software.
Packit 12c978
 *
Packit 12c978
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 12c978
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 12c978
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 12c978
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 12c978
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 12c978
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 12c978
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 12c978
 * SOFTWARE.
Packit 12c978
 * ***** END LICENSE BLOCK *****
Packit 12c978
 */
Packit 12c978
Packit 12c978
#include <stdint.h>
Packit 12c978
#include <stdio.h>
Packit 12c978
#include <stdlib.h>
Packit 12c978
#include <string.h>
Packit 12c978
Packit 12c978
#include <amqp.h>
Packit 12c978
#include <amqp_tcp_socket.h>
Packit 12c978
Packit 12c978
#include "utils.h"
Packit 12c978
Packit 12c978
int main(int argc, char const *const *argv) {
Packit 12c978
  char const *hostname;
Packit 12c978
  int port, status;
Packit 12c978
  char const *exchange;
Packit 12c978
  char const *exchangetype;
Packit 12c978
  amqp_socket_t *socket = NULL;
Packit 12c978
  amqp_connection_state_t conn;
Packit 12c978
Packit 12c978
  if (argc < 5) {
Packit 12c978
    fprintf(stderr,
Packit 12c978
            "Usage: amqp_exchange_declare host port exchange exchangetype\n");
Packit 12c978
    return 1;
Packit 12c978
  }
Packit 12c978
Packit 12c978
  hostname = argv[1];
Packit 12c978
  port = atoi(argv[2]);
Packit 12c978
  exchange = argv[3];
Packit 12c978
  exchangetype = argv[4];
Packit 12c978
Packit 12c978
  conn = amqp_new_connection();
Packit 12c978
Packit 12c978
  socket = amqp_tcp_socket_new(conn);
Packit 12c978
  if (!socket) {
Packit 12c978
    die("creating TCP socket");
Packit 12c978
  }
Packit 12c978
Packit 12c978
  status = amqp_socket_open(socket, hostname, port);
Packit 12c978
  if (status) {
Packit 12c978
    die("opening TCP socket");
Packit 12c978
  }
Packit 12c978
Packit 12c978
  die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
Packit 12c978
                               "guest", "guest"),
Packit 12c978
                    "Logging in");
Packit 12c978
  amqp_channel_open(conn, 1);
Packit 12c978
  die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");
Packit 12c978
Packit 12c978
  amqp_exchange_declare(conn, 1, amqp_cstring_bytes(exchange),
Packit 12c978
                        amqp_cstring_bytes(exchangetype), 0, 0, 0, 0,
Packit 12c978
                        amqp_empty_table);
Packit 12c978
  die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring exchange");
Packit 12c978
Packit 12c978
  die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS),
Packit 12c978
                    "Closing channel");
Packit 12c978
  die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS),
Packit 12c978
                    "Closing connection");
Packit 12c978
  die_on_error(amqp_destroy_connection(conn), "Ending connection");
Packit 12c978
  return 0;
Packit 12c978
}