From ba63cc45744ddc45ee24961ddf348044821830eb Mon Sep 17 00:00:00 2001 From: William King Date: Sat, 10 Oct 2015 16:30:16 -0700 Subject: [PATCH] FS-8306 #resolve if the exchange doesn't exist, then create it, else fail. This resolves several error cases. --- .../mod_amqp/mod_amqp_command.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c index c20ae3d937..bb7ce5451e 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c @@ -151,11 +151,8 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg) } } profile->conn_active = NULL; - - if ( mod_amqp_connection_open(profile->conn_root, &(profile->conn_active), profile->name, profile->custom_attr) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile[%s] was unable to connect to any connection\n", profile->name); - } - + /* We are not going to open the command queue connection on create, but instead wait for the running thread to open it */ + /* Start the worker threads */ switch_threadattr_create(&thd_attr, profile->pool); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); @@ -200,6 +197,19 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void continue; } + /* Check if exchange already exists */ + amqp_exchange_declare(profile->conn_active->state, 1, + amqp_cstring_bytes(profile->exchange), + amqp_cstring_bytes("topic"), + 0, /* passive */ + 1, /* durable */ + amqp_empty_table); + + if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Checking for command exchange")) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile[%s] failed to create missing command exchange", profile->name); + continue; + } + /* Ensure we have a queue */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating command queue"); recv_queue = amqp_queue_declare(profile->conn_active->state, // state