~ubuntu-cloud-archive/ubuntu/precise/librabbitmq/precise-icehouse

« back to all changes in this revision

Viewing changes to examples/amqp_bind.c

  • Committer: Package Import Robot
  • Author(s): Michael Fladischer
  • Date: 2013-11-04 20:15:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131104201555-wdjlgotdjansj1j9
Tags: 0.4.1-1
* Imported Upstream version 0.4.1
* Add libssl-dev to Build-Depends.
* Update librabbitmq1.symbols.
* Switch buildsystem to cmake.
  + Add cmake_multiarch.patch to fix multiarch installation paths for shared
    library files in cmake.
  * Add cmake to Build-Depends.
  * Drop dh-autoreconf from Build-Depends.
* Format packaging files with wrap-and-sort.
* Update d/watch file to use github releases instead of tags.
* Bump Standards version to 3.9.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:set ft=c ts=2 sw=2 sts=2 et cindent: */
1
2
/*
2
3
 * ***** BEGIN LICENSE BLOCK *****
3
4
 * Version: MIT
4
5
 *
 
6
 * Portions created by Alan Antonuk are Copyright (c) 2012-2013
 
7
 * Alan Antonuk. All Rights Reserved.
 
8
 *
5
9
 * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
6
10
 * All Rights Reserved.
7
11
 *
35
39
#include <string.h>
36
40
 
37
41
#include <stdint.h>
 
42
#include <amqp_tcp_socket.h>
38
43
#include <amqp.h>
39
44
#include <amqp_framing.h>
40
45
 
41
46
#include "utils.h"
42
47
 
43
 
int main(int argc, char const * const *argv) {
 
48
int main(int argc, char const *const *argv)
 
49
{
44
50
  char const *hostname;
45
 
  int port;
 
51
  int port, status;
46
52
  char const *exchange;
47
53
  char const *bindingkey;
48
54
  char const *queue;
49
 
 
50
 
  int sockfd;
 
55
  amqp_socket_t *socket = NULL;
51
56
  amqp_connection_state_t conn;
52
57
 
53
58
  if (argc < 6) {
63
68
 
64
69
  conn = amqp_new_connection();
65
70
 
66
 
  die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket");
67
 
  amqp_set_sockfd(conn, sockfd);
 
71
  socket = amqp_tcp_socket_new(conn);
 
72
  if (!socket) {
 
73
    die("creating TCP socket");
 
74
  }
 
75
 
 
76
  status = amqp_socket_open(socket, hostname, port);
 
77
  if (status) {
 
78
    die("opening TCP socket");
 
79
  }
 
80
 
68
81
  die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"),
69
 
                    "Logging in");
 
82
                    "Logging in");
70
83
  amqp_channel_open(conn, 1);
71
84
  die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");
72
85
 
73
86
  amqp_queue_bind(conn, 1,
74
 
                  amqp_cstring_bytes(queue),
75
 
                  amqp_cstring_bytes(exchange),
76
 
                  amqp_cstring_bytes(bindingkey),
77
 
                  amqp_empty_table);
 
87
                  amqp_cstring_bytes(queue),
 
88
                  amqp_cstring_bytes(exchange),
 
89
                  amqp_cstring_bytes(bindingkey),
 
90
                  amqp_empty_table);
78
91
  die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding");
79
92
 
80
93
  die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel");