From abf48864499ecc6ea1cb7eb4dc563b2f78c11325 Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Tue, 9 Jan 2018 21:36:33 -0800 Subject: Examples: remove duplicate amqps_* examples amqps_* examples only differ in the connection, and are otherwise duplicates of the amqp_* examples. Delete these examples and rename amqps_connection_timeout.c to amqp_ssl_connect.c to demonstrate how to connect over SSL. --- examples/CMakeLists.txt | 28 +---- examples/amqp_ssl_connect.c | 134 +++++++++++++++++++++ examples/amqps_bind.c | 126 ------------------- examples/amqps_connect_timeout.c | 134 --------------------- examples/amqps_consumer.c | 246 -------------------------------------- examples/amqps_exchange_declare.c | 125 ------------------- examples/amqps_listen.c | 174 --------------------------- examples/amqps_listenq.c | 155 ------------------------ examples/amqps_producer.c | 180 ---------------------------- examples/amqps_sendstring.c | 133 --------------------- examples/amqps_unbind.c | 126 ------------------- 11 files changed, 136 insertions(+), 1425 deletions(-) create mode 100644 examples/amqp_ssl_connect.c delete mode 100644 examples/amqps_bind.c delete mode 100644 examples/amqps_connect_timeout.c delete mode 100644 examples/amqps_consumer.c delete mode 100644 examples/amqps_exchange_declare.c delete mode 100644 examples/amqps_listen.c delete mode 100644 examples/amqps_listenq.c delete mode 100644 examples/amqps_producer.c delete mode 100644 examples/amqps_sendstring.c delete mode 100644 examples/amqps_unbind.c (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ea13881..f49bc7a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -43,30 +43,6 @@ add_executable(amqp_listenq amqp_listenq.c ${COMMON_SRCS}) target_link_libraries(amqp_listenq ${RMQ_LIBRARY_TARGET}) if (ENABLE_SSL_SUPPORT) -add_executable(amqps_connect_timeout amqps_connect_timeout.c ${COMMON_SRCS}) -target_link_libraries(amqps_connect_timeout ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_sendstring amqps_sendstring.c ${COMMON_SRCS}) -target_link_libraries(amqps_sendstring ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_exchange_declare amqps_exchange_declare.c ${COMMON_SRCS}) -target_link_libraries(amqps_exchange_declare ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_listen amqps_listen.c ${COMMON_SRCS}) -target_link_libraries(amqps_listen ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_producer amqps_producer.c ${COMMON_SRCS}) -target_link_libraries(amqps_producer ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_consumer amqps_consumer.c ${COMMON_SRCS}) -target_link_libraries(amqps_consumer ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_unbind amqps_unbind.c ${COMMON_SRCS}) -target_link_libraries(amqps_unbind ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_bind amqps_bind.c ${COMMON_SRCS}) -target_link_libraries(amqps_bind ${RMQ_LIBRARY_TARGET}) - -add_executable(amqps_listenq amqps_listenq.c ${COMMON_SRCS}) -target_link_libraries(amqps_listenq ${RMQ_LIBRARY_TARGET}) +add_executable(amqp_ssl_connect amqp_ssl_connect.c ${COMMON_SRCS}) +target_link_libraries(amqp_ssl_connect ${RMQ_LIBRARY_TARGET}) endif (ENABLE_SSL_SUPPORT) diff --git a/examples/amqp_ssl_connect.c b/examples/amqp_ssl_connect.c new file mode 100644 index 0000000..e41b00a --- /dev/null +++ b/examples/amqp_ssl_connect.c @@ -0,0 +1,134 @@ +/* + * ***** BEGIN LICENSE BLOCK ***** + * Version: MIT + * + * Portions created by Alan Antonuk are Copyright (c) 2012-2013 + * Alan Antonuk. All Rights Reserved. + * + * Portions created by Mike Steinert are Copyright (c) 2012-2013 + * Mike Steinert. All Rights Reserved. + * + * Portions created by Bogdan Padalko are Copyright (c) 2013. + * Bogdan Padalko. All Rights Reserved. + * + * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. + * All Rights Reserved. + * + * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 + * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * ***** END LICENSE BLOCK ***** + */ + +#include +#include +#include +#include + +#include +#include + +#include + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#else +#include +#endif + +#include "utils.h" + +int main(int argc, char const *const *argv) { + char const *hostname; + int port; + int timeout; + amqp_socket_t *socket; + amqp_connection_state_t conn; + struct timeval tval; + struct timeval *tv; + + if (argc < 3) { + fprintf(stderr, + "Usage: amqps_connect_timeout host port timeout_sec " + "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); + return 1; + } + + hostname = argv[1]; + port = atoi(argv[2]); + + timeout = atoi(argv[3]); + if (timeout > 0) { + tv = &tval; + + tv->tv_sec = timeout; + tv->tv_usec = 0; + } else { + tv = NULL; + } + + conn = amqp_new_connection(); + + socket = amqp_ssl_socket_new(conn); + if (!socket) { + die("creating SSL/TLS socket"); + } + + amqp_ssl_socket_set_verify_peer(socket, 0); + amqp_ssl_socket_set_verify_hostname(socket, 0); + + if (argc > 5) { + int nextarg = 6; + die_on_error(amqp_ssl_socket_set_cacert(socket, argv[5]), + "setting CA certificate"); + if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { + amqp_ssl_socket_set_verify_peer(socket, 1); + nextarg++; + } + if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { + amqp_ssl_socket_set_verify_hostname(socket, 1); + nextarg++; + } + if (argc > nextarg + 1) { + die_on_error( + amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]), + "setting client key"); + } + } + + die_on_error(amqp_socket_open_noblock(socket, hostname, port, tv), + "opening SSL/TLS connection"); + + die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, + "guest", "guest"), + "Logging in"); + + die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), + "Closing connection"); + die_on_error(amqp_destroy_connection(conn), "Ending connection"); + + printf("Done\n"); + return 0; +} diff --git a/examples/amqps_bind.c b/examples/amqps_bind.c deleted file mode 100644 index 8832566..0000000 --- a/examples/amqps_bind.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#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; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, - "Usage: amqps_bind host port exchange bindingkey queue " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\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_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 6) { - int nextarg = 7; - status = amqp_ssl_socket_set_cacert(socket, argv[6]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_bind(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; -} diff --git a/examples/amqps_connect_timeout.c b/examples/amqps_connect_timeout.c deleted file mode 100644 index e41b00a..0000000 --- a/examples/amqps_connect_timeout.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by Bogdan Padalko are Copyright (c) 2013. - * Bogdan Padalko. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include - -#ifdef _WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#else -#include -#endif - -#include "utils.h" - -int main(int argc, char const *const *argv) { - char const *hostname; - int port; - int timeout; - amqp_socket_t *socket; - amqp_connection_state_t conn; - struct timeval tval; - struct timeval *tv; - - if (argc < 3) { - fprintf(stderr, - "Usage: amqps_connect_timeout host port timeout_sec " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - - timeout = atoi(argv[3]); - if (timeout > 0) { - tv = &tval; - - tv->tv_sec = timeout; - tv->tv_usec = 0; - } else { - tv = NULL; - } - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 5) { - int nextarg = 6; - die_on_error(amqp_ssl_socket_set_cacert(socket, argv[5]), - "setting CA certificate"); - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - die_on_error( - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]), - "setting client key"); - } - } - - die_on_error(amqp_socket_open_noblock(socket, hostname, port, tv), - "opening SSL/TLS connection"); - - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, - "guest", "guest"), - "Logging in"); - - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), - "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - printf("Done\n"); - return 0; -} diff --git a/examples/amqps_consumer.c b/examples/amqps_consumer.c deleted file mode 100644 index 50013e3..0000000 --- a/examples/amqps_consumer.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void run(amqp_connection_state_t conn) { - uint64_t start_time = now_microseconds(); - int received = 0; - int previous_received = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - amqp_frame_t frame; - - uint64_t now; - - for (;;) { - amqp_rpc_reply_t ret; - amqp_envelope_t envelope; - - now = now_microseconds(); - if (now > next_summary_time) { - int countOverInterval = received - previous_received; - double intervalRate = - countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Received %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, received, countOverInterval, - (int)intervalRate); - - previous_received = received; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - amqp_maybe_release_buffers(conn); - ret = amqp_consume_message(conn, &envelope, NULL, 0); - - if (AMQP_RESPONSE_NORMAL != ret.reply_type) { - if (AMQP_RESPONSE_LIBRARY_EXCEPTION == ret.reply_type && - AMQP_STATUS_UNEXPECTED_STATE == ret.library_error) { - if (AMQP_STATUS_OK != amqp_simple_wait_frame(conn, &frame)) { - return; - } - - if (AMQP_FRAME_METHOD == frame.frame_type) { - switch (frame.payload.method.id) { - case AMQP_BASIC_ACK_METHOD: - /* if we've turned publisher confirms on, and we've published a - * message here is a message being confirmed. - */ - - break; - case AMQP_BASIC_RETURN_METHOD: - /* if a published message couldn't be routed and the mandatory - * flag was set this is what would be returned. The message then - * needs to be read. - */ - { - amqp_message_t message; - ret = amqp_read_message(conn, frame.channel, &message, 0); - if (AMQP_RESPONSE_NORMAL != ret.reply_type) { - return; - } - - amqp_destroy_message(&message); - } - - break; - - case AMQP_CHANNEL_CLOSE_METHOD: - /* a channel.close method happens when a channel exception occurs, - * this can happen by publishing to an exchange that doesn't exist - * for example. - * - * In this case you would need to open another channel redeclare - * any queues that were declared auto-delete, and restart any - * consumers that were attached to the previous channel. - */ - return; - - case AMQP_CONNECTION_CLOSE_METHOD: - /* a connection.close method happens when a connection exception - * occurs, this can happen by trying to use a channel that isn't - * open for example. - * - * In this case the whole connection must be restarted. - */ - return; - - default: - fprintf(stderr, "An unexpected method was received %u\n", - frame.payload.method.id); - return; - } - } - } - - } else { - amqp_destroy_envelope(&envelope); - } - - received++; - } -} - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - char const *exchange; - char const *bindingkey; - amqp_socket_t *socket; - amqp_connection_state_t conn; - amqp_bytes_t queuename; - - if (argc < 3) { - fprintf(stderr, - "Usage: amqps_consumer host port " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = "amq.direct"; /* argv[3]; */ - bindingkey = "test queue"; /* argv[4]; */ - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 3) { - int nextarg = 4; - status = amqp_ssl_socket_set_cacert(socket, argv[3]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client key"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_declare_ok_t *r = amqp_queue_declare( - conn, 1, amqp_empty_bytes, 0, 0, 0, 1, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - run(conn); - - 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; -} diff --git a/examples/amqps_exchange_declare.c b/examples/amqps_exchange_declare.c deleted file mode 100644 index 1436e0c..0000000 --- a/examples/amqps_exchange_declare.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include "utils.h" - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - char const *exchange; - char const *exchangetype; - amqp_socket_t *socket; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, - "Usage: amqps_exchange_declare host port exchange " - "exchangetype [cacert.pem [verifypeer] [verifyhostname] " - "[key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - exchangetype = argv[4]; - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 5) { - int nextarg = 6; - status = amqp_ssl_socket_set_cacert(socket, argv[5]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client key/cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_exchange_declare(conn, 1, amqp_cstring_bytes(exchange), - amqp_cstring_bytes(exchangetype), 0, 0, 0, 0, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring exchange"); - - 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; -} diff --git a/examples/amqps_listen.c b/examples/amqps_listen.c deleted file mode 100644 index 5d12bbf..0000000 --- a/examples/amqps_listen.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include - -#include "utils.h" - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - char const *exchange; - char const *bindingkey; - amqp_socket_t *socket; - amqp_connection_state_t conn; - - amqp_bytes_t queuename; - - if (argc < 5) { - fprintf(stderr, - "Usage: amqps_listen host port exchange bindingkey " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 5) { - int nextarg = 6; - status = amqp_ssl_socket_set_cacert(socket, argv[5]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_declare_ok_t *r = amqp_queue_declare( - conn, 1, amqp_empty_bytes, 0, 0, 0, 1, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - for (;;) { - amqp_rpc_reply_t res; - amqp_envelope_t envelope; - - amqp_maybe_release_buffers(conn); - - res = amqp_consume_message(conn, &envelope, NULL, 0); - - if (AMQP_RESPONSE_NORMAL != res.reply_type) { - break; - } - - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned)envelope.delivery_tag, (int)envelope.exchange.len, - (char *)envelope.exchange.bytes, (int)envelope.routing_key.len, - (char *)envelope.routing_key.bytes); - - if (envelope.message.properties._flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int)envelope.message.properties.content_type.len, - (char *)envelope.message.properties.content_type.bytes); - } - printf("----\n"); - - amqp_dump(envelope.message.body.bytes, envelope.message.body.len); - - amqp_destroy_envelope(&envelope); - } - } - - 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; -} diff --git a/examples/amqps_listenq.c b/examples/amqps_listenq.c deleted file mode 100644 index 3f6d425..0000000 --- a/examples/amqps_listenq.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include - -#include "utils.h" - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - char const *queuename; - amqp_socket_t *socket; - amqp_connection_state_t conn; - - if (argc < 4) { - fprintf(stderr, - "Usage: amqps_listenq host port queuename " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - queuename = argv[3]; - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 4) { - int nextarg = 5; - status = amqp_ssl_socket_set_cacert(socket, argv[4]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_basic_consume(conn, 1, amqp_cstring_bytes(queuename), amqp_empty_bytes, - 0, 0, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - for (;;) { - amqp_rpc_reply_t res; - amqp_envelope_t envelope; - - amqp_maybe_release_buffers(conn); - - res = amqp_consume_message(conn, &envelope, NULL, 0); - - if (AMQP_RESPONSE_NORMAL != res.reply_type) { - break; - } - - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned)envelope.delivery_tag, (int)envelope.exchange.len, - (char *)envelope.exchange.bytes, (int)envelope.routing_key.len, - (char *)envelope.routing_key.bytes); - - if (envelope.message.properties._flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int)envelope.message.properties.content_type.len, - (char *)envelope.message.properties.content_type.bytes); - } - printf("----\n"); - - amqp_dump(envelope.message.body.bytes, envelope.message.body.len); - - amqp_destroy_envelope(&envelope); - } - } - - 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; -} diff --git a/examples/amqps_producer.c b/examples/amqps_producer.c deleted file mode 100644 index 120c21b..0000000 --- a/examples/amqps_producer.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void send_batch(amqp_connection_state_t conn, char const *queue_name, - int rate_limit, int message_count) { - uint64_t start_time = now_microseconds(); - int i; - int sent = 0; - int previous_sent = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - char message[256]; - amqp_bytes_t message_bytes; - - for (i = 0; i < (int)sizeof(message); i++) { - message[i] = i & 0xff; - } - - message_bytes.len = sizeof(message); - message_bytes.bytes = message; - - for (i = 0; i < message_count; i++) { - uint64_t now = now_microseconds(); - - die_on_error(amqp_basic_publish(conn, 1, amqp_cstring_bytes("amq.direct"), - amqp_cstring_bytes(queue_name), 0, 0, NULL, - message_bytes), - "Publishing"); - sent++; - if (now > next_summary_time) { - int countOverInterval = sent - previous_sent; - double intervalRate = - countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Sent %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, sent, countOverInterval, - (int)intervalRate); - - previous_sent = sent; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - while (((i * 1000000.0) / (now - start_time)) > rate_limit) { - microsleep(2000); - now = now_microseconds(); - } - } - - { - uint64_t stop_time = now_microseconds(); - int total_delta = (int)(stop_time - start_time); - - printf("PRODUCER - Message count: %d\n", message_count); - printf("Total time, milliseconds: %d\n", total_delta / 1000); - printf("Overall messages-per-second: %g\n", - (message_count / (total_delta / 1000000.0))); - } -} - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - int rate_limit; - int message_count; - amqp_socket_t *socket; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, - "Usage: amqps_producer host port rate_limit message_count " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - rate_limit = atoi(argv[3]); - message_count = atoi(argv[4]); - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 5) { - int nextarg = 6; - status = amqp_ssl_socket_set_cacert(socket, argv[5]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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"); - - send_batch(conn, "test queue", rate_limit, message_count); - - 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; -} diff --git a/examples/amqps_sendstring.c b/examples/amqps_sendstring.c deleted file mode 100644 index 9fed198..0000000 --- a/examples/amqps_sendstring.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#include "utils.h" - -int main(int argc, char const *const *argv) { - char const *hostname; - int port, status; - char const *exchange; - char const *routingkey; - char const *messagebody; - amqp_socket_t *socket; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, - "Usage: amqps_sendstring host port exchange routingkey " - "messagebody [cacert.pem [verifypeer] [verifyhostname] " - "[key.pem cert.pem]]\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - routingkey = argv[4]; - messagebody = argv[5]; - - conn = amqp_new_connection(); - - socket = amqp_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 6) { - int nextarg = 7; - status = amqp_ssl_socket_set_cacert(socket, argv[6]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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_basic_properties_t props; - props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG; - props.content_type = amqp_cstring_bytes("text/plain"); - props.delivery_mode = 2; /* persistent delivery mode */ - die_on_error(amqp_basic_publish(conn, 1, amqp_cstring_bytes(exchange), - amqp_cstring_bytes(routingkey), 0, 0, - &props, amqp_cstring_bytes(messagebody)), - "Publishing"); - } - - 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; -} diff --git a/examples/amqps_unbind.c b/examples/amqps_unbind.c deleted file mode 100644 index aad45c5..0000000 --- a/examples/amqps_unbind.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 - * Alan Antonuk. All Rights Reserved. - * - * Portions created by Mike Steinert are Copyright (c) 2012-2013 - * Mike Steinert. All Rights Reserved. - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include - -#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; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, - "Usage: amqps_unbind host port exchange bindingkey queue " - "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\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_ssl_socket_new(conn); - if (!socket) { - die("creating SSL/TLS socket"); - } - - amqp_ssl_socket_set_verify_peer(socket, 0); - amqp_ssl_socket_set_verify_hostname(socket, 0); - - if (argc > 6) { - int nextarg = 7; - status = amqp_ssl_socket_set_cacert(socket, argv[6]); - if (status) { - die("setting CA certificate"); - } - if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) { - amqp_ssl_socket_set_verify_peer(socket, 1); - nextarg++; - } - if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) { - amqp_ssl_socket_set_verify_hostname(socket, 1); - nextarg++; - } - if (argc > nextarg + 1) { - status = - amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]); - if (status) { - die("setting client cert"); - } - } - } - - status = amqp_socket_open(socket, hostname, port); - if (status) { - die("opening SSL/TLS connection"); - } - - 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; -} -- cgit v1.2.1